#include <OSGDgramSocket.h>
Inheritance diagram for osg::DgramSocket:

Public Member Functions | |
Constructors | |
| * | DgramSocket () |
| DgramSocket (const DgramSocket &source) | |
open/close | |
| *virtual void | open (void) |
| virtual void | close (void) |
read, write | |
| *int | recvFrom (void *buf, int size, SocketAddress &from) |
| int | peekFrom (void *buf, int size, SocketAddress &from) |
| int | recvFrom (NetworkMessage &msg, SocketAddress &from) |
| int | sendTo (const void *buf, int size, const SocketAddress &to) |
| int | sendTo (NetworkMessage &msg, const SocketAddress &to) |
multicast | |
| *void | join (const SocketAddress &group, const SocketAddress &interf=SocketAddress(SocketAddress::ANY)) |
| void | leave (const SocketAddress &group, const SocketAddress &interf=SocketAddress(SocketAddress::ANY)) |
| void | setTTL (unsigned char ttl) |
| void | setMCastInterface (const SocketAddress &interf) |
assignment | |
| *const DgramSocket & | operator= (const DgramSocket &source) |
Protected Types | |
| typedef void | SocketOptT |
| typedef socklen_t | SocketLenT |
Private Types | |
| typedef Socket | Inherited |
Static Private Attributes | |
| static char | cvsid [] |
char buffer[100];
DgramSocket s;
SocketAddress from;
s.open();
s.sendTo(buffer,10,SocketAddress("serverhost.com",4567));
s.recvFrom(buffer,10,from);
s.close();
Definition at line 56 of file OSGDgramSocket.h.
|
|
Definition at line 124 of file OSGDgramSocket.h. |
|
|
Socket option type. Used to hide the different interface implementations Definition at line 139 of file OSGSocket.h. |
|
|
Socket length type. Used to hide the different interface implementations Definition at line 146 of file OSGSocket.h. |
|
|
Constructor. Use open to assign a system socket. No system socket is assigned by the constructor.
Definition at line 100 of file OSGDgramSocket.cpp. 00100 : 00101 Socket() 00102 { 00103 }
|
|
|
Copy constructor Definition at line 107 of file OSGDgramSocket.cpp. 00107 : 00108 Socket(source) 00109 { 00110 }
|
|
|
Assign a socket.
Implements osg::Socket. Definition at line 119 of file OSGDgramSocket.cpp. References osg::Socket::_sd, and setTTL(). Referenced by osg::ClusterServer::acceptClient(), osg::GroupMCastConnection::GroupMCastConnection(), osg::ClusterWindow::init(), and osg::PointMCastConnection::initialize(). 00120 { 00121 _sd = socket(AF_INET, SOCK_DGRAM, 0); 00122 if(_sd<0) 00123 { 00124 throw SocketError("socket()"); 00125 } 00126 // all dgram sockets are allowed to send broadcast 00127 int on = 1; 00128 if(::setsockopt(_sd, 00129 SOL_SOCKET, SO_BROADCAST, 00130 (SocketOptT*)&on, sizeof(on)) < 0) 00131 { 00132 throw SocketError("setsockopt(,SOL_SOCKET,SO_BROADCAST)"); 00133 } 00134 // by default, multicast only in local network 00135 setTTL(2); 00136 }
|
|
|
close socket Implements osg::Socket. Definition at line 140 of file OSGDgramSocket.cpp. References osg::Socket::_sd. Referenced by osg::ClusterServer::acceptClient(), osg::ClusterWindow::init(), osg::GroupMCastConnection::~GroupMCastConnection(), and osg::PointMCastConnection::~PointMCastConnection(). 00141 { 00142 #ifdef WIN32 00143 ::closesocket(_sd); 00144 #else 00145 ::close(_sd); 00146 #endif 00147 }
|
|
||||||||||||||||
|
Read size bytes into the buffer. Wait until size Bytes are available data maight be lossed, if size is smaller then the incomming package. This situation will not be treated as an error.
Definition at line 157 of file OSGDgramSocket.cpp. References osg::Socket::_sd, osg::Socket::getError(), osg::SocketAddress::getSockAddr(), and osg::SocketAddress::getSockAddrSize(). Referenced by osg::ClusterServer::acceptClient(), recvFrom(), osg::PointMCastConnection::recvNextDgram(), and osg::GroupMCastConnection::sendQueue(). 00158 { 00159 int len; 00160 SocketLenT addrLen=from.getSockAddrSize(); 00161 00162 #ifndef WIN32 00163 do 00164 { 00165 #endif 00166 len=recvfrom(_sd, 00167 (char*)buf, 00168 size, 00169 0, 00170 from.getSockAddr(), 00171 &addrLen); 00172 #ifndef WIN32 00173 } 00174 while(len < 0 && errno == EAGAIN); 00175 #endif 00176 00177 if(len < 0) 00178 { 00179 #if defined WIN32 00180 if(getError() == WSAECONNRESET) 00181 { 00182 throw SocketConnReset("recvfrom"); 00183 } 00184 if(getError() == WSAEMSGSIZE) 00185 { 00186 len=size; 00187 } 00188 else 00189 #endif 00190 throw SocketError("recvfrom()"); 00191 } 00192 return len; 00193 }
|
|
||||||||||||||||
|
Read size bytes into the buffer. Wait until size Bytes are available On Dgram sockets data maight be lossed, if size is smaller then the incomming package. This situation will not be treated as an error. The read bytes will not be removed from the in buffer. A call to recv after peek will result in the same data.
Definition at line 202 of file OSGDgramSocket.cpp. References osg::Socket::_sd, osg::Socket::getError(), osg::SocketAddress::getSockAddr(), and osg::SocketAddress::getSockAddrSize(). 00203 { 00204 int len; 00205 SocketLenT addrLen=from.getSockAddrSize(); 00206 00207 len=recvfrom(_sd, 00208 (char*)buf, 00209 size, 00210 MSG_PEEK, 00211 from.getSockAddr(), 00212 &addrLen); 00213 if(len == -1) 00214 { 00215 #if defined WIN32 00216 if(getError() == WSAECONNRESET) 00217 { 00218 throw SocketConnReset("recvfrom"); 00219 } 00220 if(getError() == WSAEMSGSIZE) 00221 { 00222 len=size; 00223 } 00224 else 00225 #endif 00226 throw SocketError("recvfrom()"); 00227 } 00228 return len; 00229 }
|
|
||||||||||||
|
Receive a NetworkMessage. Workes like recv, but buffer and size is taken from the NetworkMessage
Definition at line 235 of file OSGDgramSocket.cpp. References osg::NetworkMessage::getBuffer(), osg::NetworkMessage::getSize(), osg::osgntohl(), osg::Socket::peek(), recvFrom(), and osg::NetworkMessage::setSize(). 00236 { 00237 NetworkMessage::Header hdr; 00238 peek(&hdr,sizeof(hdr)); 00239 msg.setSize(osgntohl(hdr.size)); 00240 return recvFrom(msg.getBuffer(),msg.getSize(),from); 00241 }
|
|
||||||||||||||||
|
Write size bytes to the socket. This method maight block, if the output buffer is full.
Definition at line 247 of file OSGDgramSocket.cpp. References osg::Socket::_sd, osg::SocketAddress::getSockAddr(), and osg::SocketAddress::getSockAddrSize(). Referenced by osg::ClusterServer::acceptClient(), osg::PointMCastConnection::combineAck(), osg::ClusterWindow::init(), osg::PointMCastConnection::recvNextDgram(), osg::PointMCastConnection::recvQueue(), osg::GroupMCastConnection::sendQueue(), sendTo(), and osg::GroupMCastConnection::write(). 00248 { 00249 int len; 00250 00251 // send Request 00252 len=sendto(_sd, 00253 (const char*)buf,size, 00254 #if defined(WIN32) && defined(MSG_NOSIGNAL) 00255 MSG_NOSIGNAL, 00256 #else 00257 0, 00258 #endif 00259 to.getSockAddr(), 00260 to.getSockAddrSize()); 00261 #ifdef _sgi 00262 /* Irix simetimes returns ENOBUFS on blocking write. 00263 Retry until buffer is available */ 00264 while(len == -1 && errno == ENOBUFS) 00265 { 00266 usleep(100); 00267 len=sendto(_sd, 00268 (const char*)buf,size, 00269 0, 00270 to.getSockAddr(), 00271 to.getSockAddrSize()); 00272 } 00273 #endif 00274 00275 if(len == -1) 00276 { 00277 throw SocketError("sendto()"); 00278 } 00279 return len; 00280 }
|
|
||||||||||||
|
Send a NetworkMessage to an address. Workes like send, but buffer and size is taken from the NetworkMessage.
Definition at line 286 of file OSGDgramSocket.cpp. References osg::NetworkMessage::getBuffer(), osg::NetworkMessage::getHeader(), osg::NetworkMessage::getSize(), osg::osghtonl(), sendTo(), and osg::NetworkMessage::Header::size. 00287 { 00288 NetworkMessage::Header &hdr=msg.getHeader(); 00289 hdr.size=osghtonl(msg.getSize()); 00290 return sendTo(msg.getBuffer(),msg.getSize(),to); 00291 }
|
|
||||||||||||
|
The socket will receive all messages from the given multicast address It is possible to join more then on goup. Definition at line 299 of file OSGDgramSocket.cpp. References osg::Socket::_sd, and osg::SocketAddress::getSockAddr(). Referenced by osg::ClusterServer::acceptClient(), and osg::PointMCastConnection::initialize(). 00300 { 00301 struct ip_mreq joinAddr; 00302 int rc; 00303 00304 // group to join 00305 joinAddr.imr_multiaddr.s_addr = 00306 ((sockaddr_in*)group.getSockAddr())->sin_addr.s_addr; 00307 00308 // interface that joins. (equal to bind address) 00309 joinAddr.imr_interface = 00310 ((struct sockaddr_in*)interf.getSockAddr())->sin_addr; 00311 rc=setsockopt(_sd, 00312 IPPROTO_IP, 00313 IP_ADD_MEMBERSHIP, 00314 (SocketOptT*)&joinAddr, 00315 sizeof(joinAddr)); 00316 if(rc < 0) 00317 { 00318 throw SocketError("setsockopt(IPPROTO_IP,IP_ADD_MEMBERSHIP)"); 00319 } 00320 }
|
|
||||||||||||
|
Leave a multicast group. Don't receive messages from the given group. Definition at line 324 of file OSGDgramSocket.cpp. References osg::Socket::_sd, and osg::SocketAddress::getSockAddr(). 00325 { 00326 struct ip_mreq joinAddr; 00327 int rc; 00328 00329 // group to join 00330 joinAddr.imr_multiaddr.s_addr = 00331 ((sockaddr_in*)group.getSockAddr())->sin_addr.s_addr; 00332 // interface that joins. (equal to bind address) 00333 joinAddr.imr_interface = 00334 ((sockaddr_in*)interf.getSockAddr())->sin_addr; 00335 rc=setsockopt(_sd, 00336 IPPROTO_IP, 00337 IP_DROP_MEMBERSHIP, 00338 (SocketOptT*)&joinAddr, 00339 sizeof(joinAddr)); 00340 if(rc < 0) 00341 { 00342 throw SocketError("setsockopt(IPPROTO_IP,IP_DROP_MEMBERSHIP)"); 00343 } 00344 }
|
|
|
Set TTL for broadcast and multicast. Defines how many routers a package will pass until it is deleted. 0 = local host, 1 = local network, ... Definition at line 350 of file OSGDgramSocket.cpp. References osg::Socket::_sd. Referenced by osg::ClusterWindow::init(), open(), and osg::GroupMCastConnection::setParams(). 00351 { 00352 int rc=setsockopt(_sd, IPPROTO_IP,IP_MULTICAST_TTL, 00353 (SocketOptT*)&ttl,sizeof(ttl)); 00354 if(rc < 0) 00355 { 00356 throw SocketError("setsockopt(IPPROTO_IP,IP_MULTICAST_TTL)"); 00357 } 00358 }
|
|
|
Spcify the network interface for outgoing multicast packages Definition at line 363 of file OSGDgramSocket.cpp. References osg::Socket::_sd, osg::SocketAddress::getSockAddr(), and osg::SocketAddress::getSockAddrSize(). Referenced by osg::PointMCastConnection::initialize(), and osg::GroupMCastConnection::initialize(). 00364 { 00365 int rc=setsockopt(_sd, 00366 IPPROTO_IP, 00367 IP_MULTICAST_IF, 00368 (SocketOptT*)interf.getSockAddr(), 00369 interf.getSockAddrSize()); 00370 if(rc < 0) 00371 { 00372 throw SocketError("setsockopt(IPPROTO_IP,IP_MULTICAST_IF)"); 00373 } 00374 00375 }
|
|
|
assignment Definition at line 382 of file OSGDgramSocket.cpp. References osg::Socket::_sd.
|
|
|
Bind a socket to a given SocketAddress. It is possible to bind a Socket to a special network interface ore to all availabel interfaces.
sock.bind(AnySocketAddress(23344)); Bind Socket to port 23344
sock.bind(Address("123.223.112.33",0); Bind to the given adapter
sock.bind(AnySocketAddress(0)); Bind to a free port
port = sock.getAddress().getPort(); Get bound port
Definition at line 150 of file OSGSocket.cpp. References osg::Socket::_sd, osg::Socket::getError(), osg::SocketAddress::getSockAddr(), and osg::SocketAddress::getSockAddrSize(). Referenced by osg::ClusterServer::acceptClient(), osg::PointSockConnection::bind(), osg::GroupSockConnection::bind(), osg::GroupMCastConnection::GroupMCastConnection(), osg::PointSockPipeline::initialize(), and osg::PointMCastConnection::initialize(). 00151 { 00152 SocketAddress result=address; 00153 00154 if( ::bind(_sd, 00155 result.getSockAddr(), 00156 result.getSockAddrSize()) < 0) 00157 { 00158 if(getError() == 00159 #if defined WIN32 00160 WSAEADDRINUSE 00161 #else 00162 EADDRINUSE 00163 #endif 00164 ) 00165 { 00166 throw SocketInUse("bind()"); 00167 } 00168 else 00169 { 00170 throw SocketError("bind()"); 00171 } 00172 } 00173 }
|
|
|
Set queue length for incomming connection requests Definition at line 177 of file OSGSocket.cpp. References osg::Socket::_sd. Referenced by osg::PointSockConnection::bind(), osg::GroupSockConnection::bind(), and osg::PointSockPipeline::initialize(). 00178 { 00179 if(::listen(_sd,maxPending)<0) 00180 { 00181 throw SocketError("listen()"); 00182 } 00183 }
|
|
|
Connect to the given address. After connect, all send data will be transfered to the address. Definition at line 188 of file OSGSocket.cpp. References osg::Socket::_sd, osg::SocketAddress::getSockAddr(), and osg::SocketAddress::getSockAddrSize(). Referenced by osg::GroupSockConnection::connectSocket(), osg::PointSockPipeline::initialize(), and osg::GroupSockPipeline::initialize(). 00189 { 00190 if( ::connect(_sd, 00191 address.getSockAddr(), 00192 address.getSockAddrSize()) ) 00193 { 00194 throw SocketError("connect()"); 00195 } 00196 }
|
|
||||||||||||
|
Read size bytes into the buffer. Wait until size Bytes are available On Dgram sockets data maight be lossed, if size is smaller then the incomming package. This situation will not be treated as an error.
Definition at line 206 of file OSGSocket.cpp. References osg::Socket::_sd, and osg::Socket::getError(). Referenced by osg::ClusterWindow::init(), osg::PointSockPipeline::initialize(), osg::PointMCastConnection::initialize(), osg::Socket::peek(), osg::PointSockPipeline::read(), osg::PointSockConnection::read(), osg::PointSockPipeline::readBuffer(), osg::PointSockConnection::readBuffer(), osg::Socket::recv(), osg::Socket::recvAvailable(), and osg::PointMCastConnection::recvQueue(). 00207 { 00208 int readSize; 00209 int pos=0; 00210 00211 while(size) 00212 { 00213 readSize=::recv(_sd,((char*)buf) + pos,size,0); 00214 if(readSize < 0) 00215 { 00216 #if defined WIN32 00217 if(getError() == WSAECONNRESET) 00218 { 00219 throw SocketConnReset("recv"); 00220 } 00221 if(getError() == WSAEMSGSIZE) 00222 { 00223 readSize=size; 00224 } 00225 else 00226 #endif 00227 throw SocketError("recv()"); 00228 } 00229 if(readSize == 0) 00230 { 00231 return 0; 00232 } 00233 size-=readSize; 00234 pos +=readSize; 00235 } 00236 return pos; 00237 }
|
|
|
Like recv, but buffer and size is taken from the NetworkMessage
Definition at line 280 of file OSGSocket.cpp. References osg::NetworkMessage::getBuffer(), osg::NetworkMessage::getSize(), osg::osgntohl(), osg::Socket::peek(), osg::Socket::recv(), and osg::NetworkMessage::setSize(). 00281 { 00282 NetworkMessage::Header hdr; 00283 peek(&hdr,sizeof(hdr)); 00284 msg.setSize(osgntohl(hdr.size)); 00285 return recv(msg.getBuffer(),msg.getSize()); 00286 }
|
|
||||||||||||
|
Read the data from the in buffer to a maximun length of size. don't wait until size bytes are available.
Definition at line 243 of file OSGSocket.cpp. References osg::Socket::_sd, osg::Socket::getError(), and osg::Socket::recv(). 00244 { 00245 int len; 00246 00247 #ifndef WIN32 00248 do 00249 { 00250 #endif 00251 len=::recv(_sd,(char*)buf,size,0); 00252 #ifndef WIN32 00253 } 00254 while(len < 0 && errno == EAGAIN); 00255 #endif 00256 if(len==-1) 00257 { 00258 #if defined WIN32 00259 switch(getError()) 00260 { 00261 case WSAECONNRESET: 00262 throw SocketConnReset("recvAvailable()"); 00263 break; 00264 case WSAEMSGSIZE: 00265 len=size; 00266 break; 00267 default: 00268 throw SocketError("recv()"); 00269 } 00270 #else 00271 throw SocketError("recv()"); 00272 #endif 00273 } 00274 return len; 00275 }
|
|
||||||||||||
|
Read size bytes into the buffer. Wait until size Bytes are available On Dgram sockets data maight be lossed, if size is smaller then the incomming package. This situation will not be treated as an error. The read bytes will not be removed from the in buffer. A call to recv after peek will result in the same data.
Definition at line 295 of file OSGSocket.cpp. References osg::Socket::_sd, osg::Socket::getError(), and osg::Socket::recv(). Referenced by osg::Socket::recv(), and recvFrom(). 00296 { 00297 int readSize; 00298 int pos=0; 00299 00300 do 00301 { 00302 readSize=::recv(_sd,((char*)buf)+pos,size,MSG_PEEK); 00303 if(readSize<0) 00304 { 00305 #if defined WIN32 00306 if(getError() == WSAECONNRESET) 00307 { 00308 throw SocketConnReset("peek"); 00309 } 00310 if(getError() == WSAEMSGSIZE) 00311 { 00312 readSize=size; 00313 } 00314 else 00315 #endif 00316 throw SocketError("peek"); 00317 } 00318 if(readSize == 0) 00319 { 00320 return 0; 00321 } 00322 } 00323 while(readSize != size); 00324 return readSize; 00325 }
|
|
||||||||||||
|
Write size bytes to the socket. This method maight block, if the output buffer is full. Definition at line 330 of file OSGSocket.cpp. References osg::Socket::_sd. Referenced by osg::PointSockPipeline::initialize(), osg::PointMCastConnection::initialize(), osg::PointSockPipeline::read(), osg::PointSockPipeline::readBuffer(), osg::Socket::send(), osg::PointSockConnection::signal(), osg::PointSockConnection::write(), osg::GroupSockPipeline::write(), osg::PointSockConnection::writeBuffer(), and osg::GroupSockPipeline::writeBuffer(). 00331 { 00332 int writeSize; 00333 int pos=0; 00334 while(size) 00335 { 00336 #if defined(WIN32) && defined(MSG_NOSIGNAL) 00337 writeSize=::send(_sd,((const char*)buf)+pos,size,MSG_NOSIGNAL); 00338 #else 00339 writeSize=::send(_sd,((const char*)buf)+pos,size,0); 00340 #endif 00341 if(writeSize == -1) 00342 { 00343 throw SocketError("send()"); 00344 } 00345 if(writeSize == 0) 00346 { 00347 return 0; 00348 } 00349 size-=writeSize; 00350 pos+=writeSize; 00351 } 00352 return pos; 00353 }
|
|
|
Like send, but buffer and size is taken from the NetworkMessage
Definition at line 358 of file OSGSocket.cpp. References osg::NetworkMessage::getBuffer(), osg::NetworkMessage::getHeader(), osg::NetworkMessage::getSize(), osg::osghtonl(), osg::Socket::send(), and osg::NetworkMessage::Header::size. 00359 { 00360 NetworkMessage::Header &hdr=msg.getHeader(); 00361 hdr.size=osghtonl(msg.getSize()); 00362 return send(msg.getBuffer(),msg.getSize()); 00363 }
|
|
|
Enable, disable reuse port behavior If reuse port is true, then more then on process or thread is able to bind to the same port. This makes sense for multicast or braodcast sockets. For StreamSockets this feature can be used to avoid the Socket in use message on not propperly closed ports. Definition at line 374 of file OSGSocket.cpp. References osg::Socket::_sd. Referenced by osg::ClusterServer::acceptClient(), osg::PointSockConnection::bind(), osg::GroupSockConnection::bind(), osg::GroupSockConnection::GroupSockConnection(), osg::PointMCastConnection::initialize(), osg::PointMCastConnection::PointMCastConnection(), and osg::PointSockConnection::PointSockConnection(). 00375 { 00376 int v=(int)value; 00377 #ifdef SO_REUSEPORT 00378 ::setsockopt(_sd,SOL_SOCKET,SO_REUSEPORT,(SocketOptT*)&v,sizeof(v)); 00379 #endif 00380 ::setsockopt(_sd,SOL_SOCKET,SO_REUSEADDR,(SocketOptT*)&v,sizeof(v)); 00381 }
|
|
|
By default all recv, send, accept calls will block until the executeion is finished. This behavior can be swithed off bei setting blocking to false. This will lead to a more difficult programming. An easier way to get non blocking behavior is to use SocketSelections or waitReadable, waitWritable. These methods provide a timeout for waiting. Definition at line 391 of file OSGSocket.cpp. References osg::Socket::_sd. 00392 { 00393 #ifndef WIN32 00394 int val=0; 00395 00396 if(value==false) 00397 val=O_NDELAY; 00398 if (fcntl(_sd, F_GETFL, &val) < 0) 00399 { 00400 throw SocketError("fcntl()"); 00401 } 00402 val|=O_NDELAY; 00403 if(value) 00404 { 00405 val^=O_NDELAY; 00406 } 00407 if (fcntl(_sd, F_SETFL, val) < 0) 00408 { 00409 throw SocketError("fcntl()"); 00410 } 00411 #else 00412 u_long ulVal = !value; 00413 if( (ioctlsocket(_sd, FIONBIO, &ulVal)) != 0) 00414 { 00415 throw SocketError("ioctlsocket()"); 00416 } 00417 #endif 00418 }
|
|
|
Get bound SocketAddress
Definition at line 423 of file OSGSocket.cpp. References osg::Socket::_sd, osg::SocketAddress::getSockAddr(), and osg::SocketAddress::getSockAddrSize(). Referenced by osg::PointSockConnection::bind(), osg::GroupSockConnection::bind(), osg::PointSockPipeline::initialize(), osg::PointMCastConnection::initialize(), and osg::GroupMCastConnection::initialize(). 00424 { 00425 SocketAddress result; 00426 SocketLenT len; 00427 00428 len=result.getSockAddrSize(); 00429 if( ::getsockname(_sd,result.getSockAddr(),&len) < 0) 00430 { 00431 throw SocketError("getsockname()"); 00432 } 00433 return result; 00434 }
|
|
|
Set the internal read buffer size
Definition at line 439 of file OSGSocket.cpp. References osg::Socket::_sd. Referenced by osg::GroupSockConnection::acceptSocket(), osg::GroupSockConnection::connectSocket(), osg::GroupMCastConnection::GroupMCastConnection(), and osg::PointMCastConnection::initialize(). 00440 { 00441 int v=(int)size; 00442 ::setsockopt(_sd,SOL_SOCKET,SO_RCVBUF,(SocketOptT*)&v,sizeof(v)); 00443 }
|
|
|
Set the internal write buffer size
Definition at line 448 of file OSGSocket.cpp. References osg::Socket::_sd. Referenced by osg::GroupSockConnection::acceptSocket(), and osg::GroupSockConnection::connectSocket(). 00449 { 00450 int v=(int)size; 00451 ::setsockopt(_sd,SOL_SOCKET,SO_SNDBUF,(SocketOptT*)&v,sizeof(v)); 00452 }
|
|
|
Get internal read buffer size
Definition at line 457 of file OSGSocket.cpp. References osg::Socket::_sd. Referenced by osg::GroupMCastConnection::GroupMCastConnection(). 00458 { 00459 int v; 00460 SocketLenT len=sizeof(v); 00461 ::getsockopt(_sd,SOL_SOCKET,SO_RCVBUF,(SocketOptT*)&v,&len); 00462 return v; 00463 }
|
|
|
Get internal write buffer size
Definition at line 468 of file OSGSocket.cpp. References osg::Socket::_sd. 00469 { 00470 int v; 00471 SocketLenT len=sizeof(v); 00472 ::getsockopt(_sd,SOL_SOCKET,SO_SNDBUF,(SocketOptT*)&v,&len); 00473 return v; 00474 }
|
|
|
Get number of bytes in the internal read buffer Definition at line 478 of file OSGSocket.cpp. References osg::Socket::_sd. 00479 { 00480 #ifndef WIN32 00481 int value; 00482 if(::ioctl(_sd, FIONREAD, &value)<0) 00483 { 00484 throw SocketError("ioctl()"); 00485 } 00486 return value; 00487 #else 00488 u_long ulVal; 00489 if( (ioctlsocket(_sd, FIONREAD, &ulVal)) != 0) 00490 { 00491 throw SocketError("ioctlsocket()"); 00492 } 00493 return (int)ulVal; 00494 #endif 00495 }
|
|
|
Wait until recv or accept will not block. True is returned if data is available. Definition at line 500 of file OSGSocket.cpp. References osg::SocketSelection::select(), and osg::SocketSelection::setRead(). Referenced by osg::ClusterServer::acceptClient(), osg::GroupSockConnection::acceptSocket(), osg::ClusterWindow::init(), osg::PointMCastConnection::recvQueue(), and osg::GroupMCastConnection::sendQueue(). 00501 { 00502 SocketSelection selection; 00503 selection.setRead(*this); 00504 if(selection.select(duration)==1) 00505 return true; 00506 else 00507 return false; 00508 }
|
|
|
Wait until send will not block for the given duration. True is returned if the next send will not block. Definition at line 513 of file OSGSocket.cpp. References osg::SocketSelection::select(), and osg::SocketSelection::setWrite(). 00514 { 00515 SocketSelection selection; 00516 selection.setWrite(*this); 00517 if(selection.select(duration)==1) 00518 return true; 00519 else 00520 return false; 00521 }
|
|
|
Get last occured error Definition at line 536 of file OSGSocket.cpp. Referenced by osg::Socket::bind(), osg::Socket::getErrorStr(), osg::Socket::peek(), peekFrom(), osg::Socket::recv(), osg::Socket::recvAvailable(), recvFrom(), and osg::SocketError::SocketError(). 00537 { 00538 #ifdef WIN32 00539 return WSAGetLastError(); 00540 #else 00541 return errno; 00542 #endif 00543 }
|
|
|
Get last host error Definition at line 547 of file OSGSocket.cpp. Referenced by osg::Socket::getHostErrorStr(), and osg::SocketHostError::SocketHostError(). 00548 { 00549 #ifdef WIN32 00550 return WSAGetLastError(); 00551 #else 00552 return h_errno; 00553 #endif 00554 }
|
|
|
Get last occured error as string Definition at line 558 of file OSGSocket.cpp. References osg::Socket::getError(). Referenced by osg::SocketError::SocketError(). 00559 { 00560 const char *err=NULL; 00561 00562 #ifdef WIN32 00563 switch(getError()) 00564 { 00565 case WSAEINTR: err= "WSAEINTR"; break; 00566 case WSAEBADF: err= "WSAEBADF"; break; 00567 case WSAEFAULT: err= "WSAEFAULT"; break; 00568 case WSAEINVAL: err= "WSAEINVAL"; break; 00569 case WSAEMFILE: err= "WSAEMFILE"; break; 00570 case WSAEWOULDBLOCK: err= "WSAEWOULDBLOCK"; break; 00571 |