osg::GroupSockConnection Class Reference
[Network]

#include <OSGGroupSockConnection.h>

Inheritance diagram for osg::GroupSockConnection:

osg::GroupConnection osg::Connection osg::BinaryDataHandler osg::GroupMCastConnection osg::GroupSockPipeline

List of all members.

Public Types

public types


typedef Int32 Channel

Public Member Functions

Constructors


 GroupSockConnection (void)
virtual ~GroupSockConnection (void)
type info


virtual const ConnectionTypegetType (void)
connection


virtual Channel connectPoint (const std::string &address, Time timeout=-1)
virtual void disconnect (Channel channel)
virtual Channel acceptPoint (Time timeout=-1)
virtual std::string bind (const std::string &interf)
params


virtual void setParams (const std::string &params)
channel handling


virtual Channel selectChannel (Time timeout=-1) throw (ReadError)
channel handling


UInt32 getChannelCount (void)
void addSelection (Channel channel)
void subSelection (Channel channel)
void clearSelection (void)
void resetSelection (void)
UInt32 getSelectionCount (void)
group address


void setDestination (const std::string &destination)
std::string getDestination (void)
interface


const std::string & getInterface (void)
void setInterface (const std::string &interf)
Put


void put (void const *src, UInt32 size)
void putAndFree (MemoryHandle src, UInt32 size)
void putValue (const bool &value)
void putValue (const UInt8 &value)
void putValue (const UInt16 &value)
void putValue (const UInt32 &value)
void putValue (const UInt64 &value)
void putValue (const Int8 &value)
void putValue (const Int16 &value)
void putValue (const Int32 &value)
void putValue (const Int64 &value)
void putValue (const Real16 &value)
void putValue (const Real32 &value)
void putValue (const Real64 &value)
void putValue (const Real128 &value)
void putValue (const std::string &value)
void putValues (const bool *value, UInt32 size)
void putValues (const UInt8 *value, UInt32 size)
void putValues (const UInt16 *value, UInt32 size)
void putValues (const UInt32 *value, UInt32 size)
void putValues (const UInt64 *value, UInt32 size)
void putValues (const Int8 *value, UInt32 size)
void putValues (const Int16 *value, UInt32 size)
void putValues (const Int32 *value, UInt32 size)
void putValues (const Int64 *value, UInt32 size)
void putValues (const Real16 *value, UInt32 size)
void putValues (const Real32 *value, UInt32 size)
void putValues (const Real64 *value, UInt32 size)
void putValues (const Real128 *value, UInt32 size)
void putValues (const std::string *value, UInt32 size)
Get


void get (void *dst, UInt32 size)
void getAndAlloc (MemoryHandle &src, UInt32 size)
void getValue (bool &value)
void getValue (UInt8 &value)
void getValue (UInt16 &value)
void getValue (UInt32 &value)
void getValue (UInt64 &value)
void getValue (Int8 &value)
void getValue (Int16 &value)
void getValue (Int32 &value)
void getValue (Int64 &value)
void getValue (Real16 &value)
void getValue (Real32 &value)
void getValue (Real64 &value)
void getValue (Real128 &value)
void getValue (std::string &value)
void getValues (bool *value, UInt32 size)
void getValues (UInt8 *value, UInt32 size)
void getValues (UInt16 *value, UInt32 size)
void getValues (UInt32 *value, UInt32 size)
void getValues (UInt64 *value, UInt32 size)
void getValues (Int8 *value, UInt32 size)
void getValues (Int16 *value, UInt32 size)
void getValues (Int32 *value, UInt32 size)
void getValues (Int64 *value, UInt32 size)
void getValues (Real16 *value, UInt32 size)
void getValues (Real32 *value, UInt32 size)
void getValues (Real64 *value, UInt32 size)
void getValues (Real128 *value, UInt32 size)
void getValues (std::string *value, UInt32 size)
Helper


virtual void forceCopy (void)
virtual void forceDirectIO (void)
void flush (void)
 write data not yet written
void setNetworkOrder (bool value)
bool getNetworkOrder (void)

Static Public Member Functions

create


static GroupConnectioncreate (void)
 create conneciton

Protected Types

typedef std::vector< MemoryBlockBuffersT
typedef std::list< MemoryHandleFreeMemT
protected types


typedef Int32 ChannelIndex

Protected Member Functions

IO Implementation


virtual void read (MemoryHandle mem, UInt32 size)
virtual void readBuffer (void)
virtual void write (MemoryHandle mem, UInt32 size)
virtual void writeBuffer (void)
synchronisation


virtual bool wait (Time timeout) throw (ReadError)
virtual void signal (void) throw (WriteError)
internal channel handling


Channel newChannelIndex (ChannelIndex index)
void delChannelIndex (ChannelIndex index)
channel index mapping


ChannelIndex channelToIndex (Channel channel) const
Channel indexToChannel (ChannelIndex index) const
Read


BuffersT::iterator readBufBegin (void)
BuffersT::iterator readBufEnd (void)
void readBufAdd (MemoryHandle mem, UInt32 size, UInt32 dataSize=0)
void readBufClear (void)
Write


BuffersT::iterator writeBufBegin (void)
BuffersT::iterator writeBufEnd (void)
void writeBufAdd (MemoryHandle mem, UInt32 size, UInt32 dataSize=0)
void writeBufClear (void)
Helper


bool isReadBufferEmpty (void)

Protected Attributes

members


StreamSocket _acceptSocket
std::vector< StreamSocket_sockets
std::vector< SocketAddress_remoteAddresses
ChannelIndex _readIndex
std::vector< UInt8_socketReadBuffer
std::vector< UInt8_socketWriteBuffer
protected fields


std::vector< UInt8_selection
std::string _destination
std::set< Channel_disconnectedChannel
protected members


std::string _interface
Member


BuffersT _readBuffers
BuffersT _writeBuffers
BuffersT _zeroCopyBuffers
UInt32 _zeroCopyThreshold
FreeMemT _freeMem
BuffersT::iterator _currentReadBuffer
UInt32 _currentReadBufferPos
BuffersT::iterator _currentWriteBuffer
UInt32 _currentWriteBufferPos
bool _networkOrder

Private Types

typedef GroupConnection Inherited

Private Member Functions

 GroupSockConnection (const GroupSockConnection &source)
GroupSockConnectionoperator= (const GroupSockConnection &source)

Static Private Member Functions

internal methods


static bool connectSocket (StreamSocket &socket, std::string address, SocketAddress &destination, Time timeout)
static bool acceptSocket (StreamSocket &accept, StreamSocket &from, SocketAddress &destination, Time timeout)

Static Private Attributes

static type


static ConnectionType _type

Friends

class PointSockConnection

Classes

struct  SocketBufferHeader


Detailed Description

Definition at line 61 of file OSGGroupSockConnection.h.


Member Typedef Documentation

Reimplemented from osg::GroupConnection.

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockPipeline.

Definition at line 184 of file OSGGroupSockConnection.h.

typedef Int32 osg::GroupConnection::ChannelIndex [protected, inherited]

Definition at line 122 of file OSGGroupConnection.h.

typedef Int32 osg::Connection::Channel [inherited]

Definition at line 69 of file OSGConnection.h.

typedef std::vector<MemoryBlock> osg::BinaryDataHandler::BuffersT [protected, inherited]

Definition at line 213 of file OSGBinaryDataHandler.h.

typedef std::list<MemoryHandle> osg::BinaryDataHandler::FreeMemT [protected, inherited]

Definition at line 214 of file OSGBinaryDataHandler.h.


Constructor & Destructor Documentation

GroupSockConnection::GroupSockConnection ( void   ) 

Constructor

Definition at line 68 of file OSGGroupSockConnection.cpp.

References _acceptSocket, _socketReadBuffer, _socketWriteBuffer, osg::StreamSocket::open(), osg::BinaryDataHandler::readBufAdd(), osg::Socket::setReusePort(), and osg::BinaryDataHandler::writeBufAdd().

Referenced by create().

00068                                         :
00069     GroupConnection(0)
00070 {
00071     _acceptSocket.open();
00072     _acceptSocket.setReusePort(true);
00073 
00074     _socketReadBuffer.resize(131071);
00075     _socketWriteBuffer.resize( _socketReadBuffer.size() );
00076     // reserve first bytes for buffer size
00077     readBufAdd (&_socketReadBuffer [sizeof(SocketBufferHeader)],
00078                 _socketReadBuffer.size() -sizeof(SocketBufferHeader));
00079     writeBufAdd(&_socketWriteBuffer[sizeof(SocketBufferHeader)],
00080                 _socketWriteBuffer.size()-sizeof(SocketBufferHeader));
00081 }

