VR-Link API Documentation for DIS
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends
DtInetTcpSocket Class Reference

The DtInetSocket class provides an address family independent stream socket. More...

+ Inheritance diagram for DtInetTcpSocket:
+ Collaboration diagram for DtInetTcpSocket:

List of all members.

Public Member Functions

 DtInetTcpSocket ()
 Default Constructor.
 DtInetTcpSocket (DtU16 localPort, DtInetDevice *hostIf=NULL, DtInetUtils::DtInetAddrFamily family=DtInetUtils::DtInetAddrFamily_IPv4, DtU32 flags=DtSockOptNoDelay, bool immediateOpen=true)
 Server Socket Constructor.
 DtInetTcpSocket (const DtInetEndpoint &dest, DtU16 localPort=0, DtInetDevice *hostIf=NULL, DtU32 flags=DtDefaultSockOpts, bool immediateOpen=true)
 Interactive Socket Constructors.
virtual ~DtInetTcpSocket ()
 Destructor.
virtual bool setDestination (const DtInetEndpoint &addr)
 Set / get the destination endpoint for the socket.
virtual bool openSocket ()
 Enable sending and receiving of packets.
virtual bool closeSocket ()
 Close a socket.
virtual bool bindToDevice (const DtInetDevice *hostIf=NULL)
 Set the network interface device the socket will attempt to bind to on the local host.
virtual bool listenForConnections ()
 Begin listening for inbound connection attempts. TCP sockets only.
virtual bool acceptConnection (DtInetTcpSocket *peer, DtU32 flags=DtDefaultSockOpts)
 Accept an inbound connection attempt.
virtual bool connectToDestination ()
 Initiate a connection to the destination endpoint.
virtual bool setSocket (const DtInetEndpoint &dest, DtU16 localPort=0, DtInetDevice *hostIf=NULL, DtU32 flags=DtDefaultSockOpts)
 Set all socket parameters at once.
virtual bool isOk ()
 Deprecated.
virtual int descriptor () const
 Get the socket's descriptor.
Send methods.

All send methods send packets to the connected destination endpoint.

sendTo() and sendChainTo() are provided for flexibility to allow an application to use TCP and UDP sockets interchangeably. The endpoint 'dest' is ignored when using sendTo() or sendChainTo(). Return the number of bytes sent or -1 if an error occurs. Use getLastError() and getLastErrorString() to retrieve cause of failure.

virtual int send (caddr_t packet, size_t size, DtU32 flags=0)
 Simple send methods.
virtual int sendTo (caddr_t packet, size_t size, DtInetEndpoint &dest, DtU32 flags=0)
 Simple send methods.
virtual int sendChain (DtInetBufferChain &packets, DtU32 flags=0)
 Send from a chain of buffers.
virtual int sendChainTo (DtInetBufferChain &packets, DtInetEndpoint &dest, DtU32 flags=0)
 Simple send methods.
Receive methods.

Return a status code if an error occurs or if the received packet was discarded by packet filtering.

If packet filtering is enabled these methods may return empty buffers. Otherwise the number of bytes received is returned in which case the return value should be cast to an integer type. If an error occurs use getLastError() and getLastErrorString() to retrieve the cause of the failure.

virtual DtInetSockRcvStatus recv (caddr_t buff, size_t buffSize, DtU32 flags=0)
 Receives into a single user-supplied buffer.
virtual DtInetSockRcvStatus recvToChain (DtInetBufferChain &packets, DtU32 flags=0)
 Receives into user-supplied buffer chain.
virtual DtInetSockRcvStatus recvFrom (caddr_t buff, size_t buffSize, DtInetEndpoint &src, DtU32 flags=0)
 Same as above, but sets 'src' to reflect peer from which the packet was received, which in the case of TCP sockets will always be the original destination.
virtual DtInetSockRcvStatus recvToChainFrom (DtInetBufferChain &packets, DtInetEndpoint &src, DtU32 flags=0)
 Receives into a single user-supplied buffer.
Set / get socket options.

These methods provides an interface to all supported socket options.

The socket must be open in order to use these methods.

virtual bool setNonBlockingOption (bool onOrOff)
virtual bool setReuseAddressOption (bool onOrOff)
virtual bool setSendBufferSize (DtU32 size)
virtual bool setReceiveBufferSize (DtU32 size)
virtual bool setDoNotRouteOption (bool onOrOff)
virtual bool setSendLowWatermark (DtU32 size)
virtual bool setReceiveLowWatermark (DtU32 size)
virtual bool setTcpNoDelayOption (bool onOrOff)
virtual bool setTcpLingerOption (DtU16 timeout)
virtual bool setConnAbortedOption (bool onOrOff)
virtual bool setTcpKeepAliveOption (bool onOrOff)
virtual DtU32 getSendBufferSize ()
virtual DtU32 getReceiveBufferSize ()
virtual DtU32 getBytesAvailable ()
virtual bool getReuseAddressOption ()
virtual bool getDoNotRouteOption ()
virtual DtU32 getSendLowWatermark ()
virtual DtU32 getReceiveLowWatermark ()
virtual bool getTcpLingerOption (DtU16 &timeout)
virtual bool getConnAbortedOption ()
virtual bool getTcpKeepAliveOption ()

