]> git.mxchange.org Git - flightgear.git/commitdiff
Added an FGIOChannel::writestring().
authorcurt <curt>
Wed, 24 Nov 1999 14:14:45 +0000 (14:14 +0000)
committercurt <curt>
Wed, 24 Nov 1999 14:14:45 +0000 (14:14 +0000)
Some cygwin32 portability fixes for fg_socket.cxx.

src/Network/fg_file.cxx
src/Network/fg_file.hxx
src/Network/fg_serial.cxx
src/Network/fg_serial.hxx
src/Network/fg_socket.cxx
src/Network/fg_socket.hxx
src/Network/iochannel.cxx
src/Network/iochannel.hxx

index 4adb2b2204dc7f47236dc1b2dca3eebc707bc314..86bc78276d444a6f85b6983e9d41851de7535036 100644 (file)
@@ -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 ) {
index 469be7b6f6c225eb90b5d11174afdf6f4ce1ae6b..a5995b0e4499b13a100f40d754fefdf9713b3b9b 100644 (file)
@@ -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();
 
index 5f70bea4b6c875d82e02e8d60cf751fa02b486ee..3c07bb6fb630ba40d7a636418674c0a4328a080f 100644 (file)
@@ -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() ) {
index ba88881136be9537f6ab87afcf5fcaf0e6735b7b..80afd0131b27db596fbbb94ae57bb501413e3a52 100644 (file)
@@ -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();
 
index 152a11084341abfc005e394c83d8b95c48ef966e..c494ebf214d62e3a00c8179516741a6d7ccc688a 100644 (file)
@@ -27,8 +27,6 @@
 #include <sys/types.h>         // socket(), bind(), select(), accept()
 #include <sys/socket.h>                // socket(), bind(), listen(), accept()
 #include <netinet/in.h>                // struct sockaddr_in
-#include <netinet/tcp.h>       // #define TCP_NODELAY, this attempts to 
-                                // disable the Nagle algorithm.
 #include <netdb.h>             // gethostbyname()
 #include <unistd.h>            // 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 ) {
index 7b96bd5a642b3ba07eeaaa88ddb687a63217dd6e..51f64ba3ca01e419a1b19ecf61b6b587671e1fd7 100644 (file)
@@ -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();
 
index 23f6c46e993dd10ad2a4f41f8fe3ca9459e63a89..afce4006e794e5cbc90ac8ee52dfaeedc2ce8529 100644 (file)
@@ -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;
index aae5c1932ba4e6ed24c657d8e970e9a3b9f2e017..09c7e7bb43870a24d7356d2c92e86e64a1b56516 100644 (file)
@@ -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();
 };