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

osg::SocketSelection Class Reference
[Network]

Wait or check one or more sockets for read/write blocking. More...

#include <OSGSocketSelection.h>

List of all members.

Public Member Functions

Constructors
SocketSelection ()
 Constructor.
 SocketSelection (const SocketSelection &source)
 Copy constructor.
Destructor
~SocketSelection ()
 Destructor.
SocketSelection functions
*void clear (void)
 Clear all settings.
void clearRead (const Socket &soc)
 Clear read settings for the given socket.
void clearWrite (const Socket &soc)
 Clear write settings for the given socket.
void setRead (const Socket &soc)
 Set read flag for the given socket.
void setWrite (const Socket &soc)
 Set write flag for the given socket.
bool isSetRead (const Socket &soc)
 Check if read flag is set for a socket.
bool isSetWrite (const Socket &soc)
 Check if write flag is set for a socket.
int select (double time)
 Start selection.
int select (double time, SocketSelection &result) const
 Start selection.
assignment
*const SocketSelectionoperator= (const SocketSelection &source)
 assignment

Protected Attributes

fd_set _fdSetRead
fd_set _fdSetWrite


Detailed Description

Author:
Marcus Roth
You can use a SocketSelection to wait for data on one ore more sockets. It is possible to use a timeout as a maximum wait time.

Example:

 SocketSelection sel;
 Socket s1,s2;
 ...
 sel.setRead(s1);
 sel.setRead(s2);
 if(sel.select(2))
 {
   if(sel.isSetRead(s1)) cout << "Data on s1" << endl;
   if(sel.isSetRead(s2)) cout << "Data on s2" << endl;
 }
 else
 {
   cout << "No data after 2 seconds" << endl;
 }
 

Definition at line 63 of file OSGSocketSelection.h.


Constructor & Destructor Documentation

SocketSelection::SocketSelection  ) 
 

Definition at line 116 of file OSGSocketSelection.cpp.

References clear().

00117 {
00118     clear();
00119 }

SocketSelection::SocketSelection const SocketSelection source  ) 
 

Definition at line 124 of file OSGSocketSelection.cpp.

00124                                                              :
00125     _fdSetRead (source._fdSetRead),
00126     _fdSetWrite(source._fdSetWrite)
00127 {
00128 }

SocketSelection::~SocketSelection  ) 
 

Definition at line 133 of file OSGSocketSelection.cpp.

00134 {
00135 }


Member Function Documentation

void SocketSelection::clear void   ) 
 

Definition at line 140 of file OSGSocketSelection.cpp.

References _fdSetRead, and _fdSetWrite.

Referenced by SocketSelection().

00141 {
00142     FD_ZERO(&_fdSetRead);
00143     FD_ZERO(&_fdSetWrite);
00144 }

void SocketSelection::clearRead const Socket sock  ) 
 

Parameters:
sock For this socket the read flag is cleared

Definition at line 150 of file OSGSocketSelection.cpp.

References _fdSetRead, and osg::Socket::_sd.

Referenced by osg::GroupSockConnection::wait().

00151 {
00152     FD_CLR(sock._sd,&_fdSetRead);
00153 }

void SocketSelection::clearWrite const Socket sock  ) 
 

Parameters:
sock For this socket the write flag is cleared

Definition at line 159 of file OSGSocketSelection.cpp.

References _fdSetWrite, and osg::Socket::_sd.

00160 {
00161     FD_CLR(sock._sd,&_fdSetWrite);
00162 }

void SocketSelection::setRead const Socket sock  ) 
 

Parameters:
sock For this socket the read flag is set

Definition at line 168 of file OSGSocketSelection.cpp.

References _fdSetRead, and osg::Socket::_sd.

Referenced by osg::GroupMCastConnection::checkChannels(), osg::PointMCastConnection::recvNextDgram(), osg::GroupSockConnection::selectChannel(), osg::GroupSockConnection::wait(), and osg::Socket::waitReadable().

00169 {
00170     FD_SET(sock._sd,&_fdSetRead);
00171 }

void SocketSelection::setWrite const Socket sock  ) 
 

