Allow for a user specified timeout when waiting for a response from the
remote fdm command server (http server.)
This commit is contained in:
parent
4763dbae6a
commit
4fb56176ce
2 changed files with 19 additions and 5 deletions
|
@ -387,29 +387,29 @@ void FGExternalNet::init() {
|
|||
HTTPClient *http;
|
||||
sprintf( cmd, "/longitude-deg?value=%.8f", lon );
|
||||
http = new HTTPClient( fdm_host.c_str(), cmd_port, cmd );
|
||||
while ( !http->isDone() ) http->poll(0);
|
||||
while ( !http->isDone(1000000) ) http->poll(0);
|
||||
delete http;
|
||||
|
||||
sprintf( cmd, "/latitude-deg?value=%.8f", lat );
|
||||
http = new HTTPClient( fdm_host.c_str(), cmd_port, cmd );
|
||||
while ( !http->isDone() ) http->poll(0);
|
||||
while ( !http->isDone(1000000) ) http->poll(0);
|
||||
delete http;
|
||||
|
||||
sprintf( cmd, "/ground-m?value=%.8f", ground );
|
||||
http = new HTTPClient( fdm_host.c_str(), cmd_port, cmd );
|
||||
while ( !http->isDone() ) http->poll(0);
|
||||
while ( !http->isDone(1000000) ) http->poll(0);
|
||||
delete http;
|
||||
|
||||
sprintf( cmd, "/heading-deg?value=%.8f", heading );
|
||||
http = new HTTPClient( fdm_host.c_str(), cmd_port, cmd );
|
||||
while ( !http->isDone() ) http->poll(0);
|
||||
while ( !http->isDone(1000000) ) http->poll(0);
|
||||
delete http;
|
||||
|
||||
SG_LOG( SG_IO, SG_INFO, "before sending reset command." );
|
||||
|
||||
sprintf( cmd, "/reset?value=ground" );
|
||||
http = new HTTPClient( fdm_host.c_str(), cmd_port, cmd );
|
||||
while ( !http->isDone() ) http->poll(0);
|
||||
while ( !http->isDone(1000000) ) http->poll(0);
|
||||
delete http;
|
||||
|
||||
SG_LOG( SG_IO, SG_INFO, "Remote FDM init() finished." );
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <plib/netBuffer.h>
|
||||
#include <plib/netSocket.h>
|
||||
|
||||
#include <simgear/timing/timestamp.hxx> // fine grained timing measurements
|
||||
|
||||
#include <Network/net_ctrls.hxx>
|
||||
#include <Network/net_fdm.hxx>
|
||||
|
||||
|
@ -36,6 +38,7 @@ class HTTPClient : public netBufferChannel
|
|||
{
|
||||
|
||||
bool done;
|
||||
SGTimeStamp start;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -47,6 +50,8 @@ public:
|
|||
|
||||
cchar* s = netFormat ( "GET %s HTTP/1.0\r\n\r\n", path );
|
||||
bufferSend( s, strlen(s) ) ;
|
||||
|
||||
start.stamp();
|
||||
}
|
||||
|
||||
virtual void handleBufferRead (netBuffer& buffer)
|
||||
|
@ -62,6 +67,15 @@ public:
|
|||
}
|
||||
|
||||
bool isDone() const { return done; }
|
||||
bool isDone( long usec ) const {
|
||||
SGTimeStamp now;
|
||||
now.stamp();
|
||||
if ( (now - start) > usec ) {
|
||||
return true;
|
||||
} else {
|
||||
return done;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue