head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.40; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.57; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.04; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.22.01; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# sg_socket.hxx

Go to the documentation of this file.

    00001
    00006 // Written by Curtis Olson, started November 1999.
    00007 //
    00008 // Copyright (C) 1999  Curtis L. Olson - curt@@flightgear.org
    00009 //
    00010 // This program is free software; you can redistribute it and/or
    00011 // modify it under the terms of the GNU General Public License as
    00012 // published by the Free Software Foundation; either version 2 of the
    00013 // License, or (at your option) any later version.
    00014 //
    00015 // This program is distributed in the hope that it will be useful, but
    00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
    00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00018 // General Public License for more details.
    00019 //
    00020 // You should have received a copy of the GNU General Public License
    00021 // along with this program; if not, write to the Free Software
    00022 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00023 //
    00024 // $Id: sg_socket.hxx,v 1.13 2002/05/10 13:53:22 curt Exp $
    00025
    00026
    00027 #ifndef _SG_SOCKET_HXX
    00028 #define _SG_SOCKET_HXX
    00029
    00030
    00031 #ifndef __cplusplus
    00032 # error This library requires C++
    00033 #endif
    00034
    00035 #include <simgear/compiler.h>
    00036
    00037 #include STL_STRING
    00038
    00039 #include <simgear/math/sg_types.hxx>
    00040 #include <simgear/io/iochannel.hxx>
    00041
    00042 #include <plib/netSocket.h>
    00043
    00044 SG_USING_STD(string);
    00045
    00046 #define SG_MAX_SOCKET_QUEUE 32
    00047
    00048
    00052 class SGSocket : public SGIOChannel {
    00053 public:
    00054 private:
    00055     string hostname;
    00056     string port_str;
    00057
    00058     char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ];
    00059     int save_len;
    00060
    00061     netSocket sock;
    00062     netSocket* client;
    00063     unsigned short port;
    00064     bool is_tcp;
    00065     bool is_server;
    00066     bool first_read;
    00067
    00068     static bool init;
    00069
    00070     // make a server (master listening) socket
    00071     bool make_server_socket();
    00072
    00073     // make a client socket
    00074     bool  make_client_socket();
    00075
    00076     // Poll for new connections or data to read.
    00077     int poll();
    00078
    00079 public:
    00080
    00128     SGSocket( const string& host, const string& port, const string& style );
    00129
    00131     ~SGSocket();
    00132
    00133     // If specified as a server (in direction for now) open the master
    00134     // listening socket.  If specified as a client (out direction),
    00135     // open a connection to a server.
    00136     bool open( const SGProtocolDir d );
    00137
    00138     // read data from socket
    00139     int read( char *buf, int length );
    00140
    00141     // read data from socket
    00142     int readline( char *buf, int length );
    00143
    00144     // write data to a socket
    00145     int write( const char *buf, const int length );
    00146
    00147     // write null terminated string to a socket
    00148     int writestring( const char *str );
    00149
    00150     // close file
    00151     bool close();
    00152
    00157     bool nonblock();
    00158
    00160     inline string get_hostname() const { return hostname; }
    00161
    00163     inline string get_port_str() const { return port_str; }
    00164 };
    00165
    00166
    00167 #endif // _SG_SOCKET_HXX

@ 1.3 log @Oops, try again. @ text @d115 1 a115 1