GroupSockConnection::~GroupSockConnection ( void   )  [virtual]

Destructor

Definition at line 85 of file OSGGroupSockConnection.cpp.

References _acceptSocket, _sockets, and osg::StreamSocket::close().

00086 {
00087     // close and remove sockets
00088     while(_sockets.size())
00089     {
00090         try
00091         {
00092             _sockets.begin()->close();
00093             _sockets.erase(_sockets.begin());
00094         }
00095         catch(...)
00096         {
00097         }
00098     }
00099     _acceptSocket.close();
00100 }

osg::GroupSockConnection::GroupSockConnection ( const GroupSockConnection source  )  [private]


Member Function Documentation

const ConnectionType * GroupSockConnection::getType ( void   )  [virtual]

get connection type

Implements osg::GroupConnection.

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockPipeline.

Definition at line 104 of file OSGGroupSockConnection.cpp.

References _type.

00105 {
00106     return &_type;
00107 }

GroupConnection::Channel GroupSockConnection::connectPoint ( const std::string &  address,
Time  timeout = -1 
) [virtual]

connect to the given point. If timeout is reached, -1 is returned

Implements osg::Connection.

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockPipeline.

Definition at line 115 of file OSGGroupSockConnection.cpp.

References _readIndex, _remoteAddresses, _sockets, connectSocket(), and osg::GroupConnection::newChannelIndex().

Referenced by osg::GroupSockPipeline::connectPoint(), and osg::GroupMCastConnection::connectPoint().

00118 {
00119     Channel channel = -1;
00120     StreamSocket socket;
00121     SocketAddress destination;
00122     if(connectSocket(socket,address,destination,timeout))
00123     {
00124         channel = newChannelIndex(_sockets.size());
00125         _sockets.push_back(socket);
00126         _remoteAddresses.push_back(destination);
00127         _readIndex = 0;
00128     }
00129     return channel;
00130 }

void GroupSockConnection::disconnect ( Channel  channel  )  [virtual]

disconnect the given channel

Implements osg::GroupConnection.

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockPipeline.

Definition at line 134 of file OSGGroupSockConnection.cpp.

References _readIndex, _sockets, osg::GroupConnection::channelToIndex(), and osg::GroupConnection::delChannelIndex().

Referenced by osg::GroupSockPipeline::disconnect(), and osg::GroupMCastConnection::disconnect().

00135 {
00136     ChannelIndex index = channelToIndex(channel);
00137     try
00138     {
00139         _sockets[index].close();
00140     }
00141     catch(...)
00142     {
00143     }
00144     _sockets.erase(_sockets.begin() + index);
00145     delChannelIndex(index);
00146     _readIndex = 0;
00147 }

GroupConnection::Channel GroupSockConnection::acceptPoint ( Time  timeout = -1  )  [virtual]

accept an icomming point connection. If timeout is reached, -1 is returned. If timeout is -1 then wait without timeout

Implements osg::Connection.

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockPipeline.

Definition at line 152 of file OSGGroupSockConnection.cpp.

References _acceptSocket, _readIndex, _remoteAddresses, _sockets, acceptSocket(), and osg::GroupConnection::newChannelIndex().

Referenced by osg::GroupSockPipeline::acceptPoint(), and osg::GroupMCastConnection::acceptPoint().

00153 {
00154     StreamSocket from;
00155     SocketAddress destination;
00156     if(GroupSockConnection::acceptSocket(_acceptSocket,from,destination,timeout))
00157     {
00158         Channel channel = newChannelIndex(_sockets.size());
00159         _sockets.push_back(from);
00160         _remoteAddresses.push_back(destination);
00161         _readIndex = 0;
00162         return channel;
00163     }
00164     else
00165     {
00166         return -1;
00167     }
00168 }

std::string GroupSockConnection::bind ( const std::string &  address  )  [virtual]

bind the connection to an network interface. The address is returned, on wich the port could be connected. The interface is determined by the connection interface filed and the address parameter. Address can be empty, wich means to use a free port or address can contain a port number.

Implements osg::Connection.

Definition at line 176 of file OSGGroupSockConnection.cpp.

References _acceptSocket, osg::Socket::bind(), osg::Socket::getAddress(), osg::SocketAddress::getHost(), osg::Connection::getInterface(), osg::SocketAddress::getPort(), osg::Socket::listen(), osg::osgGetHostname(), osg::Socket::setReusePort(), and SINFO.

00177 {
00178     int         port=0;
00179     char        localhost[256];
00180     char        host[256];
00181     char        portStr[256];
00182     std::string interf;
00183     std::string boundedAddress;
00184 
00185     // get local host name
00186     osgGetHostname(localhost,255);
00187 
00188     if(!getInterface().empty())
00189         interf = getInterface();
00190     else
00191         interf = localhost;
00192     // parse address
00193     if(!address.empty())
00194         if(sscanf(address.c_str(),"%*[^:]:%d",&port) != 1)
00195             if(sscanf(address.c_str(),":%d",&port) != 1)
00196                 port = 0;
00197     // bind port
00198     _acceptSocket.setReusePort(true);
00199     _acceptSocket.bind(SocketAddress(interf.c_str(),port));
00200     SINFO << "Connection bound to "
00201           << _acceptSocket.getAddress().getHost() << ":"
00202           << _acceptSocket.getAddress().getPort() << std::endl;
00203     _acceptSocket.listen();
00204     // create address
00205     sprintf(portStr,"%d",_acceptSocket.getAddress().getPort());
00206     return interf + ":" + portStr;
00207 }

void GroupSockConnection::setParams ( const std::string &  params  )  [virtual]

parse the params string.

Reimplemented from osg::Connection.

Reimplemented in osg::GroupMCastConnection.

Definition at line 211 of file OSGGroupSockConnection.cpp.

References _socketReadBuffer, _socketWriteBuffer, FINFO, osg::BinaryDataHandler::readBufAdd(), osg::BinaryDataHandler::readBufClear(), osg::BinaryDataHandler::writeBufAdd(), and osg::BinaryDataHandler::writeBufClear().

Referenced by osg::GroupMCastConnection::setParams().

00212 {
00213     if(params.empty())
00214         return;
00215 
00216     std::string option = "bufferSize=";
00217     std::string::size_type i = 0;
00218     if((i=params.find(option)) != std::string::npos)
00219     {
00220         std::string str = params.substr(i + option.size());
00221 
00222         std::stringstream ss;
00223         std::string::size_type j = 0;
00224         while(j < str.length() && str[j] != ',' && isdigit(str[j]))
00225         {
00226             ss << str[j++];
00227         }
00228         UInt32 bufferSize;
00229         ss >> bufferSize;
00230 
00231         // clear old buffer.
00232         readBufClear();
00233         writeBufClear();
00234 
00235         _socketReadBuffer.resize(bufferSize);
00236         _socketWriteBuffer.resize(_socketReadBuffer.size());
00237         
00238         // reserve first bytes for buffer size
00239         readBufAdd (&_socketReadBuffer [sizeof(SocketBufferHeader)],
00240                     _socketReadBuffer.size() -sizeof(SocketBufferHeader));
00241         writeBufAdd(&_socketWriteBuffer[sizeof(SocketBufferHeader)],
00242                     _socketWriteBuffer.size()-sizeof(SocketBufferHeader));
00243 
00244         FINFO(("GroupSockConnection::setParams : setting buffer size to %u.\n", bufferSize));
00245     }
00246 }

Connection::Channel GroupSockConnection::selectChannel ( Time  timeout = -1  )  throw (ReadError) [virtual]

select the next channel for reading. If timeout is not -1 then -1 is returned if timeout is reached

Implements osg::Connection.

Definition at line 254 of file OSGGroupSockConnection.cpp.

References osg::BinaryDataHandler::_currentReadBuffer, _readIndex, osg::GroupConnection::_selection, _sockets, osg::BinaryDataHandler::_zeroCopyThreshold, FFATAL, osg::GroupConnection::indexToChannel(), osg::SocketSelection::isSetRead(), osg::BinaryDataHandler::readBufEnd(), osg::SocketSelection::select(), osg::SocketSelection::setRead(), and osg::Exception::what().

