VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions

An implementation of DtSocket which uses a TCP connection. More...

+ Inheritance diagram for DtTcpSocket:
+ Collaboration diagram for DtTcpSocket:

Public Member Functions

 DtTcpSocket (int socketfd, DtIpv4Addr addr, int clientPort=0)
 Server Constructor.
 DtTcpSocket (DtIpv4Addr addr, int port=DtDEFAULT_PORT, int nonBlockingConnect=0)
 Client Constructor.
virtual ~DtTcpSocket ()
 Destructor.
virtual int sendTo (caddr_t packet, size_t packetSize, DtIpv4Addr addr=DtUSE_DEFAULT_IP_ADDR)
 Returns size of packet sent.
virtual int DtRecv (caddr_t *buffptr, int *status=NULL)
 DtReceiv is he function which VR-Link uses to read packets from the socket.
virtual int DtRecv (caddr_t buff, size_t bufsize)
virtual DtFlushStatus flush ()
 Send buffered messages.
virtual DtFlushStatus flush (long &byteCount)
 Send buffered messages.
virtual void DtBecomeNonBlocking ()
 Designate the socket as non-blocking.
virtual void DtBecomeBlocking ()
 Designate the socket as blocking.
virtual bool isOk () const
 passively checks for errors in the socket.
virtual bool isConnectionEstablished ()
 checks if the connection is fully established by sending a minimal packet through the socket.
virtual bool testConnectionStatus ()
 actively test the connection for socket errors.
DtIpv4Addr getConnectionAddr () const
 Get the address of the connected remote host.
int sizeOffset () const
 Get/Set mySizeOffset.
void setSizeOffset (int offset)
int sizeLength () const
 Get/Set mySizeLength.
void setSizeLength (int length)
virtual void setNoDelay (bool onOff)
 Sets the TCP_NODELAY sockopt to 1 if onOff is true, 0 otherwise.
virtual int peerPort () const
 Returns the port connected to on the remote host.
virtual int localPort () const
 Returns the port bound to on the local host.
int maxForwarderQueue () const
 Get/Set the max forwarder queue size.
void setMaxForwarderQueue (int maxForwarderQueue)
std::pair< int, int > getQueueStatus () const
 Returns the queue status int 1 - the packet wait list ( myPktWaitList ) count int 2 - the max forwarder queue size.
- Public Member Functions inherited from DtSocket
 DtSocket ()
 Default constructor.
virtual ~DtSocket ()
 Default Destructor.
virtual int DtSend (caddr_t packet, size_t size, DtIpv4Addr addr=DtUSE_DEFAULT_IP_ADDR)
 DtSend is called when someone wants to send a packet to this "Socket", in other words, all outgoing messages are passed to this socket via DtSend().
caddr_t DtRecv ()
virtual void setReceiveBufferSize (int newsize)
 Change the socket's receive buffer size that the OS uses to collect incoming data from the network.
virtual void setSendBufferSize (int newsize)
 Change the socket's send buffer size that the OS uses when writing data to the network.
virtual void setBundling (int maxSize)
virtual int isBundling ()
virtual void setUnbundling (int)
virtual DtIpv4Addr lastSourceInetAddr ()
virtual int DtReportPktsRcvd (void)
virtual void notifyMe ()
virtual int listenToMulticastGroup (DtIpv4Addr addr, DtIpv4Addr netInterface=DtUSE_DEFAULT_IP_ADDR)
virtual int dropMulticastGroup (DtIpv4Addr addr, DtIpv4Addr netInterface=DtUSE_DEFAULT_IP_ADDR)
virtual int setMcastTtl (int)
virtual void setMcastDevice (DtIpv4Addr)
virtual DtFilterTestexerciseId ()
virtual DtFilterTestprotocolVersion ()
virtual DtFilterTestpduKind ()
virtual DtFilterTestipAddr ()
virtual int readFd ()
 Get the file descriptor for reading and writing to this socket.
virtual int writeFd ()

Static Public Member Functions

static void setNoDelay (int sockfd, bool onOff)
 Sets the TCP_NODELAY sockopt to 1 if onOff is true, 0 otherwise.
static void setPacketBufferSize (int size)
 Set the default buffer size for receiving data.
- Static Public Member Functions inherited from DtSocket
static void initializeNetwork ()
static void setQuietSockets (bool quietVal)
 These functions determine whether a socket will print messages, informative or error.
