Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::StreamSocket Class Reference
[Network]

Stream socket handler. More...

#include <OSGStreamSocket.h>

Inheritance diagram for osg::StreamSocket:

osg::Socket List of all members.

Public Member Functions

open, close, connect
void bind (const SocketAddress &address=SocketAddress(SocketAddress::ANY))
void listen (int maxPending=10)
void connect (const SocketAddress &address)
read, write
*int recv (void *buf, int size)
int recv (NetworkMessage &msg)
int recvAvailable (void *buf, int size)
int peek (void *buf, int size)
int send (const void *buf, int size)
int send (NetworkMessage &msg)
state access
*void setReusePort (bool value)
void setBlocking (bool value)
SocketAddress getAddress (void)
void setReadBufferSize (int size)
void setWriteBufferSize (int size)
int getReadBufferSize (void)
int getWriteBufferSize (void)
int getAvailable (void)
bool waitReadable (double duration)
bool waitWritable (double duration)
Constructors
StreamSocket ()
 StreamSocket (const StreamSocket &source)
 Copy constructor.
Socket functionaliy
*virtual void open (void)
virtual void close (void)
StreamSocket acceptFrom (SocketAddress &address)
StreamSocket accept (void)
void setDelay (bool value)
Assignment
*const StreamSocketoperator= (const StreamSocket &source)
open, close, connect
void bind (const SocketAddress &address=SocketAddress(SocketAddress::ANY))
void listen (int maxPending=10)
void connect (const SocketAddress &address)
read, write
*int recv (void *buf, int size)
int recv (NetworkMessage &msg)
int recvAvailable (void *buf, int size)
int peek (void *buf, int size)
int send (const void *buf, int size)
int send (NetworkMessage &msg)
state access
*void setReusePort (bool value)
void setBlocking (bool value)
SocketAddress getAddress (void)
void setReadBufferSize (int size)
void setWriteBufferSize (int size)
int getReadBufferSize (void)
int getWriteBufferSize (void)
int getAvailable (void)
bool waitReadable (double duration)
bool waitWritable (double duration)

Static Public Member Functions

static const char * getClassname (void)
Error information
*static int getError (void)
static int getHostError (void)
static std::string getErrorStr (void)
static std::string getHostErrorStr (void)
Error information
*static int getError (void)
static int getHostError (void)
static std::string getErrorStr (void)
static std::string getHostErrorStr (void)

Protected Types

typedef void SocketOptT
typedef socklen_t SocketLenT

Protected Attributes

member
*int _sd
member
*int _sd

Private Types

typedef Socket Inherited

Detailed Description

This class is a Handler to connection oriented sockets. A call to open will assing a stream socket and close releases the socket.

Client example

 char buffer[100];
 StreamSocket s;
 s.open();
 s.connect(Address("serverhost.com",4567);
 s.send(buffer,100);
 s.close();
 

Server example

 char buffer[100];
 StreamSocket s;
 s.open();
 s.bind(AnySocketAddress(4567);
 c=s.accept();               // accept incomming client
 c.recv(buffer,100);         // read client message
 c.close();
 s.close();
 

Definition at line 56 of file OSGStreamSocket.h.


Member Typedef Documentation

typedef Socket osg::StreamSocket::Inherited [private]
 

Definition at line 96 of file OSGStreamSocket.h.

typedef void osg::Socket::SocketOptT [protected, inherited]
 

Socket option type. Used to hide the different interface implementations

Definition at line 139 of file OSGSocket.h.

typedef socklen_t osg::Socket::SocketLenT [protected, inherited]
 

Socket length type. Used to hide the different interface implementations

Definition at line 146 of file OSGSocket.h.


Constructor & Destructor Documentation

StreamSocket::StreamSocket  ) 
 

Constructor. Use open to assign a system socket. No system socket is assigned by the constructor.

See also:
StreamSocket::open

Definition at line 106 of file OSGStreamSocket.cpp.

00106                           :
00107     Socket()
00108 {
00109 }

StreamSocket::StreamSocket const StreamSocket source  ) 
 

Definition at line 113 of file OSGStreamSocket.cpp.

00113                                                     :
00114     Socket(source)
00115 {
00116 }


Member Function Documentation

static const char* osg::StreamSocket::getClassname void   )  [inline, static]
 

Definition at line 61 of file OSGStreamSocket.h.

