Added an FGIOChannel::writestring().
Some cygwin32 portability fixes for fg_socket.cxx.
This commit is contained in:
parent
796aa8b352
commit
ba60c0effd
8 changed files with 50 additions and 6 deletions
|
@ -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 ) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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() ) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue