VR-Link API Documentation for HLA 1516
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | 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:

Public Member Functions

 DtInetTcpSocket ()
 Default Constructor. More...
 
 DtInetTcpSocket (DtU16 localPort, DtInetDevice *hostIf=NULL, DtInetUtils::DtInetAddrFamily family=DtInetUtils::DtInetAddrFamily_IPv4, DtU32 flags=DtSockOptNoDelay, bool immediateOpen=true)
 Server Socket Constructor. More...
 
 DtInetTcpSocket (const DtInetEndpoint &dest, DtU16 localPort=0, DtInetDevice *hostIf=NULL, DtU32 flags=DtDefaultSockOpts, bool immediateOpen=true)
 Interactive Socket Constructors. More...
 
virtual ~DtInetTcpSocket ()
 Destructor. More...
 
virtual bool setDestination (const DtInetEndpoint &addr)
 Set / get the destination endpoint for the socket. More...
 
virtual bool openSocket ()
 Enable sending and receiving of packets. More...
 
virtual bool closeSocket ()
 Close a socket. More...
 
virtual bool bindToDevice (const DtInetDevice *hostIf=NULL)
 Set the network interface device the socket will attempt to bind to on the local host. More...
 
virtual bool listenForConnections ()
 Begin listening for inbound connection attempts. TCP sockets only. More...
 
virtual bool acceptConnection (DtInetTcpSocket *peer, DtU32 flags=DtDefaultSockOpts)
 Accept an inbound connection attempt. More...
 
virtual bool connectToDestination ()
 Initiate a connection to the destination endpoint. More...
 
virtual bool setSocket (const DtInetEndpoint &dest, DtU16 localPort=0, DtInetDevice *hostIf=NULL, DtU32 flags=DtDefaultSockOpts)
 Set all socket parameters at once. More...
 
virtual bool isOk ()
 Deprecated. More...
 
virtual unsigned descriptor () const
 Get the socket's descriptor. More...
 
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. More...
 
virtual int sendTo (caddr_t packet, size_t size, DtInetEndpoint &dest, DtU32 flags=0)
 Simple send methods. More...
 
virtual int sendChain (DtInetBufferChain &packets, DtU32 flags=0)
 Send from a chain of buffers. More...
 
virtual int sendChainTo (DtInetBufferChain &packets, DtInetEndpoint &dest, DtU32 flags=0)
 Simple send methods. More...
 
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. More...
 
virtual DtInetSockRcvStatus recvToChain (DtInetBufferChain &packets, DtU32 flags=0)
 Receives into user-supplied buffer chain. More...
 
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. More...
 
virtual DtInetSockRcvStatus recvToChainFrom (DtInetBufferChain &packets, DtInetEndpoint &src, DtU32 flags=0)
 Receives into a single user-supplied buffer. More...
 
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 ()
 
- Public Member Functions inherited from DtInetSocket
 DtInetSocket ()
 Default Constructor. More...
 
virtual ~DtInetSocket ()
 Destructor. More...
 
virtual const DtInetEndpointdestination () const
 
virtual const DtInetEndpointlocalEndpoint () const
 Get the local endpoint for the socket. More...
 
virtual bool setLocalPort (DtU16 port)
 Set / get the local port number of the socket. More...
 
virtual DtU16 localPort () const
 
virtual const DtInetDevicehostIf () const
 Get the host network interface device the socket is bound to. More...
 
virtual DtInetSockState state ()
 Return the present state of the socket. More...
 
virtual DtU32 protocol () const
 Get the protocol (DtInetProtocol_TCP or DtInetProtocol_UDP) More...
 
virtual
DtInetUtils::DtInetAddrFamily 
family () const
 Get the address family, IPv4 or IPv6. More...
 
virtual DtU32 flags ()
 Get the flags for this socket. More...
 
virtual int getLastError ()
 Return code or string describing last error. More...
 
virtual DtString getLastErrorString ()
 
virtual bool isErrorWouldBlockOrTryAgain ()
 
virtual void clearError ()
 
virtual int getTerminationCode ()
 Return code or string describing termination cause. More...
 
virtual DtString getTerminationString ()
 
virtual DtU64 totalBytesSent () const
 Get traffic statistics. More...
 
virtual DtU64 totalPacketsSent () const
 
virtual DtU64 totalBytesReceived () const
 
virtual DtU64 totalPacketsReceived () const
 
virtual void clearStats ()
 Reset all statistics. More...
 
virtual bool addProcessingCallback (DtInetSockProcessingType kind, DtInetSocketProcessingCallback cb, void *usr, int callSequence=-1)
 Add / remove pre- and post- processing callbacks. More...
 
virtual bool removeProcessingCallback (DtInetSockProcessingType kind, DtInetSocketProcessingCallback cb)
 
virtual DtTime receiveTime ()
 
virtual bool isNonBlocking () const
 
virtual bool isNoDelay () const
 
virtual bool isIPv4 () const
 Return true if the socket matches the queried family or protocol. More...
 
virtual bool isIPv6 () const
 Return true if the socket matches the queried family or protocol. More...
 
virtual bool isTcp () const
 Return true if the socket matches the queried family or protocol. More...
 
virtual bool isUdp () const
 Return true if the socket matches the queried family or protocol. More...
 

Protected Member Functions

virtual bool initAcceptedConnection (const DtInetAddr &localAddr, DtU16 localPort, DtU32 flags=DtDefaultSockOpts)
 Accepted Connection Initializer. More...
 
virtual bool openAcceptedConnection (DtInetEndpoint peer)
 Accepted Connection finalizer. More...
 
virtual void * tcpSocket ()
 Return the underlying socket object. More...
 
virtual void * tcpServerSocket ()
 
bool isServerSock () const
 Return true if the socket is a listening (aka 'server') socket. More...
 
- Protected Member Functions inherited from DtInetSocket
virtual bool findAndRemoveCallback (DtInetSockCallbackList &cbList, DtInetSocketProcessingCallback cb)
 

Protected Attributes

void * myIoService
 
void * myTcpSocket
 
void * myTcpAcceptor
 
DtInetUtils::DtInetAddrFamily myAddrFamily
 
- Protected Attributes inherited from DtInetSocket
DtInetEndpoint myLocalEndpoint
 
DtInetEndpoint myRemoteEndpoint
 
DtInetDevicemyHostIf
 
DtInetSockState myState
 
DtU32 myFlags
 
bool myAsync
 
bool myNonBlockingEnabled
 
bool myNoDelayEnabled
 
bool myStartImmediately
 
int myErrorCode
 
DtString myErrorString
 
int myTerminationCode
 
DtString myTerminationString
 
DtInetSockCallbackList myPreRecvCallbacks
 
DtInetSockCallbackList myPostRecvCallbacks
 
DtInetSockCallbackList myPreSendCallbacks
 
DtInetSockCallbackList myPostSendCallbacks
 
DtU64 mySentByteCount
 
DtU64 mySentPacketCount
 
DtU64 myReceivedByteCount
 
DtU64 myReceivedPacketCount
 
DtTime myReceiveTime
 

Private Member Functions

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

Private Attributes

DtInetTcpSockPimplmyAsyncPimpl
 

Friends

class DtInetTcpSockPimpl
 For async operations. More...
 

Detailed Description

The DtInetSocket class provides an address family independent stream socket.

Constructor & Destructor Documentation

DtInetTcpSocket::DtInetTcpSocket ( )

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.

DtInetTcpSocket::DtInetTcpSocket ( const DtInetTcpSocket orig)
private

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 unsigned DtInetTcpSocket::descriptor ( ) const
virtual

Get the socket's descriptor.

Implements DtInetSocket.

virtual DtU32 DtInetTcpSocket::getBytesAvailable ( )
virtual

Implements DtInetSocket.

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

Implements DtInetSocket.

virtual DtU32 DtInetTcpSocket::getReceiveBufferSize ( )
virtual

Implements DtInetSocket.

virtual DtU32 DtInetTcpSocket::getReceiveLowWatermark ( )
virtual

Implements DtInetSocket.

virtual bool DtInetTcpSocket::getReuseAddressOption ( )
virtual

Implements DtInetSocket.

virtual DtU32 DtInetTcpSocket::getSendBufferSize ( )
virtual

Implements DtInetSocket.

virtual DtU32 DtInetTcpSocket::getSendLowWatermark ( )
virtual

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 
)
protectedvirtual

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)
protectedvirtual

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 ( )
protectedvirtual
virtual void* DtInetTcpSocket::tcpSocket ( )
protectedvirtual

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

DtInetUtils::DtInetAddrFamily DtInetTcpSocket::myAddrFamily
protected
DtInetTcpSockPimpl* DtInetTcpSocket::myAsyncPimpl
private
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 Thu Sep 19 02:12:35 EDT 2024 from SVN revision 269601
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)