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 Types | Protected Attributes | Private Member Functions | Private Attributes | Friends
DtInetUdpSocket Class Reference

An abstract base class to represent a Socket Type. More...

+ Inheritance diagram for DtInetUdpSocket:
+ Collaboration diagram for DtInetUdpSocket:

Public Member Functions

 DtInetUdpSocket ()
 Default Constructor.
 DtInetUdpSocket (const DtInetEndpoint &dest, DtU16 localPort=0, DtInetDevice *hostIf=NULL, DtU32 flags=DtDefaultSockOpts, bool immediateOpen=true)
 Client Socket Constructor.
virtual ~DtInetUdpSocket ()
 Destructor.
virtual bool setDestination (const DtInetEndpoint &dest)
 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 connectToDestination ()
 Initiate a connection to a single unicast destination endpoint.
virtual bool disconnect ()
 Dissolve any unicast connection and return to normal 'connectionless' operation.
virtual bool isOk ()
 Deprecated.
virtual int descriptor () const
 Get the socket's descriptor.
virtual bool setSocket (const DtInetEndpoint &dest, DtU16 localPort=0, DtInetDevice *hostIf=NULL, DtU32 flags=DtDefaultSockOpts)
 Set all socket parameters at once.
virtual void * udpSocket ()
 Return the underlying socket object.
virtual void * secondUdpSocket ()
 Return the second underlying socket object.
Send methods.

Use send() or sendChain() to write to the socket's default destination endpoint, whether the socket is in CONNECTED state or not.

Use sendTo() or sendChainTo() on unconnected sockets to send to any endpoint, including the default destination, by specifying the endpoint in 'dest'. If sendTo() or sendChainTo() is used on a socket in the CONNECTED the destination endpoint will be ignored and the packet will be sent to the default destination. 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.

If the socket is in the CONNECTED state it will only receive packets from the designated connected host regardless of the receive method invoked.

Return a status code if an error occurs or if the received packet was discarded by packet filtering. If packet filtering is enabled this method 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)
 Simple receive method.
virtual DtInetSockRcvStatus recvToChain (DtInetBufferChain &packets, DtU32 flags=0)
 Receives into a 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.
virtual DtInetSockRcvStatus recvToChainFrom (DtInetBufferChain &packets, DtInetEndpoint &src, DtU32 flags=0)
 Simple receive method.
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 setSendBufferSize (DtU32 size)
virtual bool setReceiveBufferSize (DtU32 size)
virtual bool setBroadcastOption (bool onOrOff)
virtual bool setReuseAddressOption (bool onOrOff)
virtual bool setDoNotRouteOption (bool onOrOff)
virtual bool setSendLowWatermark (DtU32 size)
virtual bool setReceiveLowWatermark (DtU32 size)
virtual bool setMcastDevice (const DtInetAddr &devAddr)
virtual bool setMcastDevice (DtInetDevice *hostIf)
virtual DtU32 getSendBufferSize ()
virtual DtU32 getReceiveBufferSize ()
virtual DtU32 getBytesAvailable ()
virtual bool getBroadcastOption ()
virtual bool getReuseAddressOption ()
virtual bool getDoNotRouteOption ()
virtual DtU32 getSendLowWatermark ()
virtual DtU32 getReceiveLowWatermark ()
Multicast specific methods.

Join / drop subscription to multicast group.

Socket will join group identified by the multicast address in grpAddr or grpEndpoint. If an object is passed in the port value of the endpoint will be ignored and the socket will join from the same port the socket's local endpoint uses. If no interface is specified in the join it will join on the host's default multicast interface.

virtual bool joinMulticastGroup (const DtInetAddr &grpAddr, DtInetDevice *device=NULL)
 Change the default time-to-live on outbound multicast packets sent from this socket.
virtual bool joinMulticastGroup (const DtInetEndpoint &grpEndpoint, DtInetDevice *device=NULL)
 Change the default time-to-live on outbound multicast packets sent from this socket.
virtual bool dropMulticastGroup (const DtInetAddr &grpAddr, DtInetDevice *device=NULL)
 Change the default time-to-live on outbound multicast packets sent from this socket.