static bool areQuietSockets ()

Protected Member Functions

int sendTo (caddr_t packet, size_t packetSize, bool reportMinSizePktFaults)
 Returns size of packet sent.
int recvWithStatus (caddr_t *buffptr, int *status)
int checkSize (int size, caddr_t *buffptr, int *status)
bool expandPktBuffer (unsigned int sizeNeeded)
int sendMinimumSizePkt (bool reportMinSizePktFaults)
- Protected Member Functions inherited from DtSocket
virtual bool accept (char *buf, DtIpv4Addr iaddr)

Protected Attributes

char * myPktBuff
unsigned int myPktBuffSize
DtIpv4Addr myConnectAddr
int myPeerPort
int myLocalPort
bool myOk
int myNeedSize
int mySizeOffset
int mySizeLength
int myNumBytesToWaitFor
int myNumBytesReceived
DtListmyPktWaitList
 List for saving un-sent packets.
int myMaxForwarderQueue
 Max forwarder queue size.
- Protected Attributes inherited from DtSocket
BufferMap myBufferMap
int myBundlingFlag
int myMaxBundleSize
int mySockFd

Static Protected Attributes

static int thePktBuffSize
- Static Protected Attributes inherited from DtSocket
static bool theAreQuietSockets
 Should a socket print messages, informative or error.

Private Member Functions

 DtTcpSocket (const DtTcpSocket &)
 Copy CTOR Not Implemented.
DtTcpSocketoperator= (const DtTcpSocket &)
 Assignment Operator Not Implemented.

Additional Inherited Members

- Public Attributes inherited from DtSocket
int myBlockingFlag
int pkts_rcvd
- Protected Types inherited from DtSocket
typedef std::vector< char > Buffer
typedef std::map< DtIpv4Addr,
Buffer
BufferMap
- Static Protected Member Functions inherited from DtSocket
static int getConfig (const char *device, int sock, ifconf *ifc)
 Get ifconfig information by filling in ifc.

Detailed Description

An implementation of DtSocket which uses a TCP connection.

Constructor & Destructor Documentation

DtTcpSocket::DtTcpSocket ( int  socketfd,
DtIpv4Addr  addr,
int  clientPort = 0 
)

Server Constructor.

DtTcpSocket::DtTcpSocket ( DtIpv4Addr  addr,
int  port = DtDEFAULT_PORT,
int  nonBlockingConnect = 0 
)

Client Constructor.

virtual DtTcpSocket::~DtTcpSocket ( )
virtual

Destructor.

DtTcpSocket::DtTcpSocket ( const DtTcpSocket )
private

Copy CTOR Not Implemented.

Member Function Documentation

int DtTcpSocket::checkSize ( int  size,
caddr_t *  buffptr,
int *  status 
)
protected
virtual void DtTcpSocket::DtBecomeBlocking ( )
virtual

Designate the socket as blocking.

virtual void DtTcpSocket::DtBecomeNonBlocking ( )
virtual

Designate the socket as non-blocking.

Reimplemented from DtSocket.

virtual int DtTcpSocket::DtRecv ( caddr_t *  buffptr,
int *  status = NULL 
)
virtual

DtReceiv is he function which VR-Link uses to read packets from the socket.

Users who wish to provide another mechanisim, such as shared memory, or loopback, will need to impliment or override these functions to return new packets. Depending on the implementation in derived DtSockets, one of the forms of DtRecv may be faster than the other.

DtRecv has an optional status argument that could more elegantly be implemented as different return codes, but this would break older code.

Note
If a derived class complains "... hides virtual DtRecv() ...", make sure you have BOTH overloads of DtRecv declared and defined in the subclass.

Implements DtSocket.

virtual int DtTcpSocket::DtRecv ( caddr_t  buff,
size_t   
)
virtual
See Also
DtRecv(caddr_t *buffptr, int *status=0)

Implements DtSocket.

bool DtTcpSocket::expandPktBuffer ( unsigned int  sizeNeeded)
protected
virtual DtFlushStatus DtTcpSocket::flush ( )
virtual

Send buffered messages.

Returns the status indicating error, flush is complete or incomplete.

Reimplemented from DtSocket.

virtual DtFlushStatus DtTcpSocket::flush ( long &  byteCount)
virtual

Send buffered messages.

Number of flushed bytes returned in provided parameter. Returns the status indicating error, flush is complete or incomplete.

Reimplemented from DtSocket.