00256 {
00257     Int32 maxnread=0,nread;
00258     ChannelIndex index;
00259     SocketSelection selection,result;
00260 
00261     // if there is data in the read buffer, return current channel
00262     if(_zeroCopyThreshold != 1 &&
00263        _currentReadBuffer != readBufEnd())
00264     {
00265         FFATAL(("Channel change ignores data in current buffer"))
00266         return indexToChannel(_readIndex);
00267     }    
00268 
00269     if(_selection[_readIndex] &&
00270        _sockets[_readIndex].getAvailable())
00271     {
00272         return indexToChannel(_readIndex);;
00273     }
00274 
00275     // wait for first socket to deliver data
00276     for(index = 0 ; index < _sockets.size() ; ++index)
00277     {
00278         if(_selection[index])
00279             selection.setRead(_sockets[index]);
00280     }
00281     
00282     try 
00283     {
00284         // select ok ?
00285         if(!selection.select(timeout,result))
00286             return -1;
00287 
00288         // use socket with most data
00289         for(index = 0 ; index < _sockets.size() ; ++index)
00290         {
00291             if(result.isSetRead(_sockets[index]))
00292             {
00293                 nread=_sockets[index].getAvailable();
00294                 if(maxnread < nread)
00295                 {
00296                     maxnread = nread;
00297                     _readIndex=index;
00298                 }
00299             }
00300         }
00301     }
00302     catch(SocketException &e)
00303     {
00304         throw ReadError(e.what());
00305     }
00306 
00307     // return channel id
00308     return indexToChannel(_readIndex);
00309 }

ConnectionType GroupSockConnection::_type & GroupSockConnection::create ( void   )  [static]

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockPipeline.

Definition at line 382 of file OSGGroupSockConnection.cpp.

References GroupSockConnection().

00383 {
00384     return new GroupSockConnection();
00385 }

void GroupSockConnection::read ( MemoryHandle  mem,
UInt32  size 
) [protected, virtual]

Read data into given memory

Read data form the current read socket. The read socket is that socket, that was selectet in selectChannel.

Reimplemented from osg::BinaryDataHandler.

Definition at line 397 of file OSGGroupSockConnection.cpp.

References _readIndex, and _sockets.

00398 {
00399     int len;
00400 
00401     // read data
00402     len=_sockets[_readIndex].recv(mem,size);
00403     if(len==0)
00404     {
00405 //        throw ChannelClosed(indexToChannel(_readIndex));
00406         throw ReadError("Channel closed");
00407     }
00408 } 

void GroupSockConnection::readBuffer ( void   )  [protected, virtual]

Read next data block

The stream connection uses only BinaryDataHandler buffer. If more then one buffer is present, then this methode must be changed!

Reimplemented from osg::BinaryDataHandler.

Definition at line 417 of file OSGGroupSockConnection.cpp.

References _readIndex, _socketReadBuffer, _sockets, osg::osgntohl(), and osg::BinaryDataHandler::readBufBegin().

00418 {
00419     int size;
00420     int len;
00421 
00422     // read buffer header
00423     len=_sockets[_readIndex].recv(&_socketReadBuffer[0],sizeof(SocketBufferHeader));
00424     if(len==0)
00425         throw ReadError("Channel closed");
00426     // read remaining data
00427     size=osgntohl(((SocketBufferHeader*)&_socketReadBuffer[0])->size);
00428     len=_sockets[_readIndex].recv(&_socketReadBuffer[sizeof(SocketBufferHeader)],
00429                          size);
00430     if(len==0)
00431         throw ReadError("Channel closed");
00432     readBufBegin()->setDataSize(size);
00433 }    

void GroupSockConnection::write ( MemoryHandle  mem,
UInt32  size 
) [protected, virtual]

Write data to all destinations

Parameters:
mem Pointer to data buffer
size Size of bytes to write

Reimplemented from osg::BinaryDataHandler.

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockPipeline.

Definition at line 442 of file OSGGroupSockConnection.cpp.

References _sockets, and osg::Exception::what().

00443 {
00444     Int32 index;
00445 
00446     try
00447     {
00448         // write to all connected sockets
00449         for(index = 0 ; index < _sockets.size() ; ++index)
00450             _sockets[index].send(mem,size);
00451     }
00452     catch(SocketException &e)
00453     {
00454         throw WriteError(e.what());
00455     }
00456 }

void GroupSockConnection::writeBuffer ( void   )  [protected, virtual]

Write buffer

Write blocksize and data.

Reimplemented from osg::BinaryDataHandler.

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockPipeline.

Definition at line 463 of file OSGGroupSockConnection.cpp.

References _sockets, _socketWriteBuffer, osg::osghtonl(), and osg::BinaryDataHandler::writeBufBegin().

00464 {
00465     Int32 index;
00466     UInt32 size = writeBufBegin()->getDataSize();
00467     // write size to header
00468     ((SocketBufferHeader*)&_socketWriteBuffer[0])->size=osghtonl(size);
00469     if(size)
00470     {
00471         // write data to all sockets
00472         for(index = 0 ; index < _sockets.size() ; ++index)
00473         {
00474             // write whole block
00475             _sockets[index].send(&_socketWriteBuffer[0],
00476                                  size+sizeof(SocketBufferHeader));
00477         }
00478     }
00479 }

bool GroupSockConnection::wait ( Time  timeout  )  throw (ReadError) [protected, virtual]

wait for signal

Implements osg::Connection.

Reimplemented in osg::GroupMCastConnection.

Definition at line 316 of file OSGGroupSockConnection.cpp.

References _sockets, osg::SocketSelection::clearRead(), FFATAL, osg::SocketSelection::isSetRead(), osg::osgntohl(), osg::SocketSelection::select(), osg::SocketSelection::setRead(), and osg::Exception::what().

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

00317 {
00318     UInt32 len;
00319     UInt32 index;
00320     UInt32 tag=314156;
00321     UInt32 missing = _sockets.size();
00322     SocketSelection selection,result;
00323 
00324     for(index = 0 ; index < _sockets.size() ; ++index)
00325         selection.setRead(_sockets[index]);
00326 
00327     try
00328     {
00329         while(missing)
00330         {
00331             if(!selection.select(timeout,result))
00332                 return false;
00333             for(index = 0 ; index < _sockets.size() ; ++index)
00334             {
00335                 if(result.isSetRead(_sockets[index]))
00336                 {
00337                     len = _sockets[index].recv(&tag,sizeof(tag));
00338                     tag = osgntohl(tag);
00339                     if(len == 0)
00340                         throw ReadError("Channel closed");
00341                     selection.clearRead(_sockets[index]);
00342                     missing--;
00343                     if(tag != 314156)
00344                     {
00345                         FFATAL(("Stream out of sync in SockConnection\n"));
00346                         throw ReadError("Stream out of sync");
00347                     }
00348                 }
00349             }
00350         }
00351     }
00352     catch(SocketException &e)
00353     {
00354         throw ReadError(e.what());
00355     }
00356     return true;
00357 }

void GroupSockConnection::signal ( void   )  throw (WriteError) [protected, virtual]

send signal

Implements osg::Connection.

Reimplemented in osg::GroupMCastConnection.

Definition at line 361 of file OSGGroupSockConnection.cpp.

References _sockets, osg::osghtonl(), and osg::Exception::what().

00362 {
00363     UInt32 tag=osghtonl(314156);
00364     UInt32 index;
00365 
00366     try
00367     {
00368         for(index = 0 ; index<_sockets.size() ; ++index)
00369             _sockets[index].send(&tag,sizeof(tag));
00370     }
00371     catch(SocketError &e)
00372     {
00373         throw WriteError(e.what());
00374     }
00375 }

bool GroupSockConnection::connectSocket ( StreamSocket socket,
std::string  address,
SocketAddress destination,
Time  timeout 
) [static, private]

connect two sockets until success or timeout

Definition at line 486 of file OSGGroupSockConnection.cpp.

References osg::Socket::connect(), osg::getSystemTime(), osg::StreamSocket::open(), osg::StreamSocket::setDelay(), osg::Socket::setReadBufferSize(), osg::Socket::setWriteBufferSize(), and startTime.

Referenced by osg::PointSockConnection::connectGroup(), osg::PointSockConnection::connectPoint(), and connectPoint().

00490 {
00491     std::string  host="unknown";
00492     int          port=0;
00493     Time         startTime = getSystemTime();
00494     bool         connected=false;
00495     
00496     int pos = address.find(':');
00497     if(pos>=0)
00498     {
00499         host = std::string(address,0,pos);
00500         port = atoi(std::string(address,pos+1,std::string::npos).c_str());
00501     }
00502     else
00503     {
00504         host = address;
00505     }
00506     
00507     socket.open();
00508     socket.setDelay(false);
00509     socket.setReadBufferSize(1048576);
00510     socket.setWriteBufferSize(1048576);
00511     destination = SocketAddress(host.c_str(),port);
00512     while(!connected && 
00513           (timeout == -1 || (getSystemTime()-startTime) < timeout))
00514     {
00515         try
00516         {
00517             socket.connect(destination);
00518             connected = true;
00519         }
00520         catch(...)
00521         {
00522         }
00523     }
00524     if(connected)
00525         return true;
00526     else
00527         return false;
00528 }