virtual bool dropMulticastGroup (const DtInetEndpoint &grpEndpoint, DtInetDevice *device=NULL)
 Change the default time-to-live on outbound multicast packets sent from this socket.
virtual bool setMcastTtlOption (DtU32 ttl)
 Change the default time-to-live on outbound multicast packets sent from this socket.
- Public Member Functions inherited from DtInetSocket
 DtInetSocket ()
 Default Constructor.
virtual ~DtInetSocket ()
 Destructor.
virtual const DtInetEndpointdestination () const
virtual const DtInetEndpointlocalEndpoint () const
 Get the local endpoint for the socket.
virtual bool setLocalPort (DtU16 port)
 Set / get the local port number of the socket.
virtual DtU16 localPort () const
virtual const DtInetDevicehostIf () const
 Get the host network interface device the socket is bound to.
virtual DtInetSockState state ()
 Return the present state of the socket.
virtual DtU32 protocol () const
 Get the protocol (DtInetProtocol_TCP or DtInetProtocol_UDP)
virtual
DtInetUtils::DtInetAddrFamily 
family () const
 Get the address family, IPv4 or IPv6.
virtual int getLastError ()
 Return code or string describing last error.
virtual DtString getLastErrorString ()
virtual bool isErrorWouldBlockOrTryAgain ()
virtual void clearError ()
virtual int getTerminationCode ()
 Return code or string describing termination cause.
virtual DtString getTerminationString ()
virtual DtU64 totalBytesSent () const
 Get traffic statistics.
virtual DtU64 totalPacketsSent () const
virtual DtU64 totalBytesReceived () const
virtual DtU64 totalPacketsReceived () const
virtual void clearStats ()
 Reset all statistics.
virtual bool addProcessingCallback (DtInetSockProcessingType kind, DtInetSocketProcessingCallback cb, void *usr, int callSequence=-1)
 Add / remove pre- and post- processing callbacks.
virtual bool removeProcessingCallback (DtInetSockProcessingType kind, DtInetSocketProcessingCallback cb)
virtual bool isNonBlocking () const
virtual bool isNoDelay () const
virtual bool isIPv4 () const
 Return true if the socket matches the queried family or protocol.
virtual bool isIPv6 () const
 Return true if the socket matches the queried family or protocol.
virtual bool isTcp () const
 Return true if the socket matches the queried family or protocol.
virtual bool isUdp () const
 Return true if the socket matches the queried family or protocol.

Protected Types

typedef std::pair< DtInetAddr,
DtInetAddr
DtInetMcastGroupIntfcBinding
 Associate the multicast group address with the host interface address the group is joined from.
typedef std::vector
< DtInetMcastGroupIntfcBinding
DtInetMcastGroupBindings

Protected Attributes

void * myIoService
void * myUdpSocket
void * mySecondUdpSocket
DtInetMcastGroupBindings myMcastGroups
- 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

Private Member Functions

 DtInetUdpSocket (const DtInetUdpSocket &orig)
 Copy constructor not implemented.
DtInetUdpSocketoperator= (const DtInetUdpSocket &orig)
 Assignment not implemented.

Private Attributes

DtInetUdpSockPimplmyAsyncPimpl

Friends

class DtInetUdpSockPimpl
 For async operations.

Additional Inherited Members

- Protected Member Functions inherited from DtInetSocket
virtual bool findAndRemoveCallback (DtInetSockCallbackList &cbList, DtInetSocketProcessingCallback cb)

Detailed Description

An abstract base class to represent a Socket Type.

Member Typedef Documentation

Associate the multicast group address with the host interface address the group is joined from.

Constructor & Destructor Documentation

DtInetUdpSocket::DtInetUdpSocket ( )

Default Constructor.

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

Client Socket Constructor.

