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

osg::PointSockConnection Class Reference
[Network]

#include <OSGPointSockConnection.h>

Inheritance diagram for osg::PointSockConnection:

osg::PointConnection osg::Connection osg::BinaryDataHandler osg::PointMCastConnection osg::PointSockPipeline List of all members.

Public Member Functions

params
*virtual void setParams (const std::string &params)
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)
Constructors
PointSockConnection (void)
virtual ~PointSockConnection (void)
type info
*virtual const ConnectionTypegetType (void)
connection
*virtual Channel connectPoint (const std::string &address, Time timeout=-1)
virtual Channel connectGroup (const std::string &address, Time timeout=-1)
virtual void disconnect (void)
virtual Channel acceptGroup (Time timeout=-1)
virtual Channel acceptPoint (Time timeout=-1)
virtual std::string bind (const std::string &interf)
synchronisation
*virtual bool wait (Time timeout) throw (ReadError )
virtual void signal (void) throw (WriteError)
channel handling
*virtual Channel selectChannel (Time timeout=-1) throw (ReadError)
params
*virtual void setParams (const std::string &params)
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 PointConnectioncreate (void)
 create conneciton

Public Attributes

public types
*typedef Int32 Channel
public types
*typedef Int32 Channel

Protected Types

typedef std::vector< MemoryBlock > BuffersT
typedef std::list< MemoryHandleFreeMemT

Protected Member Functions

Helper
*bool isReadBufferEmpty (void)
IO Implementation
*virtual void read (MemoryHandle mem, UInt32 size)
virtual void readBuffer (void)
virtual void write (MemoryHandle mem, UInt32 size)
virtual void writeBuffer (void)
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

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
members
*StreamSocket _acceptSocket
StreamSocket _socket
std::vector< UInt8_socketReadBuffer
std::vector< UInt8_socketWriteBuffer
members
*bool _pointToPoint
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 PointConnection Inherited

Private Member Functions

 PointSockConnection (const PointSockConnection &source)
PointSockConnectionoperator= (const PointSockConnection &source)

Static Private Attributes

static type
*static ConnectionType _type

Classes

struct  SocketBufferHeader

Detailed Description

Definition at line 59 of file OSGPointSockConnection.h.


Member Typedef Documentation

typedef PointConnection osg::PointSockConnection::Inherited [private]
 

Reimplemented from osg::PointConnection.

Reimplemented in osg::PointMCastConnection, and osg::PointSockPipeline.

Definition at line 160 of file OSGPointSockConnection.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

PointSockConnection::PointSockConnection void   ) 
 

Constructor

Definition at line 66 of file OSGPointSockConnection.cpp.

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

Referenced by create().

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

PointSockConnection::~PointSockConnection void   )  [virtual]
 

Destructor

Definition at line 83 of file OSGPointSockConnection.cpp.

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

00084 {
00085     _acceptSocket.close();
00086 }

osg::PointSockConnection::PointSockConnection const PointSockConnection source  )  [private]
 


Member Function Documentation

const ConnectionType * PointSockConnection::getType void   )  [virtual]
 

get connection type

Implements osg::PointConnection.

Reimplemented in osg::PointMCastConnection, and osg::PointSockPipeline.

Definition at line 90 of file OSGPointSockConnection.cpp.

References _type.

00091 {
00092     return &_type;
00093 }

Connection::Channel PointSockConnection::connectPoint const std::string &  address,
Time  timeout = -1
[virtual]
 

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

Implements osg::Connection.

Definition at line 101 of file OSGPointSockConnection.cpp.

References osg::PointConnection::_pointToPoint, _socket, and osg::GroupSockConnection::connectSocket().

00104 {
00105     StreamSocket socket;
00106     if(GroupSockConnection::connectSocket(socket,address,timeout))
00107     {
00108         _socket = socket;
00109         _pointToPoint = true;
00110         return true;
00111     }
00112     else
00113     {
00114         return false;
00115     }
00116 }

Connection::Channel PointSockConnection::connectGroup const std::string &  address,
Time  timeout = -1
[virtual]
 

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

Implements osg::PointConnection.

Reimplemented in osg::PointMCastConnection, and osg::PointSockPipeline.

Definition at line 121 of file OSGPointSockConnection.cpp.

References osg::PointConnection::_pointToPoint, _socket, and osg::GroupSockConnection::connectSocket().

Referenced by osg::PointSockPipeline::connectGroup(), and osg::PointMCastConnection::connectGroup().

00124 {
00125     StreamSocket socket;
00126     if(GroupSockConnection::connectSocket(socket,address,timeout))
00127     {
00128         _socket = socket;
00129         _pointToPoint = false;
00130         return true;
00131     }
00132     else
00133     {
00134         return false;
00135     }
00136 }

void PointSockConnection::disconnect void   )  [virtual]
 

disconnect the given channel

Implements osg::PointConnection.

Reimplemented in osg::PointMCastConnection, and osg::PointSockPipeline.

Definition at line 140 of file OSGPointSockConnection.cpp.

References _socket, and osg::StreamSocket::close().

00141 {
00142     _socket.close();
00143 }

