AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
agxNet::TCPSocket Class Reference

#include <Socket.h>

+ Inheritance diagram for agxNet::TCPSocket:

Public Member Functions

 TCPSocket ()
 Constructs an invalid TCP socket object. More...
 
 TCPSocket (const TCPSocket &s, const IPAddress &adr=IPAddress())
 A copy constructor. More...
 
 TCPSocket (const IPAddress &ip, bool disableNaggle=false)
 A constructor which automatically calls TCPSocket::Open() method. More...
 
const IPAddress & adr () const
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
void close ()
 Closes the socket disconnecting it if necessary. More...
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
bool isBlocking () const
 
bool isReady () const
 Tells whether there is some activity on the socket or not. More...
 
bool isValid () const
 Tells whether the socket is opened or not. More...
 
void open (const IPAddress &ip, bool disableNaggle=false)
 Connects the socket. More...
 
TCPSocket & operator= (const TCPSocket &s)
 Assignment operator, works similar to std::auto_ptr::operator=(). More...
 
bool readyToReceive () const
 
bool readyToSend () const
 
size_t recv (agx::UInt8 *buf, size_t maxSize)
 Receive data from connected socket. More...
 
void recvBlocking (agx::UInt8 *buf, agx::UInt32 size)
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void select (agx::UInt32 timeoutMillis=0)
 
agx::UInt32 send (const agx::UInt8 *data, agx::UInt32 size)
 Send data to connected socket. More...
 
void sendBlocking (const agx::UInt8 *data, agx::UInt32 size)
 
void sendBlocking (const StructuredMessage *message)
 
void setBlocking (bool flag)
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 

Static Public Member Functions

template<typename T >
static bool ValidateCast (const Referenced *object)
 

Protected Member Functions

void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 

Static Protected Member Functions

static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 

Protected Attributes

IPAddress m_adr
 
bool m_blocking
 
Mutex m_mutex
 
ObserverContainer m_observers
 
bool m_readyToReceive
 
bool m_readyToSend
 
AtomicValue m_refCount
 
SystemIndependentSocketHandle m_socket
 

Detailed Description

Definition at line 319 of file Socket.h.

Constructor & Destructor Documentation

agxNet::TCPSocket::TCPSocket ( )
inline

Constructs an invalid TCP socket object.

Definition at line 325 of file Socket.h.

agxNet::TCPSocket::TCPSocket ( const TCPSocket &  s,
const IPAddress &  adr = IPAddress() 
)
inline

A copy constructor.

Copy constructor creates a new socket object which refers to the same socket as s. After constructor completes the s becomes invalid. In other words, the behavior of copy constructor is similar to one of std::auto_ptr class from standard C++ library.

Parameters
s- other TCP socket to make a copy from.

Definition at line 335 of file Socket.h.

agxNet::TCPSocket::TCPSocket ( const IPAddress &  ip,
bool  disableNaggle = false 
)
inline

A constructor which automatically calls TCPSocket::Open() method.

This constructor creates a socket and calls its TCPSocket::Open() method. So, it creates an already opened socket.

Parameters
ip- IP address to 'connect to/listen on'.
disableNaggle- enable/disable Naggle algorithm.

Definition at line 347 of file Socket.h.

Member Function Documentation

const IPAddress& agxNet::Socket::adr ( ) const
inlineinherited

Definition at line 285 of file Socket.h.

void agx::Referenced::allocateObserverVector ( ) const
protectedinherited
template<typename T >
T* agx::Referenced::as ( )
inherited

Subclass casting.

Template type must match actual type, dynamic_cast assertion will fail otherwise.

Referenced by agx::InternalData::get(), agxVehicle::Track::getNode(), and agx::InternalData::getOrCreate().

template<typename T >
const T* agx::Referenced::as ( ) const
inherited
template<typename T >
T* agx::Referenced::asSafe ( )
inherited

Safe subclass casting, return nullptr if template type does not match.

Referenced by agxUtil::CollectBodiesAndWiresVisitor::visit().

template<typename T >
const T* agx::Referenced::asSafe ( ) const
inherited
void agxNet::Socket::close ( )
inherited

Closes the socket disconnecting it if necessary.

void agx::Referenced::deleteUsingDeleteHandler ( ) const
protectedinherited
static DeleteHandler* agx::Referenced::getDeleteHandler ( )
staticprotectedinherited
Returns
a DeleteHandler.
int agx::Referenced::getReferenceCount ( ) const
inherited
Returns
the number pointers currently referencing this object.
template<typename T >
bool agx::Referenced::is ( ) const
inherited
bool agxNet::Socket::isBlocking ( ) const
inlineinherited

Definition at line 258 of file Socket.h.

bool agxNet::Socket::isReady ( ) const
inlineinherited

Tells whether there is some activity on the socket or not.

See SocketSet class description for more info on how to use this method properly.

Returns
  • true if there is some data to read on the socket or if the remote socket has disconnected. The latter case can be detected by checking if subsequent Recv() method returns 0.
  • false if there is no any activity on the socket.

Definition at line 268 of file Socket.h.

bool agxNet::Socket::isValid ( ) const
inherited

Tells whether the socket is opened or not.

TODO: write some detailed description.

Returns
Returns true if the socket is opened or false otherwise.
void agxNet::TCPSocket::open ( const IPAddress &  ip,
bool  disableNaggle = false 
)

Connects the socket.

This method connects the socket to remote TCP server socket.

Parameters
ip- IP address.
disableNaggle- enable/disable Naggle algorithm.
TCPSocket& agxNet::TCPSocket::operator= ( const TCPSocket &  s)
inline

Assignment operator, works similar to std::auto_ptr::operator=().

After this assignment operator completes this socket object refers to the socket the s object referred, s become invalid. It works similar to std::auto_ptr::operator=() from standard C++ library.

Parameters
s- socket to assign from.

Definition at line 357 of file Socket.h.

References agxNet::Socket::operator=().

bool agxNet::Socket::readyToReceive ( ) const
inlineinherited

Definition at line 275 of file Socket.h.

bool agxNet::Socket::readyToSend ( ) const
inlineinherited

Definition at line 280 of file Socket.h.

size_t agxNet::TCPSocket::recv ( agx::UInt8 *  buf,
size_t  maxSize 
)

Receive data from connected socket.

Receives data available on the socket. If there is no data available this function blocks until some data arrives.

Parameters
buf- pointer to the buffer where to put received data.
maxSize- maximal number of bytes which can be put to the buffer.
Returns
if returned value is not 0 then it represents the number of bytes written to the buffer.
0 returned value indicates disconnection of remote socket.
void agxNet::TCPSocket::recvBlocking ( agx::UInt8 *  buf,
agx::UInt32  size 
)
void agx::Referenced::reference ( void *  ptr = nullptr) const
inherited

Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.

This method should be used with care, always balanced with the same number of calls to unreference.

Referenced by agxData::Val< UInt >::Val().

void agxNet::Socket::select ( agx::UInt32  timeoutMillis = 0)
inherited
agx::UInt32 agxNet::TCPSocket::send ( const agx::UInt8 *  data,
agx::UInt32  size 
)

Send data to connected socket.

Sends data on connected socket. This method blocks until all data is completely sent.

Parameters
data- pointer to the buffer with data to send.
size- number of bytes to send.
Returns
the number of bytes sent. Note that this value should normally be equal to the size argument value.
void agxNet::TCPSocket::sendBlocking ( const agx::UInt8 *  data,
agx::UInt32  size 
)
void agxNet::TCPSocket::sendBlocking ( const StructuredMessage *  message)
void agxNet::Socket::setBlocking ( bool  flag)
inherited
static void agx::Referenced::setDeleteHandler ( DeleteHandler *  handler)
staticprotectedinherited

Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.

void agx::Referenced::unreference ( void *  ptr = nullptr) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.

This method should be used with care, always balanced with the same number of calls to reference.

void agx::Referenced::unreference_nodelete ( ) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be responsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks.

template<typename T >
static bool agx::Referenced::ValidateCast ( const Referenced *  object)
staticinherited

Member Data Documentation

IPAddress agxNet::Socket::m_adr
protectedinherited

Definition at line 308 of file Socket.h.

bool agxNet::Socket::m_blocking
protectedinherited

Definition at line 307 of file Socket.h.

Mutex agx::Referenced::m_mutex
mutableprotectedinherited

Definition at line 240 of file Referenced.h.

ObserverContainer agx::Referenced::m_observers
mutableprotectedinherited

Definition at line 239 of file Referenced.h.

bool agxNet::Socket::m_readyToReceive
protectedinherited

Definition at line 305 of file Socket.h.

bool agxNet::Socket::m_readyToSend
protectedinherited

Definition at line 306 of file Socket.h.

AtomicValue agx::Referenced::m_refCount
mutableprotectedinherited

Definition at line 241 of file Referenced.h.

SystemIndependentSocketHandle agxNet::Socket::m_socket
protectedinherited

Definition at line 310 of file Socket.h.


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