bool GroupSockConnection::acceptSocket ( StreamSocket accept,
StreamSocket from,
SocketAddress destination,
Time  timeout 
) [static, private]

accept socket untile success or timeout

Definition at line 532 of file OSGGroupSockConnection.cpp.

References osg::StreamSocket::acceptFrom(), osg::StreamSocket::setDelay(), osg::Socket::setReadBufferSize(), osg::Socket::setWriteBufferSize(), and osg::Socket::waitReadable().

Referenced by osg::PointSockConnection::acceptGroup(), osg::PointSockConnection::acceptPoint(), and acceptPoint().

00536 {
00537     if(!accept.waitReadable(timeout))
00538         return false;
00539     from=accept.acceptFrom(destination);
00540     from.setDelay(false);
00541     from.setReadBufferSize(1048576);
00542     from.setWriteBufferSize(1048576);
00543     return true;
00544 }

GroupSockConnection& osg::GroupSockConnection::operator= ( const GroupSockConnection source  )  [private]

UInt32 GroupConnection::getChannelCount ( void   )  [inherited]

void GroupConnection::addSelection ( Channel  channel  )  [inherited]

mark the given channel as selectable

Definition at line 85 of file OSGGroupConnection.cpp.

References osg::GroupConnection::_channelToIndex, and osg::GroupConnection::_selection.

00086 {
00087     ChannelIndex index = _channelToIndex[channel];
00088     _selection[index] = true;
00089 }

void GroupConnection::subSelection ( Channel  channel  )  [inherited]

void GroupConnection::clearSelection ( void   )  [inherited]

mark all channels as selectable

Definition at line 101 of file OSGGroupConnection.cpp.

References osg::GroupConnection::_selection.

00102 {
00103     std::fill(_selection.begin(),_selection.end(),false);
00104 }

void GroupConnection::resetSelection ( void   )  [inherited]

UInt32 GroupConnection::getSelectionCount ( void   )  [inherited]

get number of sockets in the selection

Definition at line 115 of file OSGGroupConnection.cpp.

References osg::GroupConnection::_selection.

00116 {
00117     UInt32 selectionCount=0;
00118     std::vector<UInt8>::iterator i;
00119     for(i=_selection.begin() ; i!=_selection.end() ; ++i)
00120         if(*i)
00121             selectionCount++;
00122     return selectionCount;
00123 }

void GroupConnection::setDestination ( const std::string &  destination  )  [inherited]

set destination address used to broadcast or multicast to all connected points. On Multicast connections this could be 224.22.22.1 or something like that.

Definition at line 132 of file OSGGroupConnection.cpp.

References osg::GroupConnection::_destination.

Referenced by osg::ClusterWindow::init().

00133 {
00134     _destination = destination;
00135 }

std::string GroupConnection::getDestination ( void   )  [inherited]

get destination address

Definition at line 139 of file OSGGroupConnection.cpp.

References osg::GroupConnection::_destination.

Referenced by osg::GroupMCastConnection::initialize().

00140 {
00141     return _destination;
00142 }

Connection::Channel GroupConnection::newChannelIndex ( ChannelIndex  index  )  [protected, inherited]

create a new channel

Definition at line 149 of file OSGGroupConnection.cpp.

References osg::GroupConnection::_channelToIndex, osg::GroupConnection::_indexToChannel, osg::GroupConnection::_reuseChannel, and osg::GroupConnection::_selection.

Referenced by acceptPoint(), and connectPoint().

00150 {
00151     Channel channel;
00152     if(_reuseChannel.begin() != _reuseChannel.end())
00153     {
00154         channel = *(_reuseChannel.begin());
00155         _reuseChannel.pop_front();
00156     }
00157     else
00158     {
00159         channel = _channelToIndex.size();
00160         _channelToIndex.resize(channel+1);
00161     }
00162     if(index >= _indexToChannel.size())
00163         _indexToChannel.resize(index+1);
00164     if(index >= _selection.size())
00165         _selection.resize(index+1);
00166     // enable selection
00167     _selection[index] = true;
00168     // set index to channel mapping
00169     _indexToChannel[index] = channel;
00170     // set channel to index mapping
00171     _channelToIndex[channel] = index;
00172     return channel;
00173 }

void GroupConnection::delChannelIndex ( ChannelIndex  index  )  [protected, inherited]

remove a channel.

Definition at line 177 of file OSGGroupConnection.cpp.

References osg::GroupConnection::_indexToChannel, osg::GroupConnection::_reuseChannel, and osg::GroupConnection::_selection.

Referenced by disconnect().

00178 {
00179     Channel channel = _indexToChannel[index];
00180     // erase from indexed arrays
00181     _selection     .erase(_selection.begin()      + index);
00182     _indexToChannel.erase(_indexToChannel.begin() + index);
00183     // move to reuse
00184     _reuseChannel.push_back(channel);
00185 }

GroupConnection::ChannelIndex GroupConnection::channelToIndex ( Channel  channel  )  const [protected, inherited]

Definition at line 190 of file OSGGroupConnection.cpp.

References osg::GroupConnection::_channelToIndex.

Referenced by disconnect(), and osg::GroupMCastConnection::disconnect().

00191 {
00192     return _channelToIndex[channel];
00193 }

Connection::Channel GroupConnection::indexToChannel ( ChannelIndex  index  )  const [protected, inherited]

Definition at line 195 of file OSGGroupConnection.cpp.

References osg::GroupConnection::_indexToChannel.

Referenced by selectChannel().

00196 {
00197     return _indexToChannel[index];
00198 }

const std::string & Connection::getInterface ( void   )  [inherited]

void Connection::setInterface ( const std::string &  interf  )  [inherited]

set network interface

Definition at line 105 of file OSGConnection.cpp.

References osg::Connection::_interface.

Referenced by osg::ClusterServer::acceptClient(), and osg::ClusterWindow::init().

00106 {
00107     _interface = interf;
00108 }

void BinaryDataHandler::put ( void const *  src,
UInt32  size 
) [inherited]

Definition at line 83 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_currentWriteBuffer, osg::BinaryDataHandler::_currentWriteBufferPos, osg::BinaryDataHandler::_zeroCopyBuffers, osg::BinaryDataHandler::_zeroCopyThreshold, osg::osgMin(), osg::BinaryDataHandler::pushBuffer(), osg::BinaryDataHandler::write(), and osg::BinaryDataHandler::writeBufEnd().

Referenced by osg::BinaryDataHandler::putAndFree(), osg::BinaryDataHandler::putValue(), osg::BinaryDataHandler::putValues(), and osg::ClusterViewBuffer::send().

00084 {
00085     UInt8 const *data = static_cast<UInt8 const *>(src);
00086 
00087     if(_zeroCopyThreshold && size >= _zeroCopyThreshold)
00088     {
00089         if(_zeroCopyThreshold == 1)
00090         {
00091             write(const_cast<MemoryHandle>(data), size);
00092         }
00093         else
00094         {
00095             UInt8 tag = 1;
00096 
00097             // we have to write a tag, to indicate the membership
00098             // of this zero copy block to the current data block
00099             put(&tag, sizeof(tag));
00100 
00101             _zeroCopyBuffers.push_back(
00102                 MemoryBlock(const_cast<MemoryHandle>(data), size, size));
00103         }
00104     }
00105     else
00106     {
00107         UInt32 copySize;
00108 
00109         while(size != 0)
00110         {
00111             if(_currentWriteBuffer == writeBufEnd())
00112             {
00113                 pushBuffer();
00114             }
00115 
00116             copySize = osgMin((_currentWriteBuffer->getSize() -
00117                                _currentWriteBufferPos),
00118                               size);
00119 
00120             memcpy(_currentWriteBuffer->getMem() + _currentWriteBufferPos,
00121                     data,
00122                     copySize);
00123 
00124              size                  -= copySize;
00125             _currentWriteBufferPos += copySize;
00126              data                  += copySize;
00127 
00128             // skip to next buffer if current buffer is full
00129             if(_currentWriteBufferPos == _currentWriteBuffer->getSize())
00130             {
00131                 _currentWriteBuffer->setDataSize(_currentWriteBufferPos);
00132                 _currentWriteBuffer++;
00133                 _currentWriteBufferPos = 0;
00134             }
00135         }
00136     }
00137 }

void BinaryDataHandler::putAndFree ( MemoryHandle  src,
UInt32  size 
) [inherited]

Put data from dynamic allocated block The caller doesn't know, when the block will be written. So we are responsible for freeing this block.