00061 { return "CLASSNAME"; }

void StreamSocket::open void   )  [virtual]
 

Assign a socket. Open assignes a system socket to the StreamSocket.

See also:
Socket::close

Implements osg::Socket.

Definition at line 125 of file OSGStreamSocket.cpp.

References osg::Socket::_sd.

Referenced by osg::GroupSockConnection::connectSocket(), osg::GroupSockConnection::GroupSockConnection(), osg::GroupSockPipeline::GroupSockPipeline(), osg::PointSockPipeline::initialize(), osg::PointMCastConnection::PointMCastConnection(), osg::PointSockConnection::PointSockConnection(), and osg::PointSockPipeline::PointSockPipeline().

00126 {
00127     _sd = ::socket(AF_INET, SOCK_STREAM, 0);
00128     if(_sd < 0)
00129     {
00130         throw SocketError("socket()");
00131     }
00132     struct linger li;
00133     li.l_onoff = 1;
00134     li.l_linger = 1;
00135     int rc = setsockopt(_sd, SOL_SOCKET, SO_LINGER, 
00136                         (SocketOptT*)&li, sizeof(li));
00137 }

void StreamSocket::close void   )  [virtual]
 

close socket

Implements osg::Socket.

Definition at line 141 of file OSGStreamSocket.cpp.

References osg::Socket::_sd.

Referenced by osg::PointSockPipeline::disconnect(), osg::PointSockConnection::disconnect(), osg::PointMCastConnection::disconnect(), osg::PointSockPipeline::initialize(), osg::GroupSockConnection::~GroupSockConnection(), osg::GroupSockPipeline::~GroupSockPipeline(), osg::PointMCastConnection::~PointMCastConnection(), osg::PointSockConnection::~PointSockConnection(), and osg::PointSockPipeline::~PointSockPipeline().

00142 {
00143 #ifdef WIN32
00144     ::closesocket(_sd);
00145 #else
00146     ::close(_sd);
00147 #endif
00148 }

StreamSocket StreamSocket::acceptFrom SocketAddress address  ) 
 

Accept incomming connection. Use the returned StreamSocket to communicate over the accepted communication. If the new StreamSocket is no longer used, you have to close it. A new StreamSocket is returned to communicate with the accepted client.

Definition at line 155 of file OSGStreamSocket.cpp.

References osg::Socket::_sd, accept(), osg::SocketAddress::getSockAddr(), and osg::SocketAddress::getSockAddrSize().

Referenced by accept().

00156 {
00157     StreamSocket client;
00158     SocketLenT len;
00159     
00160     len=address.getSockAddrSize();
00161     client._sd=::accept(_sd,
00162                         address.getSockAddr(),
00163                         &len);
00164     if(client._sd < 0)
00165     {
00166         throw SocketError("accept()");
00167     }
00168     return client;
00169 }

StreamSocket StreamSocket::accept void   ) 
 

Accept incomming connection. Use the returned StreamSocket to communicate over the accepted communication. If the new StreamSocket is no longer used, you have to close it.

Definition at line 175 of file OSGStreamSocket.cpp.

References acceptFrom().

Referenced by acceptFrom(), osg::GroupSockConnection::acceptSocket(), and osg::PointSockPipeline::initialize().

00176 {
00177     SocketAddress addr;
00178     return acceptFrom(addr);
00179 }

void StreamSocket::setDelay bool  value  ) 
 

A Stream socket doesen't send data immediately. Only if the internal buffer contains enough data, an immediate write is forced. If delay is set to false, then data is written always immediately.

Definition at line 185 of file OSGStreamSocket.cpp.

References osg::Socket::_sd.

Referenced by osg::GroupSockConnection::acceptSocket(), and osg::GroupSockConnection::connectSocket().

00186 {
00187     int rc,on;
00188     on=!value;
00189     rc=setsockopt(_sd, IPPROTO_TCP, TCP_NODELAY, 
00190                   (SocketOptT*)&on, sizeof(on));
00191     if(rc < 0)
00192     {
00193         throw SocketError("setsockopt(,SOCK_STREAM,TCP_NODELAY)");
00194     }
00195 }

const StreamSocket & StreamSocket::operator= const StreamSocket source  ) 
 

assignment

Definition at line 202 of file OSGStreamSocket.cpp.

References osg::Socket::_sd.