Protected Member Functions

virtual bool initAcceptedConnection (const DtInetAddr &localAddr, DtU16 localPort, DtU32 flags=DtDefaultSockOpts)
 Accepted Connection Initializer.
virtual bool openAcceptedConnection (DtInetEndpoint peer)
 Accepted Connection finalizer.
virtual void * tcpSocket ()
 Return the underlying socket object.
virtual void * tcpServerSocket ()
bool isServerSock () const
 Return true if the socket is a listening (aka 'server') socket.

Protected Attributes

void * myIoService
void * myTcpSocket
void * myTcpAcceptor
DtInetUtils::DtInetAddrFamily myAddrFamily

Private Member Functions

 DtInetTcpSocket (const DtInetTcpSocket &orig)
 Copy constructor not implemented.
DtInetTcpSocketoperator= (const DtInetTcpSocket &orig)
 Assignment not implemented.

Private Attributes

DtInetTcpSockPimplmyAsyncPimpl

Friends

class DtInetTcpSockPimpl
 For async operations.

Detailed Description

The DtInetSocket class provides an address family independent stream socket.


Constructor & Destructor Documentation

Default Constructor.

DtInetTcpSocket::DtInetTcpSocket ( DtU16  localPort,
DtInetDevice hostIf = NULL,
DtInetUtils::DtInetAddrFamily  family = DtInetUtils::DtInetAddrFamily_IPv4,
DtU32  flags = DtSockOptNoDelay,
bool  immediateOpen = true 
)

Server Socket Constructor.

Takes a port number to listen on, a pointer to the local network interface device the socket will be bound to, an address family indication (IPv4 or IPv6), socket option flags, and a trigger to open the socket immediately. If no host interface is specified the socket will be bound to INADDR_ANY (or IN6ADDR_ANY). If the 'immediateOpen' parameter is true the socket will immediately try to bind to an interface and listen for inbound connection attempts. New connections will not be automatically accepted if no socket addition callbacks are registered, therefore all new connections must be accepted by calling the acceptConnection() method. If the 'immediateOpen' parameter is false the socket will not start listening for connection attempts until the listenForConnections() method is invoked. Socket addition callbacks should be registered prior to invoking listen(). This ctor will not throw exceptions on failure. Check the socket status by calling state() (or isOk()) to determine if the socket is ready to use.

DtInetTcpSocket::DtInetTcpSocket ( const DtInetEndpoint dest,
DtU16  localPort = 0,
DtInetDevice hostIf = NULL,
DtU32  flags = DtDefaultSockOpts,
bool  immediateOpen = true 
)

Interactive Socket Constructors.

Takes a DtInetEndpoint (containing the destination address, protocol - TCP or UDP, and destination port number), a source port number to use, a pointer to the local network interface device the socket will be bound to, socket option flags, and an 'immediateOpen' indicator dictating how the socket should behave upon creation. The address family (IPv4 or IPv6) is assumed from the destin- ation endpoint object. If the specified local port is 0 an ephemeral port will be chosen for the connection UNLESS the destination is a broadcast or multicast address, in which case the destination port is used as the local port also. If no host interface is specified the most appropriate interface will be chosen based on the destination. If the destination endpoint specifies a multicast address the multicast group is joined automatically when the socket is opened and the group member- ship is dropped when the socket is closed. If the 'immediateOpen' parameter is true the socket will immediately try to bind to an interface and connect to the destination (TCP sockets) or allow datagrams to be sent and received (UDP) using the default packet handlers which perform no parsing of packets. To use custom packet handlers for TCP send and receive functions set 'immediateOpen' to false when using this ctor, then configure the packet handler callbacks, then call connectToDestination(). To use custom packet handlers for UDP send and receive functions set 'immediateOpen' to false, configure the packet handler callbacks, then call openSocket() or connectToDestination() if the UDP socket will only communicate with a single remote host. This ctor will not throw exceptions on failure. Check the socket status by calling state() (or isOk()) to determine if the socket is ready.

virtual DtInetTcpSocket::~DtInetTcpSocket ( ) [virtual]

Destructor.

Copy constructor not implemented.


Member Function Documentation

