1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
45 #include "OSGBaseDef.h"
46 #include "OSGSocketException.h"
47 #include "OSGSocketAddress.h"
53 /*! \ingroup GrpBaseNetwork
54 \ingroup GrpBaseNetworkSockets
55 \ingroup GrpLibOSGBase
58 class OSG_BASE_DLLMAPPING Socket
60 /*========================== PUBLIC =================================*/
62 /*---------------------------------------------------------------------*/
63 /*! \name Constructors */
67 Socket(const Socket
&source
);
70 /*---------------------------------------------------------------------*/
71 /*! \name Destructor */
77 /*---------------------------------------------------------------------*/
78 /*! \name open, close, connect */
81 virtual void open ( void ) = 0;
82 virtual void close ( void ) = 0;
83 void bind (const SocketAddress
&address
=
84 SocketAddress(SocketAddress::ANY
));
85 void listen ( int maxPending
=10 );
86 void connect(const SocketAddress
&address
);
89 /*---------------------------------------------------------------------*/
90 /*! \name read, write */
93 int recv ( void *buf
,int size
);
94 int recvAvailable( void *buf
,int size
);
95 int recv ( NetworkMessage
&msg
);
96 int peek ( void *buf
,int size
);
97 int send (const void *buf
,int size
);
98 int send ( NetworkMessage
&msg
);
101 /*---------------------------------------------------------------------*/
102 /*! \name state access */
105 void setReusePort (bool value
);
106 void setBlocking (bool value
);
107 SocketAddress
getAddress (void );
108 void setReadBufferSize (int size
);
109 void setWriteBufferSize(int size
);
110 int getReadBufferSize (void );
111 int getWriteBufferSize(void );
112 int getAvailable (void );
113 bool waitReadable (double duration
);
114 bool waitWritable (double duration
);
117 /*---------------------------------------------------------------------*/
118 /*! \name Assignment */
121 const Socket
& operator =(const Socket
&source
);
124 /*---------------------------------------------------------------------*/
125 /*! \name Error information */
128 static int getError (void);
129 static int getHostError (void);
130 static std::string
getErrorStr (void);
131 static std::string
getHostErrorStr(void);
135 /*========================== PROTECTED ===============================*/
138 /*! Socket option type. Used to hide the different interface
142 typedef char FAR SocketOptT
;
144 typedef void SocketOptT
;
147 /*! Socket length type. Used to hide the different interface
150 #if defined(__linux) || defined(__APPLE__)
151 typedef socklen_t SocketLenT
;
153 typedef int SocketLenT
;
156 /*---------------------------------------------------------------------*/
163 /*========================== PRIVATE =================================*/
166 friend class SocketSelection
;
168 /*---------------------------------------------------------------------*/
169 /*! \name static member */
172 static int initialized
;