00203 {
00204     _sd=source._sd;
00205     return *this;
00206 }

void Socket::bind const SocketAddress address = SocketAddress(SocketAddress::ANY)  )  [inherited]
 

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 }

void Socket::listen int  maxPending = 10  )  [inherited]
 

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 }

void Socket::connect const SocketAddress address  )  [inherited]
 

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 }

int Socket::recv void *  buf,
int  size
[inherited]
 

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.

See also:
recvAvailable recvFrom

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 }

int Socket::recv NetworkMessage msg  )  [inherited]
 

Like recv, but buffer and size is taken from the NetworkMessage

See also:
recv

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 }

int Socket::recvAvailable void *  buf,
int  size
[inherited]
 

Read the data from the in buffer to a maximun length of size. don't wait until size bytes are available.

See also:
recv

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 }

int Socket::peek void *  buf,
int  size
[inherited]
 

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.

See also:
recv recvAvailable

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 osg::DgramSocket::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 }

int Socket::send const void *  buf,
int  size
[inherited]
 

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 }

int Socket::send NetworkMessage msg  )  [inherited]
 

Like send, but buffer and size is taken from the NetworkMessage

See also:
send

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 }

void Socket::setReusePort bool  value  )  [inherited]
 

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 }

void Socket::setBlocking bool  value  )  [inherited]
 

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.

See also:
Socket::waitReadable Socket::waitWritable SocketSelection

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 }

SocketAddress Socket::getAddress void   )  [inherited]
 

Get bound SocketAddress

See also:
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 }

void Socket::setReadBufferSize int  size  )  [inherited]
 

Set the internal read buffer size

See also:
Socket::getReadBufferSize

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 }

void Socket::setWriteBufferSize int  size  )  [inherited]
 

Set the internal write buffer size

See also:
Socket::getWriteBufferSize

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 }

int Socket::getReadBufferSize void   )  [inherited]
 

Get internal read buffer size

See also:
Socket::setReadBufferSize

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 }

int Socket::getWriteBufferSize void   )  [inherited]
 

Get internal write buffer size

See also:
Socket::setWriteBufferSize

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 }

int Socket::getAvailable void   )  [inherited]
 

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 }

bool Socket::waitReadable double  duration  )  [inherited]
 

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 }

bool Socket::waitWritable double  duration  )  [inherited]
 

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 }

int Socket::getError void   )  [static, inherited]
 

Get last occured error

Definition at line 536 of file OSGSocket.cpp.

Referenced by osg::Socket::bind(), osg::Socket::getErrorStr(), osg::Socket::peek(), osg::DgramSocket::peekFrom(), osg::Socket::recv(), osg::Socket::recvAvailable(), osg::DgramSocket::recvFrom(), and osg::SocketError::SocketError().

00537 {
00538 #ifdef WIN32
00539     return WSAGetLastError();
00540 #else
00541     return errno;
00542 #endif
00543 }

int Socket::getHostError void   )  [static, inherited]
 

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 }

