Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniform reply behaviour of FGInputSocket::Read #109

Merged
merged 8 commits into from
Aug 13, 2018
22 changes: 11 additions & 11 deletions src/input_output/FGInputSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void FGInputSocket::Read(bool Holding)
}
}

if (command == "set") { // SET PROPERTY
if (command == "set") { // SET PROPERTY

if (argument.size() == 0) {
socket->Reply("No property argument supplied.\n");
Expand All @@ -170,7 +170,7 @@ void FGInputSocket::Read(bool Holding)
value = atof(str_value.c_str());
node->setDoubleValue(value);
}
socket->Reply("");
socket->Reply("set successful\n");

} else if (command == "get") { // GET PROPERTY

Expand Down Expand Up @@ -201,17 +201,17 @@ void FGInputSocket::Read(bool Holding)
socket->Reply(buf.str());
}

} else if (command == "hold") { // PAUSE
} else if (command == "hold") { // PAUSE

FDMExec->Hold();
socket->Reply("");
socket->Reply("Holding\n");

} else if (command == "resume") { // RESUME

FDMExec->Resume();
socket->Reply("");
socket->Reply("Resuming\n");

} else if (command == "iterate") { // ITERATE
} else if (command == "iterate") { // ITERATE

int argumentInt;
istringstream (argument) >> argumentInt;
Expand All @@ -225,15 +225,15 @@ void FGInputSocket::Read(bool Holding)
}
FDMExec->EnableIncrementThenHold( argumentInt );
FDMExec->Resume();
socket->Reply("");
socket->Reply("Iterations performed\n");

} else if (command == "quit") { // QUIT
} else if (command == "quit") { // QUIT

// close the socket connection
socket->Reply("");
socket->Reply("Closing connection\n");
socket->Close();

} else if (command == "info") { // INFO
} else if (command == "info") { // INFO

// get info about the sim run and/or aircraft, etc.
ostringstream info;
Expand All @@ -243,7 +243,7 @@ void FGInputSocket::Read(bool Holding)
info << "Simulation time: " << setw(8) << setprecision(3) << FDMExec->GetSimTime() << endl;
socket->Reply(info.str());

} else if (command == "help") { // HELP
} else if (command == "help") { // HELP

socket->Reply(
" JSBSim Server commands:\n\n"
Expand Down
13 changes: 13 additions & 0 deletions src/input_output/FGfdmSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,23 @@ void FGfdmSocket::Send(const char *data, int length)

void FGfdmSocket::WaitUntilReadable(void)
{
if (sckt_in <= 0)
return;

fd_set fds;
FD_ZERO(&fds);
FD_SET(sckt_in, &fds);
select(sckt_in+1, &fds, NULL, NULL, NULL);

/*
If you want to check select return status:

int recVal = select(sckt_in+1, &fds, NULL, NULL, NULL);
recVal: received value
0, if socket timeout
-1, if socket error
anithing else, if socket is readable
*/
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down