VR-Link API Documentation for DIS
Public Member Functions | Protected Member Functions | Protected Attributes
DtInetSocketMgr Class Reference
+ Collaboration diagram for DtInetSocketMgr:

List of all members.

Public Member Functions

 DtInetSocketMgr (DtU32 connectionFlags=DtDefaultSockOpts)
 Default Constructor.
 DtInetSocketMgr (DtInetEndpoint &serverEndpoint, DtInetDevice *hostIf=NULL, DtU32 serverFlags=(DtDefaultSockOpts|DtSockOptNonBlocking), DtU32 connectionFlags=DtDefaultSockOpts, DtInetUtils::DtInetAddrFamily family=DtInetUtils::DtInetAddrFamily_IPv4)
 Server manager.
virtual ~DtInetSocketMgr ()
 Destructor.
virtual int processConnections ()
 Check for incoming connection attempts.
virtual DtInetSocketserverSocket () const
 Returns a pointer to the server socket, whether it be a DtInetTcpSocket or a DtInetUdpSocket.
virtual const DtInetSocketListsocketList () const
 Returns the list (actually a map) of sockets being managed.
virtual DtInetSocketpeerSocket (const DtInetEndpoint &peer) const
 Returns a pointer to the socket object associated with the peer endpoint specified in the 'peer' argument.
virtual void addSocketCreationCallback (DtSocketCreationCallback cb, void *socketCreator)
 Set a specialized socket creation callback to be invoked prior to accepting a new incoming connection.
Connection addition methods.

Initiate a connection (TCP) or add new peer (UDP) to the list of managed connections.

The peer endpoint may be a unicast, broadcast, or multicast address. If the connection is UDP and the connectUdpSocket parameter is FALSE no new socket is created. Unconnected UDP links are handled by the UDP server socket. However if the UDP link is to be connected a new UDP socket is created. If the openImmediately parameter is FALSE the application is responsible for opening and connecting the returned socket. Returns a pointer to the new socket created or to the UDP socket handling all unconnected UDP links or NULL if an error occurs.

virtual DtInetSocketaddConnection (const DtInetEndpoint &peerEp, DtU16 localPort=0, DtInetDevice *hostIf=NULL, bool openImmediately=true, bool connectUdpSocket=false)
 Add an established socket to the list of managed connections.
virtual DtInetSocketaddConnection (const DtInetSocket *socket)
 Add an established socket to the list of managed connections.
Connection removal methods.

Remove a connection from the list of managed connections.

Any socket removal callbacks registered by the application will be invoked. The application is responsible for closing sockets and releasing the memory allocated for sockets (even if it was allocated by the socket manager in addConnection()). This should be performed in a socket removal call- back. Returns TRUE if the connection was successfully closed. Returns FALSE if the connection was not found in the connection list, which could indicate it was closed by the peer.

virtual bool removeConnection (const DtInetEndpoint &peerEndpoint)
virtual bool removeConnection (const DtInetSocket *socket)
Send methods

Send a packet to one or more sockets.

If the destination list is empty the packet is sent to all connections. If the manager detects that an error or a connection that has been closed by the peer during this operation it will automatically remove it from the connection list and invoke any socket removal callbacks. The manager will continue attempting to send to to the remaining active sockets. Returns number of bytes sent or -1 if any error occurs.

virtual int sendTo (caddr_t buff, int buffSize, DtInetDestList &dest, DtU32 flags=0)
virtual int sendTo (DtInetBufferChain packets, DtInetDestList &dest, DtU32 flags=0)
Receive methods

Receive a packet from one connection at a time.

If the 'peer' argument address member is not an ANY address (INADDR_ANY or IN6ADDR_ANY) the manager will try to receive from that peer connection. Otherwise the manager will return the next available packet and fill in the 'peer' endpoint information to indicate which connection it was received from. The manager ensures fairness in checking for received packets from every connection in its connection list. If the manager detects that an error on a socket or detects a connection that has been closed by the peer during this method it will automatically remove it from the connection list and invoke any socket. If an error is detected the receive operation will be aborted immediately and an error indication returned. Otherwise the manager will attempt to receive from the remaining active sockets after handling the termination. Returns the number of bytes received or an error status indication if any error occurs.

virtual DtInetSockRcvStatus recvFrom (caddr_t buff, size_t buffSize, DtInetEndpoint &peer, DtU32 flags=0)
virtual DtInetSockRcvStatus recvToChainFrom (DtInetBufferChain &packets, DtInetEndpoint &peer, DtU32 flags=0)
Add / Delete Socket Addition Callbacks

