1
0
Fork 0

PLIB net removed from FlightGear

This commit is contained in:
James Turner 2010-10-23 20:37:26 +01:00
parent 984900d84d
commit 0e53e2cbb1
16 changed files with 93 additions and 109 deletions

View file

@ -26,6 +26,7 @@
#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>
@ -34,6 +35,49 @@
#include "ExternalNet.hxx"
class HTTPClient : public simgear::NetBufferChannel
{
bool done;
SGTimeStamp start;
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) ) ;
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;
}
}
};
FGExternalNet::FGExternalNet( double dt, string host, int dop, int dip, int cp )
{
// set_delta_t( dt );

View file

@ -23,59 +23,14 @@
#ifndef _EXTERNAL_NET_HXX
#define _EXTERNAL_NET_HXX
#include <plib/netBuffer.h>
#include <plib/netSocket.h>
#include <simgear/timing/timestamp.hxx> // fine grained timing measurements
#include <simgear/io/raw_socket.hxx>
#include <Network/net_ctrls.hxx>
#include <Network/net_fdm.hxx>
#include <FDM/flight.hxx>
class HTTPClient : public netBufferChannel
{
bool done;
SGTimeStamp start;
public:
HTTPClient ( const char* host, int port, const char* path ) :
done( false )
{
open ();
connect (host, port);
const char* s = netFormat ( "GET %s HTTP/1.0\r\n\r\n", path );
bufferSend( s, strlen(s) ) ;
start.stamp();
}
virtual void handleBufferRead (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;
}
}
};
class FGExternalNet: public FGInterface {
private:
@ -85,8 +40,8 @@ private:
int cmd_port;
string fdm_host;
netSocket data_client;
netSocket data_server;
simgear::Socket data_client;
simgear::Socket data_server;
bool valid;

View file

@ -24,11 +24,9 @@ endif
if HAVE_FRAMEWORK_PLIB
fgfs_PLIB_FW = $(plib_FRAMEWORK)
metar_PLIB_FW = $(plib_FRAMEWORK)
else
fgfs_PLIB_LIBS = -lplibpuaux -lplibpu -lplibfnt -lplibjs -lplibnet \
fgfs_PLIB_LIBS = -lplibpuaux -lplibpu -lplibfnt -lplibjs \
-lplibsg -lplibul
metar_PLIB_LIBS = -lplibnet -lplibul
endif
if HAVE_FRAMEWORK_OSG
@ -133,9 +131,8 @@ metar_SOURCES = metar_main.cxx
metar_LDADD = \
-lsgenvironment -lsgio -lsgbucket -lsgmisc -lsgstructure -lsgdebug \
$(metar_PLIB_LIBS) $(network_LIBS) \
$(network_LIBS) \
-lz $(base_LIBS)
metar_LDFLAGS = $(metar_PLIB_FW)
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src

View file

@ -48,6 +48,7 @@
#include <simgear/props/props.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/math/sg_random.h>
#include <simgear/io/raw_socket.hxx>
#include <Time/light.hxx>
#include <Aircraft/replay.hxx>
@ -588,8 +589,8 @@ int fgMainInit( int argc, char **argv ) {
fgRegisterIdleHandler( &fgIdleFunction );
fgRegisterDrawHandler( &FGRenderer::update );
// Initialize plib net interface
netInit( &argc, argv );
// Initialize sockets (WinSock needs this)
simgear::Socket::initSockets();
// Clouds3D requires an alpha channel
fgOSOpenWindow(true /* request stencil buffer */);

View file

@ -35,7 +35,6 @@
#include <algorithm>
#include <cstring>
#include <osg/Math> // isNaN
#include <plib/netSocket.h>
#include <simgear/misc/stdint.hxx>
#include <simgear/timing/timestamp.hxx>
@ -411,7 +410,7 @@ FGMultiplayMgr::init (void)
SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-callsign= "<<mCallsign);
Close(); // Should Init be called twice, close Socket first
// A memory leak was reported here by valgrind
mSocket = new netSocket();
mSocket = new simgear::Socket();
if (!mSocket->open(false)) {
SG_LOG( SG_NETWORK, SG_DEBUG,
"FGMultiplayMgr::init - Failed to create data socket" );
@ -731,7 +730,7 @@ FGMultiplayMgr::update(double)
// returned will only be that of the next
// packet waiting to be processed.
//////////////////////////////////////////////////
netAddress SenderAddress;
simgear::IPAddress SenderAddress;
bytes = mSocket->recvfrom(msgBuf.Msg, sizeof(msgBuf.Msg), 0,
&SenderAddress);
//////////////////////////////////////////////////
@ -815,7 +814,7 @@ FGMultiplayMgr::update(double)
//////////////////////////////////////////////////////////////////////
void
FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
const netAddress& SenderAddress, long stamp)
const simgear::IPAddress& SenderAddress, long stamp)
{
const T_MsgHdr* MsgHdr = Msg.msgHdr();
if (MsgHdr->MsgLen < sizeof(T_MsgHdr) + sizeof(T_PositionMsg)) {
@ -965,7 +964,7 @@ FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
//////////////////////////////////////////////////////////////////////
void
FGMultiplayMgr::ProcessChatMsg(const MsgBuf& Msg,
const netAddress& SenderAddress)
const simgear::IPAddress& SenderAddress)
{
const T_MsgHdr* MsgHdr = Msg.msgHdr();
if (MsgHdr->MsgLen < sizeof(T_MsgHdr) + 1) {

View file

@ -38,8 +38,8 @@
#include <simgear/compiler.h>
#include <simgear/props/props.hxx>
#include <plib/netSocket.h>
#include <Main/globals.hxx>
#include <simgear/io/raw_socket.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <AIModel/AIMultiplayer.hxx>
@ -78,16 +78,16 @@ private:
const std::string& modelName);
FGAIMultiplayer* getMultiplayer(const std::string& callsign);
void FillMsgHdr(T_MsgHdr *MsgHdr, int iMsgId, unsigned _len = 0u);
void ProcessPosMsg(const MsgBuf& Msg, const netAddress& SenderAddress,
void ProcessPosMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress,
long stamp);
void ProcessChatMsg(const MsgBuf& Msg, const netAddress& SenderAddress);
void ProcessChatMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress);
/// maps from the callsign string to the FGAIMultiplayer
typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
MultiPlayerMap mMultiPlayerMap;
netSocket* mSocket;
netAddress mServer;
simgear::Socket* mSocket;
simgear::IPAddress mServer;
bool mHaveServer;
bool mInitialised;
std::string mCallsign;

View file

@ -13,9 +13,6 @@
#include <string>
#include <plib/ul.h>
#include <plib/netSocket.h>
#include "tiny_xdr.hxx"
/* XDR 8bit integers */

View file

@ -28,8 +28,6 @@
# include <config.h>
#endif
#include <plib/netChat.h>
#include <simgear/misc/sg_path.hxx>
#include <Main/fg_props.hxx>

View file

@ -66,7 +66,7 @@ bool FGHttpd::open() {
bool FGHttpd::process() {
netChannel::poll();
simgear::NetChannel::poll();
return true;
}

View file

@ -32,7 +32,7 @@
# include <config.h>
#endif
#include <plib/netChat.h>
#include <simgear/io/sg_netChat.hxx>
#include "protocol.hxx"
@ -40,10 +40,10 @@
/* simple httpd server that makes an hasty stab at following the http
1.1 rfc. */
class HttpdChannel : public netChat
class HttpdChannel : public simgear::NetChat
{
netBuffer buffer ;
simgear::NetBuffer buffer ;
string urlEncode(string);
string urlDecode(string);
@ -61,12 +61,12 @@ public:
} ;
class HttpdServer : private netChannel
class HttpdServer : private simgear::NetChannel
{
virtual bool writable (void) { return false ; }
virtual void handleAccept (void) {
netAddress addr ;
simgear::IPAddress addr ;
int handle = accept ( &addr ) ;
SG_LOG( SG_IO, SG_INFO, "Client " << addr.getHost() << ":" << addr.getPort() << " connected" );

View file

@ -75,7 +75,7 @@ bool FGJpegHttpd::open() {
bool FGJpegHttpd::process() {
netChannel::poll();
simgear::NetChannel::poll();
return true;
}

View file

@ -32,7 +32,7 @@
# include <config.h>
#endif
#include <plib/netChat.h>
#include <simgear/io/sg_netChat.hxx>
#ifdef FG_JPEG_SERVER
# include <simgear/screen/jpgfactory.hxx>
@ -57,10 +57,10 @@ class trJpgFactory;
/* simple httpd server that makes an hasty stab at following the http
1.1 rfc. */
class HttpdImageChannel : public netChat
class HttpdImageChannel : public simgear::NetChat
{
netBuffer buffer ;
simgear::NetBuffer buffer ;
trJpgFactory *JpgFactory;
public:
@ -89,12 +89,12 @@ public:
};
class HttpdImageServer : private netChannel
class HttpdImageServer : private simgear::NetChannel
{
virtual bool writable (void) { return false ; }
virtual void handleAccept (void) {
netAddress addr ;
simgear::IPAddress addr ;
int handle = accept ( &addr ) ;
SG_LOG( SG_IO, SG_INFO, "Client " << addr.getHost() << ":" << addr.getPort() << " connected" );

View file

@ -40,7 +40,7 @@
#include <Main/globals.hxx>
#include <Main/viewmgr.hxx>
#include <plib/netChat.h>
#include <simgear/io/sg_netChat.hxx>
#include "props.hxx"
@ -54,9 +54,9 @@ using std::endl;
* Props connection class.
* This class represents a connection to props client.
*/
class PropsChannel : public netChat
class PropsChannel : public simgear::NetChat
{
netBuffer buffer;
simgear::NetBuffer buffer;
/**
* Current property node name.
@ -471,9 +471,9 @@ FGProps::open()
return false;
}
netChannel::open();
netChannel::bind( "", port );
netChannel::listen( 5 );
simgear::NetChannel::open();
simgear::NetChannel::bind( "", port );
simgear::NetChannel::listen( 5 );
SG_LOG( SG_IO, SG_INFO, "Props server started on port " << port );
set_enabled( true );
@ -496,7 +496,7 @@ FGProps::close()
bool
FGProps::process()
{
netChannel::poll();
simgear::NetChannel::poll();
return true;
}
@ -506,7 +506,7 @@ FGProps::process()
void
FGProps::handleAccept()
{
netAddress addr;
simgear::IPAddress addr;
int handle = accept( &addr );
SG_LOG( SG_IO, SG_INFO, "Props server accepted connection from "
<< addr.getHost() << ":" << addr.getPort() );

View file

@ -30,10 +30,7 @@
#include <string>
#include <vector>
using std::string;
using std::vector;
#include <plib/netChannel.h>
#include <simgear/io/sg_netChannel.hxx>
#include "protocol.hxx"
@ -43,7 +40,7 @@ using std::vector;
* FlightGear properties.
*/
class FGProps : public FGProtocol,
public netChannel
public simgear::NetChannel
{
private:
@ -58,7 +55,7 @@ public:
*
* @param tokens Tokenized configuration parameters
*/
FGProps( const vector<string>& tokens );
FGProps( const std::vector<std::string>& tokens );
/**
* Destructor.

View file

@ -6,10 +6,4 @@ terrasync_SOURCES = terrasync.cxx
AM_CPPFLAGS = $(svn_CPPFLAGS)
if HAVE_FRAMEWORK_PLIB
terrasync_LDFLAGS = $(plib_FRAMEWORK)
else
terrasync_PLIB_LIBS = -lplibnet -lplibul
endif
terrasync_LDADD = $(terrasync_PLIB_LIBS) -lsgmisc -lsgdebug $(network_LIBS) $(svn_LIBS)
terrasync_LDADD = -lsgio -lsgmisc -lsgdebug $(network_LIBS) $(svn_LIBS)

View file

@ -47,9 +47,7 @@
#include <deque>
#include <map>
#include <plib/netSocket.h>
#include <plib/ul.h>
#include <simgear/io/raw_socket.hxx>
#include <simgear/bucket/newbucket.hxx>
#include <simgear/misc/sg_path.hxx>
@ -115,7 +113,7 @@ static void usage( const string& prog ) {
deque<string> waitingTiles;
typedef map<string,time_t> CompletedTiles;
CompletedTiles completedTiles;
netSocket theSocket;
simgear::Socket theSocket;
#ifdef HAVE_SVN_CLIENT_H
@ -513,7 +511,7 @@ int main( int argc, char **argv ) {
}
// Must call this before any other net stuff
netInit( &argc,argv );
simgear::Socket::initSockets();
if ( ! theSocket.open( false ) ) { // open a UDP socket
printf("error opening socket\n");
@ -624,7 +622,11 @@ int main( int argc, char **argv ) {
terminating = true;
} else
ulSleep( 1 );
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
} // while !terminating
return 0;