00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _SOCKET_H_
00040 #define _SOCKET_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include "OSGBase.h"
00046 #include "OSGSocketException.h"
00047 #include "OSGSocketAddress.h"
00048
00049 OSG_BEGIN_NAMESPACE
00050
00051 class NetworkMessage;
00052
00053 class OSG_BASE_DLLMAPPING Socket
00054 {
00055
00056 public:
00057
00061 Socket(void);
00062 Socket(const Socket &source);
00063
00065
00069 virtual ~Socket();
00070
00072
00076 virtual void open ( void )=0;
00077 virtual void close ( void )=0;
00078 void bind (const SocketAddress &address=
00079 SocketAddress(SocketAddress::ANY));
00080 void listen ( int maxPending=10 );
00081 void connect(const SocketAddress &address );
00082
00084
00088 int recv ( void *buf,int size);
00089 int recvAvailable( void *buf,int size);
00090 int recv ( NetworkMessage &msg );
00091 int peek ( void *buf,int size);
00092 int send (const void *buf,int size);
00093 int send ( NetworkMessage &msg );
00094
00096
00100 void setReusePort (bool value );
00101 void setBlocking (bool value );
00102 SocketAddress getAddress (void );
00103 void setReadBufferSize (int size );
00104 void setWriteBufferSize(int size );
00105 int getReadBufferSize (void );
00106 int getWriteBufferSize(void );
00107 int getAvailable (void );
00108 bool waitReadable (double duration);
00109 bool waitWritable (double duration);
00110
00112
00116 const Socket & operator =(const Socket &source);
00117
00119
00123 static int getError (void);
00124 static int getHostError (void);
00125 static std::string getErrorStr (void);
00126 static std::string getHostErrorStr(void);
00127
00130
00131 protected:
00132
00136 #if defined WIN32
00137 typedef char FAR SocketOptT;
00138 #else
00139 typedef void SocketOptT;
00140 #endif
00141
00145 #if defined __linux
00146 typedef socklen_t SocketLenT;
00147 #else
00148 typedef int SocketLenT;
00149 #endif
00150
00151
00155 int _sd;
00156
00158
00159 private:
00160
00161 friend class SocketSelection;
00162
00163
00167 static int initialized;
00168
00170 };
00171
00172 OSG_END_NAMESPACE
00173
00174 #define OSG_SOCKET_HEADER_CVSID "@(#)$Id: $"
00175
00176 #endif