From ba60c0effdb454d7100eb0f05be4fb4a8233e3ca Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 24 Nov 1999 14:14:45 +0000 Subject: [PATCH] Added an FGIOChannel::writestring(). Some cygwin32 portability fixes for fg_socket.cxx. --- src/Network/fg_file.cxx | 7 +++++++ src/Network/fg_file.hxx | 3 +++ src/Network/fg_serial.cxx | 7 +++++++ src/Network/fg_serial.hxx | 5 ++++- src/Network/fg_socket.cxx | 18 ++++++++++++++++-- src/Network/fg_socket.hxx | 9 ++++++--- src/Network/iochannel.cxx | 6 ++++++ src/Network/iochannel.hxx | 1 + 8 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/Network/fg_file.cxx b/src/Network/fg_file.cxx index 4adb2b220..86bc78276 100644 --- a/src/Network/fg_file.cxx +++ b/src/Network/fg_file.cxx @@ -108,6 +108,13 @@ int FGFile::write( char *buf, int length ) { } +// write null terminated string to a file +int FGFile::writestring( char *str ) { + int length = strlen( str ); + return write( str, length ); +} + + // close the port bool FGFile::close() { if ( std::close( fp ) == -1 ) { diff --git a/src/Network/fg_file.hxx b/src/Network/fg_file.hxx index 469be7b6f..a5995b0e4 100644 --- a/src/Network/fg_file.hxx +++ b/src/Network/fg_file.hxx @@ -66,6 +66,9 @@ public: // write data to a file int write( char *buf, int length ); + // write null terminated string to a file + int writestring( char *str ); + // close file bool close(); diff --git a/src/Network/fg_serial.cxx b/src/Network/fg_serial.cxx index 5f70bea4b..3c07bb6fb 100644 --- a/src/Network/fg_serial.cxx +++ b/src/Network/fg_serial.cxx @@ -136,6 +136,13 @@ int FGSerial::write( char *buf, int length ) { } +// write null terminated string to port +int FGSerial::writestring( char *str ) { + int length = strlen( str ); + return write( str, length ); +} + + // close the port bool FGSerial::close() { if ( ! port.close_port() ) { diff --git a/src/Network/fg_serial.hxx b/src/Network/fg_serial.hxx index ba8888113..80afd0131 100644 --- a/src/Network/fg_serial.hxx +++ b/src/Network/fg_serial.hxx @@ -70,9 +70,12 @@ public: // read a line of data, length is max size of input buffer int readline( char *buf, int length ); - // write data to a file + // write data to port int write( char *buf, int length ); + // write null terminated string to port + int writestring( char *str ); + // close port bool close(); diff --git a/src/Network/fg_socket.cxx b/src/Network/fg_socket.cxx index 152a11084..c494ebf21 100644 --- a/src/Network/fg_socket.cxx +++ b/src/Network/fg_socket.cxx @@ -27,8 +27,6 @@ #include // socket(), bind(), select(), accept() #include // socket(), bind(), listen(), accept() #include // struct sockaddr_in -#include // #define TCP_NODELAY, this attempts to - // disable the Nagle algorithm. #include // gethostbyname() #include // select(), fsync()/fdatasync() @@ -53,7 +51,12 @@ FGSocket::~FGSocket() { int FGSocket::make_server_socket () { struct sockaddr_in name; + +#if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) + int length; +#else socklen_t length; +#endif // Create the socket. sock = socket (PF_INET, SOCK_STREAM, 0); @@ -107,7 +110,11 @@ int FGSocket::make_client_socket () { // Connect this socket to the host and the port specified on the // command line +#if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) + bcopy(hp->h_addr, (char *)(&(name.sin_addr.s_addr)), hp->h_length); +#else bcopy(hp->h_addr, &(name.sin_addr.s_addr), hp->h_length); +#endif name.sin_port = htons(port); if ( connect(sock, (struct sockaddr *) &name, @@ -312,6 +319,13 @@ int FGSocket::write( char *buf, int length ) { } +// write null terminated string to socket (server) +int FGSocket::writestring( char *str ) { + int length = strlen( str ); + return write( str, length ); +} + + // close the port bool FGSocket::close() { for ( int i = 0; i < (int)client_connections.size(); ++i ) { diff --git a/src/Network/fg_socket.hxx b/src/Network/fg_socket.hxx index 7b96bd5a6..51f64ba3c 100644 --- a/src/Network/fg_socket.hxx +++ b/src/Network/fg_socket.hxx @@ -71,15 +71,18 @@ public: // open the file based on specified direction bool open( FGProtocol::fgProtocolDir dir ); - // read data from file + // read data from socket int read( char *buf, int length ); - // read data from file + // read data from socket int readline( char *buf, int length ); - // write data to a file + // write data to a socket int write( char *buf, int length ); + // write null terminated string to a socket + int writestring( char *str ); + // close file bool close(); diff --git a/src/Network/iochannel.cxx b/src/Network/iochannel.cxx index 23f6c46e9..afce4006e 100644 --- a/src/Network/iochannel.cxx +++ b/src/Network/iochannel.cxx @@ -62,6 +62,12 @@ int FGIOChannel::write( char *buf, int length ) { } +// dummy process routine +int FGIOChannel::writestring( char *str ) { + return false; +} + + // dummy close routine bool FGIOChannel::close() { return false; diff --git a/src/Network/iochannel.hxx b/src/Network/iochannel.hxx index aae5c1932..09c7e7bb4 100644 --- a/src/Network/iochannel.hxx +++ b/src/Network/iochannel.hxx @@ -51,6 +51,7 @@ public: virtual int read( char *buf, int length ); virtual int readline( char *buf, int length ); virtual int write( char *buf, int length ); + virtual int writestring( char *str ); virtual bool close(); };