Add/remove socket addition callback to be invoked when a new socket connection is accepted.

The order in which these callbacks are invoked can be controlled by setting the 'order' when adding the callback. Callbacks are invoked in order from lowest to highest. If the order callbacks are invoked doesn't matter the 'order' parameter can be set to -1. This will cause it to be added to the current end of the list.

virtual void addSocketAdditionCallback (DtInetSocketAdditionCallback cb, void *usr, int order)
virtual void removeSocketAdditionCallback (DtInetSocketAdditionCallback cb, void *usr)
Add / Delete Socket Removal Callbacks

Add/remove socket removal callback to be invoked when a managed socket connection is removed.

The order in which these callbacks are invoked can be controlled by setting the 'order' when adding the callback. Callbacks are invoked in order from lowest to highest. If the order callbacks are invoked doesn't matter the 'order' parameter can be set to -1. This will cause it to be added to the current end of the list.

virtual void addSocketRemovalCallback (DtInetSocketRemovalCallback cb, void *usr, int order)
virtual void removeSocketRemovalCallback (DtInetSocketRemovalCallback cb, void *usr)
Flags accessors

Get the server socket or connection flags

virtual DtU32 getServerFlags () const
virtual DtU32 getConnectionFlags () const
Error reporting

Retrieve or clear the last error code or description.

virtual int getLastError ()
virtual DtString getLastErrorString ()
virtual void clearError ()

Protected Member Functions

 DtInetSocketMgr (const DtInetSocketMgr &)
 Copy CTOR Not Implemented.
DtInetSocketMgroperator= (const DtInetSocketMgr &)
 Assignment Operator Not Implemented.
virtual int processNewTcpConnections ()
virtual int processNewUdpConnections ()
virtual DtInetSocketremoveByKey (const DtInetEndpoint &key, DtInetSocketList &list)
virtual bool removeByItem (const DtInetSocket *item, DtInetSocketList &list)

Protected Attributes

DtInetSocketmyServerSocket
DtInetTcpSocketmyTcpServerSocket
DtInetUdpSocketmyUdpServerSocket
DtInetSocketList mySockets
std::pair< DtInetEndpoint,
DtInetSocket * > 
myLastSocketReadFrom
std::map< int,
DtInetSocketCbInfo * > 
myAdditionCallbacks
std::map< int,
DtInetSocketCbInfo * > 
myRemovalCallbacks
DtSocketCreationCallback mySocketCreateCallback
void * mySocketCreator
DtU32 myServerFlags
DtU32 myConnectionFlags
int myErrorCode
DtString myErrorString
DtInetTcpSocketmyPeerSocket
 The next peer socket to be returned.

Constructor & Destructor Documentation

Default Constructor.

Creates a generic socket manager without a server socket. Incoming connections cannot be accepted.

Server manager.

Creates a socket manager which opens a server socket using the protocol, address, and port specified in the serverEndpoint argument. If the server endpoint address is INADDR_ANY (or IN6ADDR_ANY) the server will bind to the interface specified by the hostIf parameter. If a specific interface is not identified the server will accept connections on all interfaces. If a specific port is not identified (port == 0) an ephemeral port will be chosen. The serverFlags argument specifies the operating characteristics of the server socket only. The connectionFlags argument specifies the default flags that will be applied to any automatically accepted connections. The individual connection socket flags can be altered within a socket addition callback. A TCP server manager will create a TCP socket to listen for and accept incoming connections but which cannot be used for sending and receiving packets. A UDP server manager will create a UDP socket which can keep track of known sources for incoming packets and signal, via socket addition callbacks, when a previously unknown source is recognized. This UDP server socket can send and receive data to or from all other UDP peers in 'unconnected' mode, including multicast groups, but cannot send or receive broadcast communications. The application is responsible for joining the UDP server socket to a multicast group. The family parameter is only used for TCP socket managers, as only a port is needed for a TCP server socket. This way, users can specify what type of address to use.

virtual DtInetSocketMgr::~DtInetSocketMgr ( ) [virtual]

Destructor.

Copy CTOR Not Implemented.


Member Function Documentation

virtual DtInetSocket* DtInetSocketMgr::addConnection ( const DtInetEndpoint peerEp,
DtU16  localPort = 0,
DtInetDevice hostIf = NULL,
bool  openImmediately = true,
bool  connectUdpSocket = false 
) [virtual]

Add an established socket to the list of managed connections.

