![]() |
VR-Link API Documentation for HLA Evolved
|
The DtInetSocket class provides a protocol independant, address family independant base class for TCP or UDP socket subclasses. More...
Inheritance diagram for DtInetSocket:
Collaboration diagram for DtInetSocket:Public Member Functions | |
| DtInetSocket () | |
| Default Constructor. | |
| virtual | ~DtInetSocket () |
| Destructor. | |
| virtual bool | setDestination (const DtInetEndpoint &dest)=0 |
| Set / get the destination endpoint for the socket. | |
| virtual const DtInetEndpoint & | destination () const |
| virtual const DtInetEndpoint & | localEndpoint () 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 bool | bindToDevice (const DtInetDevice *hostIf=NULL)=0 |
| Bind the socket to a network interface device on the local host. | |
| virtual const DtInetDevice * | hostIf () const |
| Get the host network interface device the socket is bound to. | |
| virtual bool | openSocket ()=0 |
| Enable sending and receiving of packets. | |
| virtual bool | closeSocket ()=0 |
| Close a socket. | |
| virtual bool | connectToDestination ()=0 |
| Initiate a connection to the destination endpoint. | |
| virtual DtInetSockState | state () |
| Return the present state of the socket. | |
| virtual bool | isOk () |
| Deprecated. | |
| 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 | descriptor () const =0 |
| Get the socket's descriptor. | |
| virtual bool | setSocket (const DtInetEndpoint &dest, DtU16 localPort=0, DtInetDevice *hostIf=NULL, DtU32 flags=DtDefaultSockOpts)=0 |
| Set all socket parameters at once. | |
| 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) |
Send methods. | |
These are pure virtual methods which must be overridden by subclasses that implement the underlying protocol (TCP, UDP, etc). 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)=0 |
| Simple send methods. | |
| virtual int | sendTo (caddr_t packet, size_t size, DtInetEndpoint &dest, DtU32 flags=0)=0 |
| Simple send methods. | |
| virtual int | sendChain (DtInetBufferChain &packets, DtU32 flags=0)=0 |
| Send from a chain of buffers. | |
| virtual int | sendChainTo (DtInetBufferChain &packets, DtInetEndpoint &dest, DtU32 flags=0)=0 |
| Simple send methods. | |
Receive methods. | |
These are pure virtual methods which must be overridden by subclasses that implement the underlying protocol (TCP, UDP, etc). Return a status code if an error occurs or if the received packet is discarded. 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)=0 |
| Simple receive method. | |
| virtual DtInetSockRcvStatus | recvToChain (DtInetBufferChain &packets, DtU32 flags=0)=0 |
| Receives into a buffer chain. | |
| virtual DtInetSockRcvStatus | recvFrom (caddr_t buff, size_t buffSize, DtInetEndpoint &src, DtU32 flags=0)=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)=0 |
| Simple receive method. | |
Get / Set methods. | |
These methods provides an interface all supported socket options. Subclasses must override these functions to perform the set or get operation on the underlying socket if the socket supports the operation. The socket must be open in order to use these methods. | |
| virtual bool | setNonBlockingOption (bool onOrOff)=0 |
| virtual bool | setReuseAddressOption (bool onOrOff)=0 |
| virtual bool | setSendBufferSize (DtU32 size)=0 |
| virtual bool | setReceiveBufferSize (DtU32 size)=0 |
| virtual bool | setDoNotRouteOption (bool onOrOff)=0 |
| virtual bool | setSendLowWatermark (DtU32 size)=0 |
| virtual bool | setReceiveLowWatermark (DtU32 size)=0 |
| virtual bool | isNonBlocking () const |
| virtual bool | isNoDelay () const |
| virtual bool | getReuseAddressOption ()=0 |
| virtual bool | getDoNotRouteOption ()=0 |
| virtual DtU32 | getSendBufferSize ()=0 |
| virtual DtU32 | getReceiveBufferSize ()=0 |
| virtual DtU32 | getBytesAvailable ()=0 |
| virtual DtU32 | getSendLowWatermark ()=0 |
| virtual DtU32 | getReceiveLowWatermark ()=0 |
| 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 Member Functions | |
| virtual bool | findAndRemoveCallback (DtInetSockCallbackList &cbList, DtInetSocketProcessingCallback cb) |
Protected Attributes | |
| DtInetEndpoint | myLocalEndpoint |
| DtInetEndpoint | myRemoteEndpoint |
| DtInetDevice * | myHostIf |
| 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 | |
| DtInetSocket (const DtInetSocket &orig) | |
| Copy constructor not implemented. | |
| DtInetSocket & | operator= (const DtInetSocket &orig) |
| Assignment not implemented. | |
The DtInetSocket class provides a protocol independant, address family independant base class for TCP or UDP socket subclasses.
The DtInetSocket class provides no communications facilities. All send and receive functionality is provided by protocol-specific subclasses
Default Constructor.
This ctor will create a skeleton socket object that has no socket descriptor or destination address and is not bound to any interface.
| virtual DtInetSocket::~DtInetSocket | ( | ) | [virtual] |
Destructor.
| DtInetSocket::DtInetSocket | ( | const DtInetSocket & | orig | ) | [private] |
Copy constructor not implemented.
| virtual bool DtInetSocket::addProcessingCallback | ( | DtInetSockProcessingType | kind, |
| DtInetSocketProcessingCallback | cb, | ||
| void * | usr, | ||
| int | callSequence = -1 |
||
| ) | [virtual] |
Add / remove pre- and post- processing callbacks.
The order in which callbacks are processed is determined by the callSequence value for each callback. The lower the sequence value, the earlier the callback is executed in the sequence. If no specific order is specified for a callback (callSequence == -1) the callback will be added to the end of the callback chain.
| virtual bool DtInetSocket::bindToDevice | ( | const DtInetDevice * | hostIf = NULL | ) | [pure virtual] |
Bind the socket to a network interface device on the local host.
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. All subclasses must override this pure virtual function in order to perform the bind() call on the underlying socket.
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual void DtInetSocket::clearError | ( | ) | [virtual] |
| void DtInetSocket::clearStats | ( | ) | [inline, virtual] |
Reset all statistics.
| virtual bool DtInetSocket::closeSocket | ( | ) | [pure virtual] |
Close a socket.
Returns true on successful close or false on failure. Call getLastError() and getLastErrorString() to retrieve cause of failure. All subclasses must override this pure virtual function to perform the close() operation on the underlying socket.
Implemented in DtDisSocket, DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::connectToDestination | ( | ) | [pure virtual] |
Initiate a connection to the destination endpoint.
For UDP sockets connectToDestination() limits the socket to only communicating with the specified destination endpoint (which must be a unicast address). Returns true on successful initiation of connection or false on failure. Note that initiation of connection does not necessarily mean completion of connection. Call socket state() method to determine when connection has been successfully completed. Call getLastError() and getLastErrorString() to retrieve cause of failure.
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual int DtInetSocket::descriptor | ( | ) | const [pure virtual] |
Get the socket's descriptor.
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual const DtInetEndpoint& DtInetSocket::destination | ( | ) | const [virtual] |
| virtual DtInetUtils::DtInetAddrFamily DtInetSocket::family | ( | ) | const [virtual] |
Get the address family, IPv4 or IPv6.
| bool DtInetSocket::findAndRemoveCallback | ( | DtInetSockCallbackList & | cbList, |
| DtInetSocketProcessingCallback | cb | ||
| ) | [inline, protected, virtual] |
References DtDELETE.
| virtual DtU32 DtInetSocket::getBytesAvailable | ( | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::getDoNotRouteOption | ( | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual int DtInetSocket::getLastError | ( | ) | [virtual] |
Return code or string describing last error.
| virtual DtString DtInetSocket::getLastErrorString | ( | ) | [virtual] |
| virtual DtU32 DtInetSocket::getReceiveBufferSize | ( | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual DtU32 DtInetSocket::getReceiveLowWatermark | ( | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::getReuseAddressOption | ( | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual DtU32 DtInetSocket::getSendBufferSize | ( | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual DtU32 DtInetSocket::getSendLowWatermark | ( | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual int DtInetSocket::getTerminationCode | ( | ) | [virtual] |
Return code or string describing termination cause.
| virtual DtString DtInetSocket::getTerminationString | ( | ) | [virtual] |
| virtual const DtInetDevice* DtInetSocket::hostIf | ( | ) | const [virtual] |
Get the host network interface device the socket is bound to.
Returns NULL if the socket is not yet bound to a device. Note that if the socket was not deliberately bound to a particular interface upon creation it may be bound to an interface automatically depending on the nature of the connection.
| virtual bool DtInetSocket::isErrorWouldBlockOrTryAgain | ( | ) | [virtual] |
| virtual bool DtInetSocket::isIPv4 | ( | ) | const [virtual] |
Return true if the socket matches the queried family or protocol.
| virtual bool DtInetSocket::isIPv6 | ( | ) | const [virtual] |
Return true if the socket matches the queried family or protocol.
| virtual bool DtInetSocket::isNoDelay | ( | ) | const [virtual] |
| virtual bool DtInetSocket::isNonBlocking | ( | ) | const [virtual] |
| virtual bool DtInetSocket::isOk | ( | ) | [virtual] |
Deprecated.
Provided for compatibility with DtSocket. For TCP sockets returns true if socket is not disconnected (client type sockets) or is stull listening (server-type sockets). Intermediate states (like INPROGRESS) also return true, even though the socket is not in a state suitable for sending/receiving packets or accepting connections. For UDP sockets returns true if socket creation succeeded.
Reimplemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::isTcp | ( | ) | const [virtual] |
Return true if the socket matches the queried family or protocol.
| virtual bool DtInetSocket::isUdp | ( | ) | const [virtual] |
Return true if the socket matches the queried family or protocol.
| virtual const DtInetEndpoint& DtInetSocket::localEndpoint | ( | ) | const [virtual] |
Get the local endpoint for the socket.
The local endpoint object is created by the socket object once a connection is established by TCP sockets or UDP sockets when connectToDestination() is invoked, or when packets are first transmitted for unconnected UDP sockets.
| virtual DtU16 DtInetSocket::localPort | ( | ) | const [virtual] |
| virtual bool DtInetSocket::openSocket | ( | ) | [pure 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.
Implemented in DtDisSocket, DtInetTcpSocket, and DtInetUdpSocket.
| DtInetSocket& DtInetSocket::operator= | ( | const DtInetSocket & | orig | ) | [private] |
Assignment not implemented.
| virtual DtU32 DtInetSocket::protocol | ( | ) | const [virtual] |
Get the protocol (DtInetProtocol_TCP or DtInetProtocol_UDP)
| virtual DtInetSockRcvStatus DtInetSocket::recv | ( | caddr_t | buff, |
| size_t | buffSize, | ||
| DtU32 | flags = 0 |
||
| ) | [pure virtual] |
Simple receive method.
This method does NOT perform pre- or post- reception callbacks. It receives into a single user-supplied buffer.
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual DtInetSockRcvStatus DtInetSocket::recvFrom | ( | caddr_t | buff, |
| size_t | buffSize, | ||
| DtInetEndpoint & | src, | ||
| DtU32 | flags = 0 |
||
| ) | [pure virtual] |
Same as above, but sets 'src' to reflect peer from which the packet was received.
Implemented in DtInetTcpSocket, DtInetUdpSocket, and DtDisSocket.
| virtual DtInetSockRcvStatus DtInetSocket::recvToChain | ( | DtInetBufferChain & | packets, |
| DtU32 | flags = 0 |
||
| ) | [pure 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 or an empty chain can be supplied in which case the method will allocate buffers and add them to the chain to be returned to the caller.
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual DtInetSockRcvStatus DtInetSocket::recvToChainFrom | ( | DtInetBufferChain & | packets, |
| DtInetEndpoint & | src, | ||
| DtU32 | flags = 0 |
||
| ) | [pure virtual] |
Simple receive method.
This method does NOT perform pre- or post- reception callbacks. It receives into a single user-supplied buffer.
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::removeProcessingCallback | ( | DtInetSockProcessingType | kind, |
| DtInetSocketProcessingCallback | cb | ||
| ) | [virtual] |
| virtual int DtInetSocket::send | ( | caddr_t | packet, |
| size_t | size, | ||
| DtU32 | flags = 0 |
||
| ) | [pure virtual] |
Simple send methods.
The send() and sendChain() methods DO NOT support pre- or post- processing callbacks (eg. bundling, backlog queueing)
Implemented in DtInetTcpSocket, DtInetUdpSocket, and DtDisSocket.
| virtual int DtInetSocket::sendChain | ( | DtInetBufferChain & | packets, |
| DtU32 | flags = 0 |
||
| ) | [pure virtual] |
Send from a chain of buffers.
For 'gather' send operations or when pre- or post- processing callbacks are used (eg. bundling, backlog queueing)
Implemented in DtInetTcpSocket, DtInetUdpSocket, and DtDisSocket.
| virtual int DtInetSocket::sendChainTo | ( | DtInetBufferChain & | packets, |
| DtInetEndpoint & | dest, | ||
| DtU32 | flags = 0 |
||
| ) | [pure virtual] |
Simple send methods.
The send() and sendChain() methods DO NOT support pre- or post- processing callbacks (eg. bundling, backlog queueing)
Implemented in DtInetTcpSocket, DtInetUdpSocket, and DtDisSocket.
| virtual int DtInetSocket::sendTo | ( | caddr_t | packet, |
| size_t | size, | ||
| DtInetEndpoint & | dest, | ||
| DtU32 | flags = 0 |
||
| ) | [pure virtual] |
Simple send methods.
The send() and sendChain() methods DO NOT support pre- or post- processing callbacks (eg. bundling, backlog queueing)
Implemented in DtInetTcpSocket, DtInetUdpSocket, and DtDisSocket.
| virtual bool DtInetSocket::setDestination | ( | const DtInetEndpoint & | dest | ) | [pure virtual] |
Set / get the destination endpoint for the socket.
The address family (IPv4 or IPv6) and protocol (TCP or UDP) are assumed from the destin- ation endpoint. The socket will not automatically connect when the destination is set. Use connectToDestination() to initiate connection. All subclasses must override setDestination() method to verify the destination endpoint protocol matches the underlying socket.
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::setDoNotRouteOption | ( | bool | onOrOff | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::setLocalPort | ( | DtU16 | port | ) | [virtual] |
Set / get the local port number of the socket.
The setLocalPort() method always returns true. Subclasses should override setLocalPort() to enforce any port restriction requirements the subclass may impose.
| virtual bool DtInetSocket::setNonBlockingOption | ( | bool | onOrOff | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::setReceiveBufferSize | ( | DtU32 | size | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::setReceiveLowWatermark | ( | DtU32 | size | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::setReuseAddressOption | ( | bool | onOrOff | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::setSendBufferSize | ( | DtU32 | size | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::setSendLowWatermark | ( | DtU32 | size | ) | [pure virtual] |
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual bool DtInetSocket::setSocket | ( | const DtInetEndpoint & | dest, |
| DtU16 | localPort = 0, |
||
| DtInetDevice * | hostIf = NULL, |
||
| DtU32 | flags = DtDefaultSockOpts |
||
| ) | [pure virtual] |
Set all socket parameters at once.
A new Boost socket object will be created. The socket will not immediately try to bind or connect to the destination. All subclasses must override this pure virtual function to verify the destination endpoint protocol matches the underlying socket. This method will have no effect after the socket has been opened.
Implemented in DtInetTcpSocket, and DtInetUdpSocket.
| virtual DtInetSockState DtInetSocket::state | ( | ) | [virtual] |
Return the present state of the socket.
| DtU64 DtInetSocket::totalBytesReceived | ( | ) | const [inline, virtual] |
| DtU64 DtInetSocket::totalBytesSent | ( | ) | const [inline, virtual] |
Get traffic statistics.
These do not account for integer overflow but you really gotta have an awful lot of traffic to overflow a 64 bit unsigned integer. In synchronous operation these are updated immediately as packets are sent or when they are received. In asynchronous operation they are updated asynchronously so should provide an accurate means of gauging latency and throughput.
| DtU64 DtInetSocket::totalPacketsReceived | ( | ) | const [inline, virtual] |
| DtU64 DtInetSocket::totalPacketsSent | ( | ) | const [inline, virtual] |
bool DtInetSocket::myAsync [protected] |
int DtInetSocket::myErrorCode [protected] |
DtString DtInetSocket::myErrorString [protected] |
DtU32 DtInetSocket::myFlags [protected] |
DtInetDevice* DtInetSocket::myHostIf [protected] |
DtInetEndpoint DtInetSocket::myLocalEndpoint [protected] |
bool DtInetSocket::myNoDelayEnabled [protected] |
bool DtInetSocket::myNonBlockingEnabled [protected] |
DtU64 DtInetSocket::myReceivedByteCount [protected] |
DtU64 DtInetSocket::myReceivedPacketCount [protected] |
DtInetEndpoint DtInetSocket::myRemoteEndpoint [protected] |
DtU64 DtInetSocket::mySentByteCount [protected] |
DtU64 DtInetSocket::mySentPacketCount [protected] |
bool DtInetSocket::myStartImmediately [protected] |
DtInetSockState DtInetSocket::myState [protected] |
int DtInetSocket::myTerminationCode [protected] |
DtString DtInetSocket::myTerminationString [protected] |