Takes a DtInetEndpoint (containing the destination address, protocol (must be 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 allow datagrams to be sent and received using the default packet handlers which perform no parsing of packets. To use custom packet handlers for the send and receive functions set 'immediateOpen' to false, configure the packet handler callbacks, then call openSocket() or connectToDestination() if the 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 DtInetUdpSocket::~DtInetUdpSocket ( )
virtual

Destructor.

DtInetUdpSocket::DtInetUdpSocket ( const DtInetUdpSocket orig)
private

Copy constructor not implemented.

Member Function Documentation

virtual bool DtInetUdpSocket::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. If the socket's destination endpoint specifies a broadcast address the socket will bind to the specified interface's default broadcast address even if it does not match the broadcast address in the destination endpoint (ie. it's idiot-proof). Returns true on success and false on failure. Call getLastError() and getLastErrorString() to retrieve cause of failure.

Implements DtInetSocket.

virtual bool DtInetUdpSocket::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.

Reimplemented in DtDisSocket.

virtual bool DtInetUdpSocket::connectToDestination ( )
virtual

Initiate a connection to a single unicast destination endpoint.

For UDP sockets this precludes sending and receiving broadcast and multicast while the socket is connected. It is not necessary to call connectToDestination() for normal UDP socket communication with multiple hosts or when performing broadcast or multicast send / receive. The destination can be changed at will on UDP sockets by calling setDestination() and connectToDestination() in succession. The socket state will be set to CONNECTED to indicate the socket is only communicating with one destination endpoint. To dissolve a connection (eg. communicate with more than one host at will) use disconnect(). The state will be set to OPEN when the connection is dissolved. Since there is no handshaking to confirm that communication with the destination is possible this method always returns true unless an error occurs. Call getLastError() and getLastErrorString() to retrieve the cause of the failure.

Implements DtInetSocket.

virtual int DtInetUdpSocket::descriptor ( ) const
virtual

Get the socket's descriptor.

Implements DtInetSocket.

virtual bool DtInetUdpSocket::disconnect ( )
virtual

Dissolve any unicast connection and return to normal 'connectionless' operation.

virtual bool DtInetUdpSocket::dropMulticastGroup ( const DtInetAddr grpAddr,
DtInetDevice device = NULL 
)
virtual

Change the default time-to-live on outbound multicast packets sent from this socket.

virtual bool DtInetUdpSocket::dropMulticastGroup ( const DtInetEndpoint grpEndpoint,
DtInetDevice device = NULL 
)
virtual

Change the default time-to-live on outbound multicast packets sent from this socket.

virtual bool DtInetUdpSocket::getBroadcastOption ( )
virtual
virtual DtU32 DtInetUdpSocket::getBytesAvailable ( )
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::getDoNotRouteOption ( )
virtual

Implements DtInetSocket.

virtual DtU32 DtInetUdpSocket::getReceiveBufferSize ( )
virtual

Implements DtInetSocket.

virtual DtU32 DtInetUdpSocket::getReceiveLowWatermark ( )
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::getReuseAddressOption ( )
virtual

Implements DtInetSocket.

virtual DtU32 DtInetUdpSocket::getSendBufferSize ( )
virtual

Implements DtInetSocket.

virtual DtU32 DtInetUdpSocket::getSendLowWatermark ( )
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::isOk ( )
virtual

Deprecated.

Provided for compatibility with DtSocket. For UDP sockets returns true if socket is open (or connected)

Reimplemented from DtInetSocket.

virtual bool DtInetUdpSocket::joinMulticastGroup ( const DtInetAddr grpAddr,
DtInetDevice device = NULL 
)
virtual

Change the default time-to-live on outbound multicast packets sent from this socket.

virtual bool DtInetUdpSocket::joinMulticastGroup ( const DtInetEndpoint grpEndpoint,
DtInetDevice device = NULL 
)
virtual

Change the default time-to-live on outbound multicast packets sent from this socket.

virtual bool DtInetUdpSocket::openSocket ( )
virtual

Enable sending and receiving of packets.

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

Implements DtInetSocket.

Reimplemented in DtDisSocket.

DtInetUdpSocket& DtInetUdpSocket::operator= ( const DtInetUdpSocket orig)
private

Assignment not implemented.

virtual DtInetSockRcvStatus DtInetUdpSocket::recv ( caddr_t  buff,
size_t  buffSize,
DtU32  flags = 0 
)
virtual

Simple receive method.

This method does NOT perform pre- or post- reception callbacks. It 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 DtInetUdpSocket::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.

Implements DtInetSocket.

Reimplemented in DtDisSocket.

virtual DtInetSockRcvStatus DtInetUdpSocket::recvToChain ( DtInetBufferChain packets,
DtU32  flags = 0 
)
virtual

Receives into a buffer chain.

This method CAN perform pre- and post- reception callbacks. The chain can be populated with buffers by the user in which case as much received data as possible that will fit in the available buffers is returned. If the buffer chain is too small for a single datagram packet this method will fill it with as much data as possible and return DtInetSockRcv_BUFFER_TOO_SMALL. The unreturned data is discarded. If the chain supplied by the caller is empty the method will allocate buffers and add them to the chain.

Implements DtInetSocket.

virtual DtInetSockRcvStatus DtInetUdpSocket::recvToChainFrom ( DtInetBufferChain packets,
DtInetEndpoint src,
DtU32  flags = 0 
)
virtual

Simple receive method.

This method does NOT perform pre- or post- reception callbacks. It 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 void* DtInetUdpSocket::secondUdpSocket ( )
virtual

Return the second underlying socket object.

This socket is only opened under linux, and only when the remote endpoint is broadcast, and a host interface address has been specified. Otherwise, this is a copy of the first socket.

virtual int DtInetUdpSocket::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.

Reimplemented in DtDisSocket.

virtual int DtInetUdpSocket::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.

Reimplemented in DtDisSocket.

virtual int DtInetUdpSocket::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.

Reimplemented in DtDisSocket.

virtual int DtInetUdpSocket::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.

Reimplemented in DtDisSocket.

virtual bool DtInetUdpSocket::setBroadcastOption ( bool  onOrOff)
virtual
virtual bool DtInetUdpSocket::setDestination ( const DtInetEndpoint dest)
virtual

Set / get the destination endpoint for the socket.

The endpoint protocol must not be TCP. If the protocol of the endpoint is not set, this call will automatically set it to UDP. The address family (IPv4 or IPv6) is assumed from the destination endpoint. The socket will not automatically connect when the destination is set. Use openSocket() or connectToDestination() to initiate communication on the socket. The destination can be changed at will on UDP sockets by calling setDestination() and connectToDestin- ation() in succession. To dissolve a connection (eg. communicate with more than one host at will) set the destination endpoint family to DtInetAddrFamily_INVALID, then call connectToDestination(). setDestination() returns true if the destination is valid for a UDP socket, false otherwise.

Implements DtInetSocket.

virtual bool DtInetUdpSocket::setDoNotRouteOption ( bool  onOrOff)
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::setMcastDevice ( const DtInetAddr devAddr)
virtual
virtual bool DtInetUdpSocket::setMcastDevice ( DtInetDevice hostIf)
virtual
virtual bool DtInetUdpSocket::setMcastTtlOption ( DtU32  ttl)
virtual

Change the default time-to-live on outbound multicast packets sent from this socket.

virtual bool DtInetUdpSocket::setNonBlockingOption ( bool  onOrOff)
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::setReceiveBufferSize ( DtU32  size)
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::setReceiveLowWatermark ( DtU32  size)
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::setReuseAddressOption ( bool  onOrOff)
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::setSendBufferSize ( DtU32  size)
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::setSendLowWatermark ( DtU32  size)
virtual

Implements DtInetSocket.

virtual bool DtInetUdpSocket::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.

Implements DtInetSocket.

virtual void* DtInetUdpSocket::udpSocket ( )
virtual

Return the underlying socket object.

Must be cast to appropriate type before using

Friends And Related Function Documentation

friend class DtInetUdpSockPimpl
friend

For async operations.

Member Data Documentation

DtInetUdpSockPimpl* DtInetUdpSocket::myAsyncPimpl
private
void* DtInetUdpSocket::myIoService
protected
DtInetMcastGroupBindings DtInetUdpSocket::myMcastGroups
protected
void* DtInetUdpSocket::mySecondUdpSocket
protected
void* DtInetUdpSocket::myUdpSocket
protected

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

Document ID: Generated on Wed Jan 7 13:31:29 EST 2015 from SVN revision 149162
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)