Definition at line 144 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_freeMem, osg::BinaryDataHandler::_zeroCopyThreshold, and osg::BinaryDataHandler::put().

00145 {
00146     put(src, size);
00147 
00148     if(_zeroCopyThreshold && size > _zeroCopyThreshold)
00149     {
00150         _freeMem.push_back(src);
00151     }
00152     else
00153     {
00154         delete [] src;
00155     }
00156 }

void osg::BinaryDataHandler::putValue ( const bool &  value  )  [inline, inherited]

Definition at line 60 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::put().

Referenced by osg::SortFirstWindow::clientInit(), osg::ClusterNetwork::connectAllGroupToPoint(), osg::ClusterNetwork::connectAllPointToPoint(), osg::osg::FieldDataTraits2< bool >::copyToBin(), osg::RenderNode::copyToBin(), osg::ParticleBSPTree::copyToBin(), osg::MField< FieldTypeT, fieldNameSpace >::copyToBin(), osg::FieldTraitsIntegralRecurseMapper< uint64_t >::copyToBin(), osg::FieldTraitsRecurseBase1< GLXContext >::copyToBin(), osg::FieldTraitsRecurseBase< osg::NodePtr >::copyToBin(), osg::osg::FieldTraitsRecurseMapper< FieldContainerPtr, false >::copyToBin(), osg::osg::FieldDataTraits< Plane >::copyToBin(), osg::osg::FieldDataTraits1< GLenum >::copyToBin(), osg::osg::FieldDataTraits1< BitVector >::copyToBin(), osg::osg::FieldDataTraits< DynamicVolume >::copyToBin(), osg::osg::FieldDataTraits1< Time >::copyToBin(), osg::osg::FieldDataTraits< std::string >::copyToBin(), osg::osg::FieldTraitsRecurseMapper< AttachmentMap, false >::copyToBin(), osg::BINWriter::doWriteIndexedFC(), osg::RemoteAspect::handleFCMapping(), osg::ClusterWindow::init(), osg::BinaryDataHandler::putValue(), osg::BinaryDataHandler::putValues(), osg::ClusterViewBuffer::send(), osg::RemoteAspect::sendSync(), osg::SortFirstWindow::serverInit(), osg::GroupMCastConnection::signal(), osg::ClusterServer::start(), and osg::BINWriter::writeFileHeader().

00061 {
00062     // on Mac OS X a bool is four bytes long on all other
00063     // platfroms it is one byte long. So we write now always
00064     // one byte out.
00065     // put(&value, sizeof(bool));
00066     UInt8 temp = (UInt8) value;
00067     put(&temp, sizeof(UInt8));
00068 }

void osg::BinaryDataHandler::putValue ( const UInt8 value  )  [inline, inherited]

Definition at line 71 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::put().

00072 {
00073     put(&value, sizeof(UInt8));
00074 }

void osg::BinaryDataHandler::putValue ( const UInt16 value  )  [inline, inherited]

Definition at line 77 of file OSGBinaryDataHandler.inl.

References osg::osghtons(), and osg::BinaryDataHandler::put().

00078 {
00079     UInt16 z = osghtons(value);
00080 
00081     put(&z, sizeof(UInt16));
00082 }

void osg::BinaryDataHandler::putValue ( const UInt32 value  )  [inline, inherited]

Definition at line 85 of file OSGBinaryDataHandler.inl.

References osg::osghtonl(), and osg::BinaryDataHandler::put().

00086 {
00087     UInt32 z = osghtonl(value);
00088 
00089     put(&z, sizeof(UInt32));
00090 }

void osg::BinaryDataHandler::putValue ( const UInt64 value  )  [inline, inherited]

Definition at line 93 of file OSGBinaryDataHandler.inl.

References osg::osghtonll(), and osg::BinaryDataHandler::put().

00094 {
00095     UInt64 z = osghtonll(value);
00096 
00097     put(&z, sizeof(UInt64));
00098 }

void osg::BinaryDataHandler::putValue ( const Int8 value  )  [inline, inherited]

Definition at line 101 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::put().

00102 {
00103     put(&value, sizeof(Int8));
00104 }

void osg::BinaryDataHandler::putValue ( const Int16 value  )  [inline, inherited]

Definition at line 107 of file OSGBinaryDataHandler.inl.

References osg::osghtons(), and osg::BinaryDataHandler::put().

00108 {
00109     Int16 z = osghtons(value);
00110 
00111     put(&z, sizeof(Int16));
00112 }

void osg::BinaryDataHandler::putValue ( const Int32 value  )  [inline, inherited]

Definition at line 115 of file OSGBinaryDataHandler.inl.

References osg::osghtonl(), and osg::BinaryDataHandler::put().

00116 {
00117     Int32 z = osghtonl(value);
00118 
00119     put(&z, sizeof(Int32));
00120 }

void osg::BinaryDataHandler::putValue ( const Int64 value  )  [inline, inherited]

Definition at line 123 of file OSGBinaryDataHandler.inl.

References osg::osghtonll(), and osg::BinaryDataHandler::put().

00124 {
00125     Int64 z = osghtonll(value);
00126     put(&z, sizeof(Int64));
00127 
00128 }

void osg::BinaryDataHandler::putValue ( const Real16 value  )  [inline, inherited]

Definition at line 131 of file OSGBinaryDataHandler.inl.

References osg::Real16::bits(), osg::osghtons(), and osg::BinaryDataHandler::put().

00132 {
00133     UInt16 v = osghtons(value.bits());
00134 
00135     put(&v, sizeof(Real16));
00136 }

void osg::BinaryDataHandler::putValue ( const Real32 value  )  [inline, inherited]

Definition at line 139 of file OSGBinaryDataHandler.inl.

References osg::osghtonl(), and osg::BinaryDataHandler::put().

00140 {
00141     UInt32 v = osghtonl( *((const UInt32 *)(&value)) );
00142 
00143     put(&v, sizeof(Real32));
00144 }

void osg::BinaryDataHandler::putValue ( const Real64 value  )  [inline, inherited]

Definition at line 147 of file OSGBinaryDataHandler.inl.

References osg::osghtonll(), and osg::BinaryDataHandler::put().

00148 {
00149     UInt64 v = osghtonll( *((const UInt64 *)(&value)) );
00150 
00151     put(&v, sizeof(Real64));
00152 }

void osg::BinaryDataHandler::putValue ( const Real128 value  )  [inline, inherited]

Definition at line 155 of file OSGBinaryDataHandler.inl.

References osg::osghtonll(), and osg::BinaryDataHandler::put().

00156 {
00157     UInt64 v = osghtonll( *( (const UInt64 *)(&value)) );
00158     UInt64 w = osghtonll( *(((const UInt64 *)(&value)) + 1) );
00159 
00160 #if BYTE_ORDER == LITTLE_ENDIAN
00161     put(&w, sizeof(UInt64));
00162     put(&v, sizeof(UInt64));
00163 #else
00164     put(&v, sizeof(UInt64));
00165     put(&w, sizeof(UInt64));
00166 #endif
00167 }

void osg::BinaryDataHandler::putValue ( const std::string &  value  )  [inline, inherited]

Definition at line 170 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::put(), osg::BinaryDataHandler::putValue(), and osg::stringlen().

00171 {
00172     UInt32 len = stringlen(value.c_str()) + 1;
00173 
00174     putValue(len);
00175 
00176     if(len != 0)
00177     {
00178         put(value.c_str(), len);
00179     }
00180 }

void osg::BinaryDataHandler::putValues ( const bool *  value,
UInt32  size 
) [inline, inherited]

void osg::BinaryDataHandler::putValues ( const UInt8 value,
UInt32  size 
) [inline, inherited]

Definition at line 191 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::put().

00192 {
00193     put(value, size * sizeof(UInt8));
00194 }

void osg::BinaryDataHandler::putValues ( const UInt16 value,
UInt32  size 
) [inline, inherited]

Definition at line 197 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00198 {
00199 #if BYTE_ORDER == LITTLE_ENDIAN
00200 
00201     if(_networkOrder == true)
00202     {
00203         for(UInt32 i = 0; i < size; ++i)
00204         {
00205             putValue(value[i]);
00206         }
00207     }
00208     else
00209 #endif
00210     {
00211         put(value, size * sizeof(UInt16));
00212     }
00213 }

void osg::BinaryDataHandler::putValues ( const UInt32 value,
UInt32  size 
) [inline, inherited]

Definition at line 216 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00217 {
00218 #if BYTE_ORDER == LITTLE_ENDIAN
00219     if(_networkOrder == true)
00220     {
00221         for(UInt32 i = 0; i < size; ++i)
00222         {
00223             putValue(value[i]);
00224         }
00225     }
00226     else
00227 #endif
00228     {
00229         put(value, size * sizeof(UInt32));
00230     }
00231 }