Parameters:
sock For this socket the write flag is set

Definition at line 177 of file OSGSocketSelection.cpp.

References _fdSetWrite, and osg::Socket::_sd.

Referenced by osg::Socket::waitWritable().

00178 {
00179     FD_SET(sock._sd,&_fdSetWrite);
00180 }

bool SocketSelection::isSetRead const Socket sock  ) 
 

Parameters:
sock For this socket the read flag is tested

Definition at line 249 of file OSGSocketSelection.cpp.

References _fdSetRead, and osg::Socket::_sd.

Referenced by osg::GroupMCastConnection::checkChannels(), osg::PointMCastConnection::recvNextDgram(), osg::GroupSockConnection::selectChannel(), and osg::GroupSockConnection::wait().

00250 {
00251     if(FD_ISSET(sock._sd, &_fdSetRead))
00252         return true;
00253     else
00254         return false;
00255 }

bool SocketSelection::isSetWrite const Socket sock  ) 
 

Parameters:
sock For this socket the write flag is tested

Definition at line 261 of file OSGSocketSelection.cpp.

References _fdSetWrite, and osg::Socket::_sd.

00262 {
00263     if(FD_ISSET(sock._sd, &_fdSetWrite))
00264         return true;
00265     else
00266         return false;
00267 }

int SocketSelection::select double  duration  ) 
 

Wait for the first read or write flag to be true. All other flags are cleared.

Parameters:
duration Maximum wait time in seconds
Returns:
Number of set flags

Definition at line 191 of file OSGSocketSelection.cpp.

References _fdSetRead, and _fdSetWrite.

Referenced by osg::GroupMCastConnection::checkChannels(), osg::PointMCastConnection::recvNextDgram(), select(), osg::GroupSockConnection::selectChannel(), osg::GroupSockConnection::wait(), osg::Socket::waitReadable(), and osg::Socket::waitWritable().

00192 {
00193     timeval tVal,*tValP;
00194     int count;
00195     
00196     if(duration<0)
00197     {
00198         tValP=NULL;
00199     }
00200     else
00201     {       
00202         tVal.tv_sec  = int( duration );
00203         tVal.tv_usec = int( (duration-tVal.tv_sec)*1000000 );
00204         tValP=&tVal;
00205     }
00206     do
00207     {
00208         count=::select(FD_SETSIZE, 
00209                        &_fdSetRead, 
00210                        &_fdSetWrite,
00211                        NULL,
00212                        tValP);
00213         if(count < 0)
00214         {
00215 #ifndef WIN32
00216             // select was interrupted by a signal. Ignore this
00217             // and retry to select
00218             if(errno != EINTR)
00219                 throw SocketError("select()");
00220 #else
00221             throw SocketError("select()");
00222 #endif
00223         }
00224     }
00225     while(count < 0);
00226     return count;
00227 }

int SocketSelection::select double  duration,
SocketSelection result
const
 

Wait for the first read or write flag to be true. The resulting flags are set in result.

Parameters:
duration Maximum wait time in seconds
result Result selection
Returns:
Number of set flags

Definition at line 239 of file OSGSocketSelection.cpp.

References select().

00240 {
00241     result=*this;
00242     return result.select(duration);
00243 }

const SocketSelection & SocketSelection::operator= const SocketSelection source  ) 
 

Definition at line 274 of file OSGSocketSelection.cpp.

References _fdSetRead, and _fdSetWrite.

00275 {
00276     _fdSetRead =source._fdSetRead;
00277     _fdSetWrite=source._fdSetWrite;
00278     return *this;
00279 }


Member Data Documentation

fd_set osg::SocketSelection::_fdSetRead [protected]
 

Definition at line 108 of file OSGSocketSelection.h.

Referenced by clear(), clearRead(), isSetRead(), operator=(), select(), and setRead().

fd_set osg::SocketSelection::_fdSetWrite [protected]
 

Definition at line 109 of file OSGSocketSelection.h.

Referenced by clear(), clearWrite(), isSetWrite(), operator=(), select(), and setWrite().


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