From 0d6cd11dd434f69eeb58fd28b4bfd717252bd556 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 9 Jun 2013 19:12:04 +0100 Subject: [PATCH] Work with revised NetChannel poll() API. --- src/FDM/ExternalNet/ExternalNet.cxx | 8 +++++++- src/Network/httpd.cxx | 14 +++++++++++--- src/Network/props.cxx | 5 ++++- src/Network/props.hxx | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/FDM/ExternalNet/ExternalNet.cxx b/src/FDM/ExternalNet/ExternalNet.cxx index 9d2f3e7b2..aafa2c104 100644 --- a/src/FDM/ExternalNet/ExternalNet.cxx +++ b/src/FDM/ExternalNet/ExternalNet.cxx @@ -42,7 +42,7 @@ class HTTPClient : public simgear::NetBufferChannel bool done; SGTimeStamp start; - + simgear::NetChannelPoller poller; public: HTTPClient ( const char* host, int port, const char* path ) : @@ -55,6 +55,7 @@ public: ::snprintf (buffer, 256, "GET %s HTTP/1.0\r\n\r\n", path ); bufferSend(buffer, strlen(buffer) ) ; + poller.addChannel(this); start.stamp(); } @@ -78,6 +79,11 @@ public: return done; } } + + void poll(int timeout) + { + poller.poll(timeout); + } }; FGExternalNet::FGExternalNet( double dt, string host, int dop, int dip, int cp ) diff --git a/src/Network/httpd.cxx b/src/Network/httpd.cxx index dca4c79bf..745a14c9e 100644 --- a/src/Network/httpd.cxx +++ b/src/Network/httpd.cxx @@ -58,7 +58,7 @@ using std::string; class HttpdChannel : public simgear::NetChat { simgear::NetBuffer buffer; - + string urlEncode(string); string urlDecode(string); @@ -90,11 +90,18 @@ class HttpdServer : private simgear::NetChannel HttpdChannel *hc = new HttpdChannel; hc->setHandle ( handle ); + poller.addChannel( hc ); } + simgear::NetChannelPoller poller; public: HttpdServer ( int port ); + + void poll() + { + poller.poll(); + } }; HttpdServer::HttpdServer(int port) @@ -116,6 +123,8 @@ HttpdServer::HttpdServer(int port) SG_LOG( SG_IO, SG_ALERT, "Failed to listen on HTTP port."); return; } + + poller.addChannel(this); SG_LOG(SG_IO, SG_ALERT, "Httpd server started on port " << port); } @@ -152,8 +161,7 @@ bool FGHttpd::open() { bool FGHttpd::process() { - simgear::NetChannel::poll(); - + server->poll(); return true; } diff --git a/src/Network/props.cxx b/src/Network/props.cxx index 5e88933d1..58905e2f3 100644 --- a/src/Network/props.cxx +++ b/src/Network/props.cxx @@ -594,6 +594,8 @@ FGProps::open() return false; } + poller.addChannel(this); + SG_LOG( SG_IO, SG_INFO, "Props server started on port " << port ); set_enabled( true ); @@ -616,7 +618,7 @@ FGProps::close() bool FGProps::process() { - simgear::NetChannel::poll(); + poller.poll(); return true; } @@ -632,4 +634,5 @@ FGProps::handleAccept() << addr.getHost() << ":" << addr.getPort() ); PropsChannel* channel = new PropsChannel(); channel->setHandle( handle ); + poller.addChannel( channel ); } diff --git a/src/Network/props.hxx b/src/Network/props.hxx index 09b5a09a3..9e7405583 100644 --- a/src/Network/props.hxx +++ b/src/Network/props.hxx @@ -49,7 +49,7 @@ private: * Server port to listen on. */ int port; - + simgear::NetChannelPoller poller; public: /** * Create a new TCP server.