]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/ExternalNet/ExternalNet.cxx
Do not run the HoldDown code until after the aircraft is trimmed to prevent a devide...
[flightgear.git] / src / FDM / ExternalNet / ExternalNet.cxx
index 741bb3b784ce53b9d6bf5b958a857fdc72903687..aafa2c1041bfa58e2682aaa5b7d440c637b04b16 100644 (file)
 #  include <config.h>
 #endif
 
+#include <cstring>
+
 #include <simgear/debug/logstream.hxx>
 #include <simgear/io/lowlevel.hxx> // endian tests
+#include <simgear/io/sg_netBuffer.hxx>
 
 #include <Main/fg_props.hxx>
 #include <Network/native_ctrls.hxx>
 #include "ExternalNet.hxx"
 
 
+class HTTPClient : public simgear::NetBufferChannel
+{
+
+    bool done;
+    SGTimeStamp start;
+    simgear::NetChannelPoller poller;
+public:
+
+    HTTPClient ( const char* host, int port, const char* path ) :
+        done( false )
+    {
+       open ();
+       connect (host, port);
+
+  char buffer[256];
+  ::snprintf (buffer, 256, "GET %s HTTP/1.0\r\n\r\n", path );
+       bufferSend(buffer, strlen(buffer) ) ;
+
+        poller.addChannel(this);
+        start.stamp();
+    }
+
+    virtual void handleBufferRead (simgear::NetBuffer& buffer)
+    {
+       const char* s = buffer.getData();
+       while (*s)
+           fputc(*s++,stdout);
+
+       printf("done\n");
+       buffer.remove();
+       printf("after buffer.remove()\n");
+        done = true;
+    }
+
+    bool isDone() const { return done; }
+    bool isDone( long usec ) const { 
+        if ( start + SGTimeStamp::fromUSec(usec) < SGTimeStamp::now() ) {
+            return true;
+        } else {
+            return done;
+        }
+    }
+    
+    void poll(int timeout)
+    {
+        poller.poll(timeout);
+    }
+};
+
 FGExternalNet::FGExternalNet( double dt, string host, int dop, int dip, int cp )
 {
 //     set_delta_t( dt );