Connection::Channel PointSockConnection::acceptGroup Time  timeout = -1  )  [virtual]
 

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

Implements osg::PointConnection.

Reimplemented in osg::PointMCastConnection, and osg::PointSockPipeline.

Definition at line 164 of file OSGPointSockConnection.cpp.

References _acceptSocket, osg::PointConnection::_pointToPoint, _socket, and osg::GroupSockConnection::acceptSocket().

Referenced by osg::PointSockPipeline::acceptGroup(), and osg::PointMCastConnection::acceptGroup().

00165 {
00166     if(GroupSockConnection::acceptSocket(_acceptSocket,_socket,timeout))
00167     {
00168         _pointToPoint = false;
00169         return 0;
00170     }
00171     else
00172     {
00173         return -1;
00174     }
00175 }

Connection::Channel PointSockConnection::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.

Definition at line 148 of file OSGPointSockConnection.cpp.

References _acceptSocket, osg::PointConnection::_pointToPoint, _socket, and osg::GroupSockConnection::acceptSocket().

00149 {
00150     if(GroupSockConnection::acceptSocket(_acceptSocket,_socket,timeout))
00151     {
00152         _pointToPoint = true;
00153         return 0;
00154     }
00155     else
00156     {
00157         return -1;
00158     }
00159 }

std::string PointSockConnection::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 183 of file OSGPointSockConnection.cpp.

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

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

bool PointSockConnection::wait Time  timeout  )  throw (ReadError ) [virtual]
 

wait for signal

Implements osg::PointConnection.

Reimplemented in osg::PointMCastConnection.

Definition at line 241 of file OSGPointSockConnection.cpp.

References FFATAL, and osg::osgntohl().

00242 {
00243     UInt32 tag;
00244     try
00245     {
00246         if(!_socket.waitReadable(timeout))
00247             return false;
00248         if(!_socket.recv(&tag,sizeof(tag)))
00249             throw ReadError("Channel closed");
00250         tag = osgntohl(tag);
00251         if(tag != 314156)
00252         {
00253             FFATAL(("Stream out of sync in SockConnection\n"));
00254             throw ReadError("Stream out of sync");
00255         }
00256     }
00257     catch(SocketError &e)
00258     {
00259         throw ReadError(e.what());
00260     }
00261     return true;
00262 }

void PointSockConnection::signal void   )  throw (WriteError) [virtual]
 

send signal

Implements osg::PointConnection.

Definition at line 266 of file OSGPointSockConnection.cpp.

References _socket, osg::osghtonl(), and osg::Socket::send().

00267 {
00268     UInt32 tag=osghtonl(314156);
00269     try
00270     {
00271         _socket.send(&tag,sizeof(tag));
00272     }
00273     catch(SocketError &e)
00274     {
00275         throw ReadError(e.what());
00276     }
00277 }

Connection::Channel PointSockConnection::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.

Reimplemented in osg::PointMCastConnection, and osg::PointSockPipeline.

Definition at line 221 of file OSGPointSockConnection.cpp.

00223 {
00224     try
00225     {
00226         if(_socket.waitReadable(timeout))
00227             return 0;
00228     }
00229     catch(SocketError &e)
00230     {
00231         throw ReadError(e.what());
00232     }
00233     return -1;
00234 }

PointConnection * PointSockConnection::create void   )  [static]
 

Reimplemented in osg::PointMCastConnection, and osg::PointSockPipeline.

Definition at line 284 of file OSGPointSockConnection.cpp.

References PointSockConnection().

00285 {
00286     return new PointSockConnection();
00287 }

void PointSockConnection::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.

Reimplemented in osg::PointMCastConnection, and osg::PointSockPipeline.

Definition at line 299 of file OSGPointSockConnection.cpp.

References _socket, and osg::Socket::recv().

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

00300 {
00301     int len;
00302 
00303     // read data
00304     len=_socket.recv(mem,size);
00305     if(len==0)
00306     {
00307         throw ReadError("read got 0 bytes!");
00308     }
00309 }

void PointSockConnection::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.

Reimplemented in osg::PointMCastConnection, and osg::PointSockPipeline.

Definition at line 318 of file OSGPointSockConnection.cpp.

References _socket, _socketReadBuffer, osg::osgntohl(), osg::BinaryDataHandler::readBufBegin(), and osg::Socket::recv().

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

00319 {
00320     int size;
00321     int len;
00322 
00323     // read buffer header
00324     len=_socket.recv(&_socketReadBuffer[0],sizeof(SocketBufferHeader));
00325     if(len==0)
00326         throw ReadError("peek got 0 bytes!");
00327     // read remaining data
00328     size=osgntohl(((SocketBufferHeader*)&_socketReadBuffer[0])->size);
00329     len=_socket.recv(&_socketReadBuffer[sizeof(SocketBufferHeader)],
00330                      size);
00331     if(len==0)
00332         throw ReadError("read got 0 bytes!");
00333     readBufBegin()->setDataSize(size);
00334 }    

void PointSockConnection::write MemoryHandle  mem,
UInt32  size
[protected, virtual]
 

Write data to destinations

Parameters:
mem