void osg::BinaryDataHandler::putValues ( const UInt64 value,
UInt32  size 
) [inline, inherited]

Definition at line 234 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00235 {
00236 #if BYTE_ORDER == LITTLE_ENDIAN
00237     if(_networkOrder == true)
00238     {
00239         for(UInt32 i = 0; i < size; ++i)
00240         {
00241             putValue(value[i]);
00242         }
00243     }
00244     else
00245 #endif
00246     {
00247         put(value, size * sizeof(UInt64));
00248     }
00249 }

void osg::BinaryDataHandler::putValues ( const Int8 value,
UInt32  size 
) [inline, inherited]

Definition at line 252 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00253 {
00254 #if BYTE_ORDER == LITTLE_ENDIAN
00255     if(_networkOrder == true)
00256     {
00257         for(UInt32 i = 0; i < size; ++i)
00258         {
00259             putValue(value[i]);
00260         }
00261     }
00262     else
00263 #endif
00264     {
00265         put(value, size * sizeof(Int8));
00266     }
00267 }

void osg::BinaryDataHandler::putValues ( const Int16 value,
UInt32  size 
) [inline, inherited]

Definition at line 270 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00271 {
00272 #if BYTE_ORDER == LITTLE_ENDIAN
00273     if(_networkOrder == true)
00274     {
00275         for(UInt32 i = 0; i < size; ++i)
00276         {
00277             putValue(value[i]);
00278         }
00279     }
00280     else
00281 #endif
00282     {
00283         put(value, size * sizeof(Int16));
00284     }
00285 }

void osg::BinaryDataHandler::putValues ( const Int32 value,
UInt32  size 
) [inline, inherited]

Definition at line 288 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00289 {
00290 #if BYTE_ORDER == LITTLE_ENDIAN
00291     if(_networkOrder == true)
00292     {
00293         for(UInt32 i = 0; i < size; ++i)
00294         {
00295             putValue(value[i]);
00296         }
00297     }
00298     else
00299 #endif
00300     {
00301         put(value, size * sizeof(Int32));
00302     }
00303 }

void osg::BinaryDataHandler::putValues ( const Int64 value,
UInt32  size 
) [inline, inherited]

Definition at line 306 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00307 {
00308 #if BYTE_ORDER == LITTLE_ENDIAN
00309     if(_networkOrder == true)
00310     {
00311         for(UInt32 i = 0; i < size; ++i)
00312         {
00313             putValue(value[i]);
00314         }
00315     }
00316     else
00317 #endif
00318     {
00319         put(value, size * sizeof(Int64));
00320     }
00321 }

void osg::BinaryDataHandler::putValues ( const Real16 value,
UInt32  size 
) [inline, inherited]

Definition at line 324 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00325 {
00326 #if BYTE_ORDER == LITTLE_ENDIAN
00327     if(_networkOrder == true)
00328     {
00329         for(UInt32 i = 0; i < size; ++i)
00330         {
00331             putValue(value[i]);
00332         }
00333     }
00334     else
00335 #endif
00336     {
00337         put(value, size * sizeof(Real16));
00338     }
00339 }

void osg::BinaryDataHandler::putValues ( const Real32 value,
UInt32  size 
) [inline, inherited]

Definition at line 342 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00343 {
00344 #if BYTE_ORDER == LITTLE_ENDIAN
00345     if(_networkOrder == true)
00346     {
00347         for(UInt32 i = 0; i < size; ++i)
00348         {
00349             putValue(value[i]);
00350         }
00351     }
00352     else
00353 #endif
00354     {
00355         put(value, size * sizeof(Real32));
00356     }
00357 }

void osg::BinaryDataHandler::putValues ( const Real64 value,
UInt32  size 
) [inline, inherited]

Definition at line 360 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00361 {
00362 #if BYTE_ORDER == LITTLE_ENDIAN
00363     if(_networkOrder == true)
00364     {
00365         for(UInt32 i = 0; i < size; ++i)
00366         {
00367             putValue(value[i]);
00368         }
00369     }
00370     else
00371 #endif
00372     {
00373         put(value, size * sizeof(Real64));
00374     }
00375 }

void osg::BinaryDataHandler::putValues ( const Real128 value,
UInt32  size 
) [inline, inherited]

Definition at line 378 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::BinaryDataHandler::put(), and osg::BinaryDataHandler::putValue().

00379 {
00380 #if BYTE_ORDER == LITTLE_ENDIAN
00381     if(_networkOrder == true)
00382     {
00383         for(UInt32 i = 0; i < size; ++i)
00384         {
00385             putValue(value[i]);
00386         }
00387     }
00388     else
00389 #endif
00390     {
00391         put(value, size * sizeof(Real128));
00392     }
00393 }

void osg::BinaryDataHandler::putValues ( const std::string *  value,
UInt32  size 
) [inline, inherited]

Definition at line 396 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::putValue().

00397 {
00398     for(UInt32 i = 0; i<size; ++i)
00399     {
00400         putValue(value[i]);    
00401     }
00402 }

void BinaryDataHandler::get ( void *  dst,
UInt32  size 
) [inherited]

Definition at line 161 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_currentReadBuffer, osg::BinaryDataHandler::_currentReadBufferPos, osg::BinaryDataHandler::_zeroCopyThreshold, osg::osgMin(), osg::BinaryDataHandler::pullBuffer(), osg::BinaryDataHandler::read(), and osg::BinaryDataHandler::readBufEnd().

Referenced by osg::RemoteAspect::receiveSync(), and osg::ClusterViewBuffer::recv().

00162 {
00163     MemoryHandle data = static_cast<MemoryHandle>(dst);
00164 
00165     if(_zeroCopyThreshold && size >= _zeroCopyThreshold)
00166     {
00167         if(_zeroCopyThreshold > 1)
00168         {
00169             UInt8 tag;
00170 
00171             // we have to read the tag, to force reading of data blocks
00172             // if the first data field was zero copied
00173             get(&tag, sizeof(tag));
00174         }
00175 
00176         // read direct into destination
00177         read(data, size);
00178     }
00179     else
00180     {
00181         UInt32 copySize;
00182 
00183         while(size != 0)
00184         {
00185             // read new data if nothing left
00186             if(_currentReadBuffer == readBufEnd())
00187             {
00188                 pullBuffer();
00189             }
00190 
00191             // num bytes to copy
00192             copySize = osgMin((_currentReadBuffer->getDataSize() -
00193                                _currentReadBufferPos),
00194                               size);
00195 
00196             // no data in buffer ?
00197             if(copySize != 0)
00198             {
00199                 memcpy( data,
00200                        _currentReadBuffer->getMem() + _currentReadBufferPos,
00201                         copySize);
00202 
00203                  size                 -= copySize;
00204                 _currentReadBufferPos += copySize;
00205                  data                 += copySize;
00206             }
00207 
00208             // skip to next buffer if current buffer is full
00209             if(_currentReadBufferPos == _currentReadBuffer->getDataSize())
00210             {
00211                 _currentReadBuffer++;
00212                 _currentReadBufferPos = 0;
00213             }
00214         }
00215     }
00216 }

void BinaryDataHandler::getAndAlloc ( MemoryHandle src,
UInt32  size 
) [inherited]

read data in a dynamic allocated block

If data was compressed or converted then it is not possible to write it into the destination memory. BinaryDataHandler doesn't store data in continous memory areas. If the caller needs a continuous memory then we provide a dynamic allocated block. The caller is responsible to free this block.

Definition at line 227 of file OSGBinaryDataHandler.cpp.

00228 {
00229     src = new UInt8[size];
00230 
00231     get(src, size);
00232 }

void osg::BinaryDataHandler::getValue ( bool &  value  )  [inline, inherited]

Definition at line 405 of file OSGBinaryDataHandler.inl.