The socket should be open (and, if it's a TCP socket, connected) by the application prior to putting it under control of the socket manager. Returns a pointer to the socket or NULL if an error occurs.

virtual DtInetSocket* DtInetSocketMgr::addConnection ( const DtInetSocket socket) [virtual]

Add an established socket to the list of managed connections.

The socket should be open (and, if it's a TCP socket, connected) by the application prior to putting it under control of the socket manager. Returns a pointer to the socket or NULL if an error occurs.

virtual void DtInetSocketMgr::addSocketAdditionCallback ( DtInetSocketAdditionCallback  cb,
void *  usr,
int  order 
) [virtual]
virtual void DtInetSocketMgr::addSocketCreationCallback ( DtSocketCreationCallback  cb,
void *  socketCreator 
) [virtual]

Set a specialized socket creation callback to be invoked prior to accepting a new incoming connection.

If no socket creation callback is registered a socket of the same type as the server socket accepting the connection (DtInetTcpSocket or DtInetUdpSocket) is used.

virtual void DtInetSocketMgr::addSocketRemovalCallback ( DtInetSocketRemovalCallback  cb,
void *  usr,
int  order 
) [virtual]
virtual void DtInetSocketMgr::clearError ( ) [virtual]
virtual DtU32 DtInetSocketMgr::getConnectionFlags ( ) const [virtual]
virtual int DtInetSocketMgr::getLastError ( ) [virtual]
virtual DtU32 DtInetSocketMgr::getServerFlags ( ) const [virtual]
DtInetSocketMgr& DtInetSocketMgr::operator= ( const DtInetSocketMgr ) [protected]

Assignment Operator Not Implemented.

virtual DtInetSocket* DtInetSocketMgr::peerSocket ( const DtInetEndpoint peer) const [virtual]

Returns a pointer to the socket object associated with the peer endpoint specified in the 'peer' argument.

Returns NULL if the peer endpoint does not appear in the connection list. Note that it's possible that the connection list contains more than one connection to a single endpoint (such as if an application must maintain multiple connections to a single server socket on another host) so any application that needs to identify a single socket out of many connected to a single endpoint should retrieve the complete socket list to search for the desired socket.

virtual int DtInetSocketMgr::processConnections ( ) [virtual]

Check for incoming connection attempts.

Any socket addition callbacks registered by the application will be invoked. The new connections will be automatically added to the list of managed connections if all socket addition callbacks return true. Returns the number of new connections added or -1 if a manager error occurs and -2 if a socket error occurs during establishment of a connection.

virtual int DtInetSocketMgr::processNewTcpConnections ( ) [protected, virtual]
virtual int DtInetSocketMgr::processNewUdpConnections ( ) [protected, virtual]
virtual DtInetSockRcvStatus DtInetSocketMgr::recvFrom ( caddr_t  buff,
size_t  buffSize,
DtInetEndpoint peer,
DtU32  flags = 0 
) [virtual]
virtual DtInetSockRcvStatus DtInetSocketMgr::recvToChainFrom ( DtInetBufferChain packets,
DtInetEndpoint peer,
DtU32  flags = 0 
) [virtual]
virtual bool DtInetSocketMgr::removeByItem ( const DtInetSocket item,
DtInetSocketList list 
) [protected, virtual]
virtual DtInetSocket* DtInetSocketMgr::removeByKey ( const DtInetEndpoint key,
DtInetSocketList list 
) [protected, virtual]
virtual bool DtInetSocketMgr::removeConnection ( const DtInetEndpoint peerEndpoint) [virtual]
virtual bool DtInetSocketMgr::removeConnection ( const DtInetSocket socket) [virtual]
virtual void DtInetSocketMgr::removeSocketAdditionCallback ( DtInetSocketAdditionCallback  cb,
void *  usr 
) [virtual]
virtual void DtInetSocketMgr::removeSocketRemovalCallback ( DtInetSocketRemovalCallback  cb,
void *  usr 
) [virtual]
virtual int DtInetSocketMgr::sendTo ( caddr_t  buff,
int  buffSize,
DtInetDestList dest,
DtU32  flags = 0 
) [virtual]
virtual int DtInetSocketMgr::sendTo ( DtInetBufferChain  packets,
DtInetDestList dest,
DtU32  flags = 0 
) [virtual]
virtual DtInetSocket* DtInetSocketMgr::serverSocket ( ) const [virtual]

Returns a pointer to the server socket, whether it be a DtInetTcpSocket or a DtInetUdpSocket.

virtual const DtInetSocketList& DtInetSocketMgr::socketList ( ) const [virtual]

Returns the list (actually a map) of sockets being managed.

If the socket manager is handling unconnected UDP sockets the UDP 'server' socket is included in this list. The TCP server socket is never included in this list.


Member Data Documentation

The next peer socket to be returned.


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

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)