DtIpv4Addr DtTcpSocket::getConnectionAddr ( ) const
inline

Get the address of the connected remote host.

std::pair<int, int> DtTcpSocket::getQueueStatus ( ) const

Returns the queue status int 1 - the packet wait list ( myPktWaitList ) count int 2 - the max forwarder queue size.

virtual bool DtTcpSocket::isConnectionEstablished ( )
virtual

checks if the connection is fully established by sending a minimal packet through the socket.

This should be checked after checking isOk().

bool DtTcpSocket::isOk ( ) const
inlinevirtual

passively checks for errors in the socket.

A result of true does not mean that the socket is fully connected.

Reimplemented from DtSocket.

virtual int DtTcpSocket::localPort ( ) const
virtual

Returns the port bound to on the local host.

int DtTcpSocket::maxForwarderQueue ( ) const

Get/Set the max forwarder queue size.

DtTcpSocket& DtTcpSocket::operator= ( const DtTcpSocket )
private

Assignment Operator Not Implemented.

virtual int DtTcpSocket::peerPort ( ) const
virtual

Returns the port connected to on the remote host.

int DtTcpSocket::recvWithStatus ( caddr_t *  buffptr,
int *  status 
)
protected
int DtTcpSocket::sendMinimumSizePkt ( bool  reportMinSizePktFaults)
protected
virtual int DtTcpSocket::sendTo ( caddr_t  packet,
size_t  packetSize,
DtIpv4Addr  addr = DtUSE_DEFAULT_IP_ADDR 
)
virtual

Returns size of packet sent.

It is possible that a packet may not get sent. It is the user's responsibility to call flush() and re-try sending un-sent packets.

Implements DtSocket.

int DtTcpSocket::sendTo ( caddr_t  packet,
size_t  packetSize,
bool  reportMinSizePktFaults 
)
protected

Returns size of packet sent.

Allows caller to specify whether to report send errors for minimum size messages ( for example, when checking non-blocking connect status, errors should not be reported )

void DtTcpSocket::setMaxForwarderQueue ( int  maxForwarderQueue)
virtual void DtTcpSocket::setNoDelay ( bool  onOff)
virtual

Sets the TCP_NODELAY sockopt to 1 if onOff is true, 0 otherwise.

Default is 1.

static void DtTcpSocket::setNoDelay ( int  sockfd,
bool  onOff 
)
static

Sets the TCP_NODELAY sockopt to 1 if onOff is true, 0 otherwise.

Default is 1.

static void DtTcpSocket::setPacketBufferSize ( int  size)
static

Set the default buffer size for receiving data.

The packet buffer is only created once (in the constructor), so it is important to call the function below before creating a TcpSocket if you want the buffer to be larger than the default value of 20000 bytes.

void DtTcpSocket::setSizeLength ( int  length)
void DtTcpSocket::setSizeOffset ( int  offset)
int DtTcpSocket::sizeLength ( ) const
inline

Get/Set mySizeLength.

int DtTcpSocket::sizeOffset ( ) const
inline

Get/Set mySizeOffset.

virtual bool DtTcpSocket::testConnectionStatus ( )
virtual

actively test the connection for socket errors.

sends a minimal size packet and returns false if any socket errors detected. Unlike isConnectionEstablished() a size 0 send is acceptable. This should be checked after checking isOk(). Failure sets isOk() to false.

Member Data Documentation

DtIpv4Addr DtTcpSocket::myConnectAddr
protected
int DtTcpSocket::myLocalPort
protected
int DtTcpSocket::myMaxForwarderQueue
protected

Max forwarder queue size.

int DtTcpSocket::myNeedSize
protected
int DtTcpSocket::myNumBytesReceived
protected
int DtTcpSocket::myNumBytesToWaitFor
protected
bool DtTcpSocket::myOk
protected
int DtTcpSocket::myPeerPort
protected
char* DtTcpSocket::myPktBuff
protected
unsigned int DtTcpSocket::myPktBuffSize
protected
DtList* DtTcpSocket::myPktWaitList
protected

List for saving un-sent packets.

Calling flush will attempt to empty this list.

int DtTcpSocket::mySizeLength
protected
int DtTcpSocket::mySizeOffset
protected
int DtTcpSocket::thePktBuffSize
staticprotected

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

Document ID: Generated on Fri May 15 06:36:13 EDT 2015 from SVN revision 153263
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)