virtual bool DtInetTcpSocket::acceptConnection ( DtInetTcpSocket peer,
DtU32  flags = DtDefaultSockOpts 
) [virtual]

Accept an inbound connection attempt.

The remote and local endpoint information is stored in the 'peer' socket object provided by the caller. The 'flags' parameter should contain the default socket options which the new connections should be set to. Returns false if no new connection attempts were processed. Returns true if a new connection was attempted, even if the connection was not successfully completed. If the new connection was not successfully established the 'peer' socket will indicate the error condition. If the new connection was accepted successfully the 'peer' socket will be in the CONNECTED state on return.

virtual bool DtInetTcpSocket::bindToDevice ( const DtInetDevice hostIf = NULL) [virtual]

Set the network interface device the socket will attempt to bind to on the local host.

The actual bind takes place after the socket is opened. If hostIf is NULL the socket will bind to the first device with an assigned IP address that most closely matches the destination endpoint family and prefix. Returns true on success and false on failure. Call getLastError() and getLastErrorString() to retrieve cause of failure.

Implements DtInetSocket.

virtual bool DtInetTcpSocket::closeSocket ( ) [virtual]

Close a socket.

Returns true on successful close or false on failure. Call getLastError() and getLastErrorString() to retrieve cause of failure.

Implements DtInetSocket.

virtual bool DtInetTcpSocket::connectToDestination ( ) [virtual]

Initiate a connection to the destination endpoint.

Returns true on successful initiation of connection or false on failure. Note that initiation of connection does not necessarily mean completion of the connection. Call socket state() method to determine when the connection has been successfully completed. Call getLastError() and getLastErrorString() to retrieve cause of failure.

Implements DtInetSocket.

virtual int DtInetTcpSocket::descriptor ( ) const [virtual]

Get the socket's descriptor.

Implements DtInetSocket.

Implements DtInetSocket.

virtual bool DtInetTcpSocket::getConnAbortedOption ( ) [virtual]
virtual bool DtInetTcpSocket::getDoNotRouteOption ( ) [virtual]

Implements DtInetSocket.

Implements DtInetSocket.

Implements DtInetSocket.

virtual bool DtInetTcpSocket::getReuseAddressOption ( ) [virtual]

Implements DtInetSocket.

Implements DtInetSocket.

Implements DtInetSocket.

virtual bool DtInetTcpSocket::getTcpKeepAliveOption ( ) [virtual]
virtual bool DtInetTcpSocket::getTcpLingerOption ( DtU16 timeout) [virtual]
virtual bool DtInetTcpSocket::initAcceptedConnection ( const DtInetAddr localAddr,
DtU16  localPort,
DtU32  flags = DtDefaultSockOpts 
) [protected, virtual]

Accepted Connection Initializer.

Used by a server socket to initialize a socket to handle a newly accepted connection before it is accepted.

virtual bool DtInetTcpSocket::isOk ( ) [virtual]

Deprecated.

Provided for compatibility with DtSocket. For TCP sockets returns true if socket is not disconnected (client type sockets) or can no longer listen (server-type sockets). Intermediate states (like INPROGRESS) also return true, even though the socket is not in a state suitable for sending/receiving packets. Use state() to determine actual condition of socket.

Reimplemented from DtInetSocket.

bool DtInetTcpSocket::isServerSock ( ) const [protected]

Return true if the socket is a listening (aka 'server') socket.

virtual bool DtInetTcpSocket::listenForConnections ( ) [virtual]

Begin listening for inbound connection attempts. TCP sockets only.

virtual bool DtInetTcpSocket::openAcceptedConnection ( DtInetEndpoint  peer) [protected, virtual]

Accepted Connection finalizer.

User by a server socket to set the newly accepted socket's remoted destination endpoint and to change its state to CONNECTED.

virtual bool DtInetTcpSocket::openSocket ( ) [virtual]

Enable sending and receiving of packets.

For TCP sockets openSocket() has the same effect as connectToDestination(). Returns true on success or false on failure. Call getLastError() and getLastErrorString() to retrieve cause of failure.

Implements DtInetSocket.

DtInetTcpSocket& DtInetTcpSocket::operator= ( const DtInetTcpSocket orig) [private]

Assignment not implemented.

virtual DtInetSockRcvStatus DtInetTcpSocket::recv ( caddr_t  buff,
size_t  buffSize,
DtU32  flags = 0 
) [virtual]

Receives into a single user-supplied buffer.

If buffSize is too small for the packet this method will fill 'buff' with as much data as possible and return DtInetSockRcv_BUFFER_TOO_SMALL. The unreturned data is discarded.

Implements DtInetSocket.