Referenced by osg::BINLoader::chargeFieldContainers(), osg::SortFirstWindow::clientInit(), osg::ClusterNetwork::connectAllGroupToPoint(), osg::ClusterNetwork::connectAllPointToPoint(), osg::osg::FieldDataTraits2< bool >::copyFromBin(), osg::RenderNode::copyFromBin(), osg::ParticleBSPTree::copyFromBin(), osg::MField< FieldTypeT, fieldNameSpace >::copyFromBin(), osg::FieldTraitsIntegralRecurseMapper< uint64_t >::copyFromBin(), osg::FieldTraitsRecurseBase1< GLXContext >::copyFromBin(), osg::FieldTraitsRecurseBase< osg::NodePtr >::copyFromBin(), osg::osg::FieldTraitsRecurseMapper< FieldContainerPtr, false >::copyFromBin(), osg::osg::FieldDataTraits< Plane >::copyFromBin(), osg::osg::FieldDataTraits1< GLenum >::copyFromBin(), osg::osg::FieldDataTraits1< BitVector >::copyFromBin(), osg::osg::FieldDataTraits< DynamicVolume >::copyFromBin(), osg::osg::FieldDataTraits1< Time >::copyFromBin(), osg::osg::FieldDataTraits< std::string >::copyFromBin(), osg::osg::FieldTraitsRecurseMapper< AttachmentMap, false >::copyFromBin(), osg::BINLoader::createFieldContainers(), osg::BinaryDataHandler::getValue(), osg::BinaryDataHandler::getValues(), osg::ClusterWindow::init(), osg::RemoteAspect::receiveSync(), osg::ClusterViewBuffer::recv(), osg::SortFirstWindow::serverInit(), osg::ClusterServer::start(), and osg::PointMCastConnection::wait().

00406 {
00407     //get(&value, sizeof(bool));
00408     UInt8 temp;
00409     get(&temp, sizeof(UInt8));
00410     value = (temp!=0);
00411 }

void osg::BinaryDataHandler::getValue ( UInt8 value  )  [inline, inherited]

Definition at line 414 of file OSGBinaryDataHandler.inl.

00415 {
00416     get(&value, sizeof(UInt8));
00417 }

void osg::BinaryDataHandler::getValue ( UInt16 value  )  [inline, inherited]

Definition at line 420 of file OSGBinaryDataHandler.inl.

References osg::osgntohs().

00421 {
00422     get(&value, sizeof(UInt16));
00423 
00424     value = osgntohs(value);
00425 }

void osg::BinaryDataHandler::getValue ( UInt32 value  )  [inline, inherited]

Definition at line 428 of file OSGBinaryDataHandler.inl.

References osg::osgntohl().

00429 {
00430     get(&value, sizeof(UInt32));
00431 
00432     value = osgntohl(value);
00433 }

void osg::BinaryDataHandler::getValue ( UInt64 value  )  [inline, inherited]

Definition at line 436 of file OSGBinaryDataHandler.inl.

References osg::osgntohll().

00437 {
00438     get(&value, sizeof(UInt64));
00439 
00440     value = osgntohll(value);
00441 }

void osg::BinaryDataHandler::getValue ( Int8 value  )  [inline, inherited]

Definition at line 444 of file OSGBinaryDataHandler.inl.

00445 {
00446     get(&value, sizeof(Int8));
00447 }

void osg::BinaryDataHandler::getValue ( Int16 value  )  [inline, inherited]

Definition at line 450 of file OSGBinaryDataHandler.inl.

References osg::osgntohs().

00451 {
00452     get(&value, sizeof(Int16));
00453 
00454     value = osgntohs(value);
00455 }

void osg::BinaryDataHandler::getValue ( Int32 value  )  [inline, inherited]

Definition at line 458 of file OSGBinaryDataHandler.inl.

References osg::osgntohl().

00459 {
00460     get(&value, sizeof(Int32));
00461 
00462     value = osgntohl(value);
00463 }

void osg::BinaryDataHandler::getValue ( Int64 value  )  [inline, inherited]

Definition at line 466 of file OSGBinaryDataHandler.inl.

References osg::osgntohll().

00467 {
00468     get(&value, sizeof(Int64));
00469 
00470     value = osgntohll(value);
00471 }

void osg::BinaryDataHandler::getValue ( Real16 value  )  [inline, inherited]

Definition at line 474 of file OSGBinaryDataHandler.inl.

References osg::osgntohs(), and osg::Real16::setBits().

00475 {
00476     UInt16 v;
00477 
00478     get(&v, sizeof(Real16));
00479 
00480     v     = osgntohs(v);
00481     value.setBits(v);
00482 }

void osg::BinaryDataHandler::getValue ( Real32 value  )  [inline, inherited]

Definition at line 485 of file OSGBinaryDataHandler.inl.

References osg::osgntohf(), and osg::osgntohl().

00486 {
00487     get(&value, sizeof(Real32));
00488 
00489     value = osgntohf(value);
00490 
00491 #if 0
00492     // doesn't work on my 64 bit linux ...
00493     UInt32 v;
00494 
00495     get(&v, sizeof(Real32));
00496 
00497     v     = osgntohl(v);
00498     value = *(reinterpret_cast<Real32 *>(&v));
00499 #endif
00500 }

void osg::BinaryDataHandler::getValue ( Real64 value  )  [inline, inherited]

Definition at line 503 of file OSGBinaryDataHandler.inl.

References osg::osgntohd(), and osg::osgntohll().

00504 {
00505     get(&value, sizeof(Real64));
00506 
00507     value = osgntohd(value);
00508 
00509 #if 0
00510     UInt64 v;
00511 
00512     get(&v, sizeof(Real64));
00513 
00514     v     = osgntohll(v);
00515     value = *(reinterpret_cast<Real64 *>(&v));
00516 #endif
00517 }

void osg::BinaryDataHandler::getValue ( Real128 value  )  [inline, inherited]

Definition at line 520 of file OSGBinaryDataHandler.inl.

References osg::osgntohdd(), and osg::osgntohll().

00521 {
00522     get(&value, sizeof(Real128));
00523 
00524     value = osgntohdd(value);
00525 
00526 #if 0
00527     UInt64 v[2];
00528 
00529 #if BYTE_ORDER == LITTLE_ENDIAN
00530     get(&v[1], sizeof(UInt64));
00531     get(&v[0], sizeof(UInt64));
00532 #else
00533     get(&v[0], sizeof(UInt64));
00534     get(&v[1], sizeof(UInt64));
00535 #endif
00536 
00537     v[0]     = osgntohll(v[0]);
00538     v[1]     = osgntohll(v[1]);
00539     value = *(reinterpret_cast<Real128 *>(&v));
00540 #endif
00541 }

void osg::BinaryDataHandler::getValue ( std::string &  value  )  [inline, inherited]

Definition at line 544 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::getValue().

00545 {
00546     UInt32  len;
00547     Char8  *str = NULL;
00548 
00549     getValue(len);
00550 
00551     if(len != 0)
00552     {
00553         str = new Char8[len];
00554         
00555         get(str, len);
00556 
00557         value = str;
00558         
00559         delete [] str;
00560     }
00561     else
00562     {
00563         value.erase();
00564     }
00565 }

void osg::BinaryDataHandler::getValues ( bool *  value,
UInt32  size 
) [inline, inherited]

void osg::BinaryDataHandler::getValues ( UInt8 value,
UInt32  size 
) [inline, inherited]

Definition at line 575 of file OSGBinaryDataHandler.inl.

00576 {
00577     get(value, size * sizeof(UInt8));
00578 }

void osg::BinaryDataHandler::getValues ( UInt16 value,
UInt32  size 
) [inline, inherited]

Definition at line 581 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, and osg::osgntohs().

00582 {
00583     get(value, size * sizeof(UInt16));
00584 
00585 #if BYTE_ORDER == LITTLE_ENDIAN
00586     if(_networkOrder == true)
00587     {
00588         for(UInt32 i = 0; i < size; ++i)
00589         {
00590             value[i] = osgntohs(value[i]);
00591         }
00592     }
00593 #endif
00594 }

void osg::BinaryDataHandler::getValues ( UInt32 value,
UInt32  size 
) [inline, inherited]

Definition at line 597 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, and osg::osgntohl().

00598 {
00599     get(value, size * sizeof(UInt32));
00600 
00601 #if BYTE_ORDER == LITTLE_ENDIAN
00602     if(_networkOrder == true)
00603     {
00604         for(UInt32 i = 0; i < size; ++i)
00605         {
00606             value[i] = osgntohl(value[i]);
00607         }
00608     }
00609 #endif
00610 }

void osg::BinaryDataHandler::getValues ( UInt64 value,
UInt32  size 
) [inline, inherited]

Definition at line 613 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, and osg::osgntohll().

00614 {
00615     get(value, size * sizeof(UInt64));
00616 
00617 #if BYTE_ORDER == LITTLE_ENDIAN
00618     if(_networkOrder == true)
00619     {
00620         for(UInt32 i = 0; i < size; ++i)
00621         {
00622             value[i] = osgntohll(value[i]);
00623         }
00624     }
00625 #endif
00626 }

void osg::BinaryDataHandler::getValues ( Int8 value,
UInt32  size 
) [inline, inherited]

Definition at line 629 of file OSGBinaryDataHandler.inl.

00630 {
00631     get(value, size * sizeof(Int8));
00632 }