std::string Socket::getErrorStr void   )  [static, inherited]
 

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         case WSAEINPROGRESS: err= "WSAEINPROGRESS"; break; 
00572         case WSAEALREADY: err= "WSAEALREADY"; break; 
00573         case WSAENOTSOCK: err= "WSAENOTSOCK"; break; 
00574         case WSAEDESTADDRREQ: err= "WSAEDESTADDRREQ"; break; 
00575         case WSAEMSGSIZE: err= "WSAEMSGSIZE"; break; 
00576         case WSAEPROTOTYPE: err= "WSAEPROTOTYPE"; break; 
00577         case WSAENOPROTOOPT: err= "WSAENOPROTOOPT"; break; 
00578         case WSAEPROTONOSUPPORT: err= "WSAEPROTONOSUPPORT"; break; 
00579         case WSAESOCKTNOSUPPORT: err= "WSAESOCKTNOSUPPORT"; break; 
00580         case WSAEOPNOTSUPP: err= "WSAEOPNOTSUPP"; break; 
00581         case WSAEPFNOSUPPORT: err= "WSAEPFNOSUPPORT"; break; 
00582         case WSAEAFNOSUPPORT: err= "WSAEAFNOSUPPORT"; break; 
00583         case WSAEADDRINUSE: err= "WSAEADDRINUSE"; break; 
00584         case WSAEADDRNOTAVAIL: err= "WSAEADDRNOTAVAIL"; break; 
00585         case WSAENETDOWN: err= "WSAENETDOWN"; break; 
00586         case WSAENETUNREACH: err= "WSAENETUNREACH"; break; 
00587         case WSAENETRESET: err= "WSAENETRESET"; break; 
00588         case WSAECONNABORTED: err= "WSAECONNABORTED"; break; 
00589         case WSAECONNRESET: err= "WSAECONNRESET"; break; 
00590         case WSAENOBUFS: err= "WSAENOBUFS"; break; 
00591         case WSAEISCONN: err= "WSAEISCONN"; break; 
00592         case WSAENOTCONN: err= "WSAENOTCONN"; break; 
00593         case WSAESHUTDOWN: err= "WSAESHUTDOWN"; break; 
00594         case WSAETOOMANYREFS: err= "WSAETOOMANYREFS"; break; 
00595         case WSAETIMEDOUT: err= "WSAETIMEDOUT"; break; 
00596         case WSAECONNREFUSED: err= "WSAECONNREFUSED"; break; 
00597         case WSAELOOP: err= "WSAELOOP"; break; 
00598         case WSAENAMETOOLONG: err= "WSAENAMETOOLONG"; break; 
00599         case WSAEHOSTDOWN: err= "WSAEHOSTDOWN"; break; 
00600         case WSAEHOSTUNREACH: err= "WSAEHOSTUNREACH"; break; 
00601         case WSASYSNOTREADY: err= "WSASYSNOTREADY"; break; 
00602         case WSAVERNOTSUPPORTED: err= "WSAVERNOTSUPPORTED"; break; 
00603         case WSANOTINITIALISED: err= "WSANOTINITIALISED"; break; 
00604         case WSAHOST_NOT_FOUND: err= "WSAHOST_NOT_FOUND"; break; 
00605         case WSATRY_AGAIN: err= "WSATRY_AGAIN"; break; 
00606         case WSANO_RECOVERY: err= "WSANO_RECOVERY"; break; 
00607         case WSANO_DATA: err= "WSANO_DATA"; break; 
00608     }
00609 #else
00610     err=strerror(getError());
00611 #endif
00612     if(err)
00613         return std::string(err);
00614     else
00615         return std::string("Unknown error");
00616 }

std::string Socket::getHostErrorStr void   )  [static, inherited]
 

Get last occured host error as string

Definition at line 620 of file OSGSocket.cpp.

References osg::Socket::getHostError().

Referenced by osg::SocketHostError::SocketHostError().

00621 {
00622     const char *err;
00623 #if defined(WIN32) || defined(__hpux)
00624     err = strerror(getHostError());
00625 #else
00626     err = hstrerror(getHostError());
00627 #endif
00628     if(err)
00629         return std::string(err);
00630     else
00631         return std::string("Unknown error");
00632 }


Member Data Documentation

* int osg::Socket::_sd [protected, inherited]
 

Definition at line 155 of file OSGSocket.h.

Referenced by acceptFrom(), osg::Socket::bind(), osg::SocketSelection::clearRead(), osg::SocketSelection::clearWrite(), close(), osg::DgramSocket::close(), osg::Socket::connect(), osg::Socket::getAddress(), osg::Socket::getAvailable(), osg::Socket::getReadBufferSize(), osg::Socket::getWriteBufferSize(), osg::SocketSelection::isSetRead(), osg::SocketSelection::isSetWrite(), osg::DgramSocket::join(), osg::DgramSocket::leave(), osg::Socket::listen(), open(), osg::DgramSocket::open(), operator=(), osg::Socket::operator=(), osg::DgramSocket::operator=(), osg::Socket::peek(), osg::DgramSocket::peekFrom(), osg::Socket::recv(), osg::Socket::recvAvailable(), osg::DgramSocket::recvFrom(), osg::Socket::send(), osg::DgramSocket::sendTo(), osg::Socket::setBlocking(), setDelay(), osg::DgramSocket::setMCastInterface(), osg::SocketSelection::setRead(), osg::Socket::setReadBufferSize(), osg::Socket::setReusePort(), osg::DgramSocket::setTTL(), osg::SocketSelection::setWrite(), and osg::Socket::setWriteBufferSize().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:12:58 2005 for OpenSG by  doxygen 1.4.3