2 simgear::Socket, adapted from PLIB netSocket by James Turner
3 Copyright (C) 2010 James Turner
5 PLIB - A Suite of Portable Game Libraries
6 Copyright (C) 1998,2002 Steve Baker
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef SG_IO_SOCKET_HXX
24 #define SG_IO_SOCKET_HXX
28 #if defined(__APPLE__) || defined(__FreeBSD__)
29 # include <netinet/in.h>
36 * Socket address, internet style.
40 /* DANGER!!! This MUST match 'struct sockaddr_in' exactly! */
41 #if defined(__APPLE__) || defined(__FreeBSD__)
49 unsigned short sin_port ;
50 unsigned int sin_addr ;
56 IPAddress ( const char* host, int port ) ;
58 void set ( const char* host, int port ) ;
59 const char* getHost () const ;
60 unsigned int getPort() const ;
61 unsigned int getIP () const ;
62 unsigned int getFamily () const ;
63 static const char* getLocalHost () ;
65 bool getBroadcast () const ;
81 static int initSockets();
83 int getHandle () const { return handle; }
84 void setHandle (int handle) ;
86 bool open ( bool stream=true ) ;
88 int bind ( const char* host, int port ) ;
89 int listen ( int backlog ) ;
90 int accept ( IPAddress* addr ) ;
91 int connect ( const char* host, int port ) ;
92 int send ( const void * buffer, int size, int flags = 0 ) ;
93 int sendto ( const void * buffer, int size, int flags, const IPAddress* to ) ;
94 int recv ( void * buffer, int size, int flags = 0 ) ;
95 int recvfrom ( void * buffer, int size, int flags, IPAddress* from ) ;
97 void setBlocking ( bool blocking ) ;
98 void setBroadcast ( bool broadcast ) ;
100 static bool isNonBlockingError () ;
102 static int select ( Socket** reads, Socket** writes, int timeout ) ;
105 //const char* netFormat ( const char* fmt, ... ) ;
107 } // of namespace simgear
109 #endif // SG_IO_SOCKET_HXX