virtual DtInetSockRcvStatus DtInetTcpSocket::recvFrom ( caddr_t  buff,
size_t  buffSize,
DtInetEndpoint src,
DtU32  flags = 0 
) [virtual]

Same as above, but sets 'src' to reflect peer from which the packet was received, which in the case of TCP sockets will always be the original destination.

These methods are provided for flexibility to allow an application to use TCP and UDP sockets interchangeably.

Implements DtInetSocket.

virtual DtInetSockRcvStatus DtInetTcpSocket::recvToChain ( DtInetBufferChain packets,
DtU32  flags = 0 
) [virtual]

Receives into user-supplied buffer chain.

For scattered receives. If buffer chain is too small for the packet this method will fill it with as much data as possible and return DtInetSockRcv_BUFFER_TOO_SMALL. The unreturned data is discarded.

Implements DtInetSocket.

virtual DtInetSockRcvStatus DtInetTcpSocket::recvToChainFrom ( DtInetBufferChain packets,
DtInetEndpoint src,
DtU32  flags = 0 
) [virtual]

Receives into a single user-supplied buffer.

If buffSize is too small for the packet this method will fill 'buff' with as much data as possible and return DtInetSockRcv_BUFFER_TOO_SMALL. The unreturned data is discarded.

Implements DtInetSocket.

virtual int DtInetTcpSocket::send ( caddr_t  packet,
size_t  size,
DtU32  flags = 0 
) [virtual]

Simple send methods.

The send() and sendChain() methods DO NOT support pre- or post- processing callbacks (eg. bundling, backlog queueing)

Implements DtInetSocket.

virtual int DtInetTcpSocket::sendChain ( DtInetBufferChain packets,
DtU32  flags = 0 
) [virtual]

Send from a chain of buffers.

For 'gather' send operations or when pre- or post- processing callbacks are used (eg. bundling, backlog queueing)

Implements DtInetSocket.

virtual int DtInetTcpSocket::sendChainTo ( DtInetBufferChain packets,
DtInetEndpoint dest,
DtU32  flags = 0 
) [virtual]

Simple send methods.

The send() and sendChain() methods DO NOT support pre- or post- processing callbacks (eg. bundling, backlog queueing)

Implements DtInetSocket.

virtual int DtInetTcpSocket::sendTo ( caddr_t  packet,
size_t  size,
DtInetEndpoint dest,
DtU32  flags = 0 
) [virtual]

Simple send methods.

The send() and sendChain() methods DO NOT support pre- or post- processing callbacks (eg. bundling, backlog queueing)

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setConnAbortedOption ( bool  onOrOff) [virtual]
virtual bool DtInetTcpSocket::setDestination ( const DtInetEndpoint addr) [virtual]

Set / get the destination endpoint for the socket.

The endpoint protocol MUST be TCP. The address family (IPv4 or IPv6) is assumed from the destination endpoint. The socket will not automatically connect when the destination is set. Use connectToDestination() to initiate connection. setDestination() returns true if the destination is valid for the type of socket, false otherwise.

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setDoNotRouteOption ( bool  onOrOff) [virtual]

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setNonBlockingOption ( bool  onOrOff) [virtual]

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setReceiveBufferSize ( DtU32  size) [virtual]

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setReceiveLowWatermark ( DtU32  size) [virtual]

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setReuseAddressOption ( bool  onOrOff) [virtual]

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setSendBufferSize ( DtU32  size) [virtual]

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setSendLowWatermark ( DtU32  size) [virtual]

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setSocket ( const DtInetEndpoint dest,
DtU16  localPort = 0,
DtInetDevice hostIf = NULL,
DtU32  flags = DtDefaultSockOpts 
) [virtual]

Set all socket parameters at once.

Returns true if the socket has not previously been opened and initialization succeeds, false otherwise. The socket will not immediately try to bind or connect to the destination.

Implements DtInetSocket.

virtual bool DtInetTcpSocket::setTcpKeepAliveOption ( bool  onOrOff) [virtual]
virtual bool DtInetTcpSocket::setTcpLingerOption ( DtU16  timeout) [virtual]
virtual bool DtInetTcpSocket::setTcpNoDelayOption ( bool  onOrOff) [virtual]
virtual void* DtInetTcpSocket::tcpServerSocket ( ) [protected, virtual]
virtual void* DtInetTcpSocket::tcpSocket ( ) [protected, virtual]

Return the underlying socket object.

Must be cast to appropriate type before using.


Friends And Related Function Documentation

friend class DtInetTcpSockPimpl [friend]

For async operations.


Member Data Documentation

void* DtInetTcpSocket::myIoService [protected]
void* DtInetTcpSocket::myTcpAcceptor [protected]
void* DtInetTcpSocket::myTcpSocket [protected]

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)