void osg::BinaryDataHandler::getValues ( Int16 value,
UInt32  size 
) [inline, inherited]

Definition at line 635 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, and osg::osgntohs().

00636 {
00637     get(value, size * sizeof(Int16));
00638 
00639 #if BYTE_ORDER == LITTLE_ENDIAN
00640     if(_networkOrder == true)
00641     {
00642         for(UInt32 i = 0; i < size; ++i)
00643         {
00644             value[i] = osgntohs(value[i]);
00645         }
00646     }
00647 #endif
00648 }

void osg::BinaryDataHandler::getValues ( Int32 value,
UInt32  size 
) [inline, inherited]

Definition at line 651 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, and osg::osgntohl().

00652 {
00653     get(value, size * sizeof(Int32));
00654 
00655 #if BYTE_ORDER == LITTLE_ENDIAN
00656     if(_networkOrder == true)
00657     {
00658         for(UInt32 i = 0; i < size; ++i)
00659         {
00660             value[i] = osgntohl(value[i]);
00661         }
00662     }
00663 #endif
00664 }

void osg::BinaryDataHandler::getValues ( Int64 value,
UInt32  size 
) [inline, inherited]

Definition at line 667 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, and osg::osgntohll().

00668 {
00669     get(value, size * sizeof(Int64));
00670 
00671 #if BYTE_ORDER == LITTLE_ENDIAN
00672     if(_networkOrder == true)
00673     {
00674         for(UInt32 i = 0; i < size; ++i)
00675         {
00676             value[i] = osgntohll(value[i]);
00677         }
00678     }
00679 #endif
00680 }

void osg::BinaryDataHandler::getValues ( Real16 value,
UInt32  size 
) [inline, inherited]

Definition at line 683 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, osg::osgntohs(), and osg::Real16::setBits().

00684 {
00685     get(value, size * sizeof(Real16));
00686 
00687 #if BYTE_ORDER == LITTLE_ENDIAN
00688     if(_networkOrder == true)
00689     {
00690         UInt16 *intValue = reinterpret_cast<UInt16 *>(value);
00691 
00692         for(UInt32 i = 0; i < size; ++i)
00693         {
00694             value[i].setBits(osgntohs(intValue[i]));
00695         }
00696     }
00697 #endif
00698 }

void osg::BinaryDataHandler::getValues ( Real32 value,
UInt32  size 
) [inline, inherited]

Definition at line 701 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, and osg::osgntohl().

00702 {
00703     get(value, size * sizeof(Real32));
00704 
00705 #if BYTE_ORDER == LITTLE_ENDIAN
00706     if(_networkOrder == true)
00707     {
00708         UInt32 *intValue = reinterpret_cast<UInt32 *>(value);
00709 
00710         for(UInt32 i = 0; i < size; ++i)
00711         {
00712             intValue[i] = osgntohl(intValue[i]);
00713         }
00714     }
00715 #endif
00716 }

void osg::BinaryDataHandler::getValues ( Real64 value,
UInt32  size 
) [inline, inherited]

Definition at line 719 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, and osg::osgntohll().

00720 {
00721     get(value, size * sizeof(Real64));
00722 
00723 #if BYTE_ORDER == LITTLE_ENDIAN
00724     if(_networkOrder == true)
00725     {
00726         UInt64 *longValue = reinterpret_cast<UInt64 *>(value);
00727 
00728         for(UInt32 i = 0; i < size; ++i)
00729         {
00730             longValue[i] = osgntohll(longValue[i]);
00731         }
00732     }
00733 #endif
00734 }

void osg::BinaryDataHandler::getValues ( Real128 value,
UInt32  size 
) [inline, inherited]

Definition at line 737 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::_networkOrder, and osg::osgntohll().

00738 {
00739     get(value, size * sizeof(UInt64) * 2);
00740 
00741 #if BYTE_ORDER == LITTLE_ENDIAN
00742     if(_networkOrder == true)
00743     {
00744         UInt64 *longValue = reinterpret_cast<UInt64 *>(value);
00745 
00746         for(UInt32 i = 0; i < size; i += 2)
00747         {
00748             UInt64 l = longValue[i];
00749             longValue[i]     = osgntohll(longValue[i + 1]);
00750             longValue[i + 1] = osgntohll(longValue[l    ]);
00751         }
00752     }
00753 #endif
00754 }

void osg::BinaryDataHandler::getValues ( std::string *  value,
UInt32  size 
) [inline, inherited]

Definition at line 757 of file OSGBinaryDataHandler.inl.

References osg::BinaryDataHandler::getValue().

00758 {
00759     for(UInt32 i = 0; i < size; ++i)
00760     {
00761         getValue(value[i]);
00762     }
00763 }

void BinaryDataHandler::forceCopy ( void   )  [virtual, inherited]

always copy memory blocks befor write forceCopy must be called for all endpoints of this connection

Definition at line 260 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_zeroCopyThreshold.

00261 {
00262     _zeroCopyThreshold = 0;
00263 }

void BinaryDataHandler::forceDirectIO ( void   )  [virtual, inherited]

always read or write directly into or from memory blocks forceDirectIO must be called for all endpoints of this connection

Definition at line 268 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_zeroCopyThreshold.

00269 {
00270     _zeroCopyThreshold = 1;
00271 }

void BinaryDataHandler::flush ( void   )  [inherited]

void BinaryDataHandler::setNetworkOrder ( bool  value  )  [inherited]

always copy memory blocks befor write forceCopy must be called for all endpoints of this connection

Definition at line 277 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_networkOrder.

Referenced by osg::ClusterWindow::init(), and osg::ClusterServer::start().

00278 {
00279     _networkOrder = value;    
00280 }

bool BinaryDataHandler::getNetworkOrder ( void   )  [inherited]

always copy memory blocks befor write forceCopy must be called for all endpoints of this connection

Definition at line 282 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_networkOrder.

00283 {
00284     return _networkOrder;
00285 }

BinaryDataHandler::BuffersT::iterator osg::BinaryDataHandler::readBufBegin ( void   )  [inline, protected, inherited]

BinaryDataHandler::BuffersT::iterator osg::BinaryDataHandler::readBufEnd ( void   )  [inline, protected, inherited]

void BinaryDataHandler::readBufAdd ( MemoryHandle  mem,
UInt32  size,
UInt32  dataSize = 0 
) [protected, inherited]

void BinaryDataHandler::readBufClear ( void   )  [protected, inherited]

BinaryDataHandler::BuffersT::iterator osg::BinaryDataHandler::writeBufBegin ( void   )  [inline, protected, inherited]

BinaryDataHandler::BuffersT::iterator osg::BinaryDataHandler::writeBufEnd ( void   )  [inline, protected, inherited]

void BinaryDataHandler::writeBufAdd ( MemoryHandle  mem,
UInt32  size,
UInt32  dataSize = 0 
) [protected, inherited]

void BinaryDataHandler::writeBufClear ( void   )  [protected, inherited]

bool BinaryDataHandler::isReadBufferEmpty ( void   )  [protected, inherited]

check for data in read buffer

Definition at line 431 of file OSGBinaryDataHandler.cpp.

References osg::BinaryDataHandler::_currentReadBuffer, osg::BinaryDataHandler::_zeroCopyThreshold, and osg::BinaryDataHandler::readBufEnd().

Referenced by osg::PointMCastConnection::selectChannel().

00432 {
00433     if(_zeroCopyThreshold == 1)
00434         return true;
00435     if(_currentReadBuffer == readBufEnd())
00436         return true;
00437     return false;
00438 }


Friends And Related Function Documentation

friend class PointSockConnection [friend]

Definition at line 160 of file OSGGroupSockConnection.h.


Member Data Documentation

Definition at line 144 of file OSGGroupSockConnection.h.

Referenced by GroupSockConnection(), readBuffer(), and setParams().

Reimplemented in osg::GroupMCastConnection, and osg::GroupSockPipeline.

Definition at line 166 of file OSGGroupSockConnection.h.

Referenced by getType().

std::vector<UInt8> osg::GroupConnection::_selection [protected, inherited]

std::string osg::GroupConnection::_destination [protected, inherited]

std::set<Channel> osg::GroupConnection::_disconnectedChannel [protected, inherited]

Definition at line 115 of file OSGGroupConnection.h.

std::string osg::Connection::_interface [protected, inherited]

BuffersT::iterator osg::BinaryDataHandler::_currentReadBuffer [protected, inherited]

BuffersT::iterator osg::BinaryDataHandler::_currentWriteBuffer [protected, inherited]

bool osg::BinaryDataHandler::_networkOrder [protected, inherited]


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 12:03:52 2008 for OpenSG by  doxygen 1.5.5