# SocketTCP Class Reference

This TCP socket implementation uses a Read Buffer to improve global read performances(by reducing Recv system calls). More...

`#include <SocketTCP.hh>`

Inheritance diagram for SocketTCP:

[legend]

List of all members.

## Public Member Functions
| SocketTCP ()
virtual | ~SocketTCP ()
virtual void | close ()
virtual void | createConnection (const char *server_name, unsigned int port) throw (NetworkError)
void | createTCPClient (in_port_t port, in_addr_t addr) throw (NetworkError)
void | createTCPServer (in_port_t port=0, in_addr_t addr=INADDR_ANY) throw (NetworkError)
int | accept (SocketTCP *serveur) throw (NetworkError)
virtual void | send (const unsigned char *, size_t) throw (NetworkError, NetworkSignal)
virtual void | receive (void *Buffer, unsigned long Size) throw (NetworkError, NetworkSignal)
virtual bool | isDataReady () const
virtual unsigned long | returnAdress () const
SocketTCP & | operator= (SocketTCP &theSocket)
virtual int | returnSocket ()
## Protected Member Functions
int | timeoutTCP (int, int)
| Wait for a socket event, until a time-out.
## Protected Attributes
ByteCount_t | SentBytesCount
ByteCount_t | RcvdBytesCount
## Private Member Functions
int | open ()
int | connect (in_port_t port, in_addr_t addr)
int | listen (unsigned long howMuch=5)
int | bind (in_port_t port=0, in_addr_t addr=INADDR_ANY)
void | setPort (in_port_t port)
| Change the port value.
in_port_t | getPort () const
in_addr_t | getAddr () const
## Private Attributes
long | _socket_tcp
bool | _est_init_tcp
struct sockaddr_in | _sockIn

## Detailed Description

This TCP socket implementation uses a Read Buffer to improve global read performances(by reducing Recv system calls).

An important drawback of this improvement is that a socket can be marked as empty for the system, but in fact there is data waiting in the read buffer. This is especially a problem for processes using the 'select' system call: the socket won't be marked as ready for reading, because all data has already been read, and is waiting in the internal buffer. Therefore, before returning to a select loop, be sure to call the IsDataReady method to check whether any data is waiting for processing.

Definition at line 48 of file SocketTCP.hh.

## Constructor & Destructor Documentation

SocketTCP | ( |  | ) |

Definition at line 96 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, SocketTCP::RcvdBytesCount, and SocketTCP::SentBytesCount.

~SocketTCP | ( |  | ) | `[virtual]`

Definition at line 113 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, SocketTCP::_socket_tcp, SocketTCP::close(), SocketTCP::RcvdBytesCount, and SocketTCP::SentBytesCount.

Here is the call graph for this function:

## Member Function Documentation

void close | ( |  | ) | `[virtual]`

Implements Socket.

Definition at line 402 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, and SocketTCP::_socket_tcp.

Referenced by SocketServer::close(), Communications::~Communications(), RTIG::~RTIG(), SocketTCP::~SocketTCP(), and SocketTuple::~SocketTuple().

void createConnection | ( | const char * | server_name,
|  | unsigned int | port |
| ) |  |  | throw (NetworkError)`[virtual]`

Implements Socket.

Reimplemented in SocketHTTPProxy.

Definition at line 264 of file SocketTCP.cc.

References SocketTCP::createTCPClient().

Referenced by Communications::Communications(), and SocketHTTPProxy::createConnection().

Here is the call graph for this function:

void createTCPClient | ( | in_port_t | port,
|  | in_addr_t | addr |
| ) |  |  | throw (NetworkError)

Definition at line 289 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, Socket::addr2string(), SocketTCP::connect(), and SocketTCP::open().

Referenced by SocketTCP::createConnection().

Here is the call graph for this function:

void createTCPServer | ( | in_port_t | port = `0`,
|  | in_addr_t | addr = `INADDR_ANY` |
| ) |  |  | throw (NetworkError)

Definition at line 315 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, Socket::addr2string(), SocketTCP::bind(), SocketTCP::listen(), certi::MAX_BACKLOG, and SocketTCP::open().

Referenced by RTIG::execute().

Here is the call graph for this function:

int accept | ( | SocketTCP * | serveur | ) | throw (NetworkError)

Definition at line 181 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, SocketTCP::_socket_tcp, and SocketTCP::_sockIn.

Referenced by SocketServer::open().

void send | ( | const unsigned char * | buffer,
|  | size_t | size |
| ) |  |  | throw (NetworkError, NetworkSignal)`[virtual]`

Implements Socket.

Reimplemented in SecureTCPSocket.

Definition at line 352 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, SocketTCP::_socket_tcp, certi::D, PrettyDebug::Out(), pdDebug, pdExcept, pdTrace, and SocketTCP::SentBytesCount.

Referenced by SecureTCPSocket::send(), and SocketHTTPProxy::sendHTTPConnect().

Here is the call graph for this function:

void receive | ( | void * | Buffer,
|  | unsigned long | Size |
| ) |  |  | throw (NetworkError, NetworkSignal)`[virtual]`

Implements Socket.

Reimplemented in SecureTCPSocket.

Definition at line 475 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, SocketTCP::_socket_tcp, certi::D, PrettyDebug::Out(), pdDebug, pdExcept, pdTrace, and SocketTCP::RcvdBytesCount.

Referenced by SecureTCPSocket::receive().

Here is the call graph for this function:

bool isDataReady | ( |  | ) | const`[virtual]`

Return RTI_TRUE if any data as already been read from the system socket and is waiting in the internal buffer, else RTI_FALSE.

Implements Socket.

Reimplemented in SecureTCPSocket.

Definition at line 443 of file SocketTCP.cc.

Referenced by SecureTCPSocket::isDataReady(), and Communications::readMessage().

unsigned long returnAdress | ( |  | ) | const`[virtual]`

Implements Socket.

Definition at line 540 of file SocketTCP.cc.

References SocketTCP::getAddr().

Here is the call graph for this function:

SocketTCP & operator= | ( | SocketTCP & | theSocket | ) |

Definition at line 464 of file SocketTCP.cc.

References SocketTCP::_socket_tcp, SocketTCP::_sockIn, SocketTCP::getAddr(), SocketTCP::getPort(), and SocketTCP::returnSocket().

Here is the call graph for this function:

int returnSocket | ( |  | ) | `[virtual]`

Implements Socket.

Definition at line 549 of file SocketTCP.cc.

References SocketTCP::_socket_tcp.

Referenced by RTIG::execute(), SocketTCP::operator=(), Communications::readMessage(), and SocketHTTPProxy::receiveLine().

int timeoutTCP | ( | int | sec,
|  | int | usec |
| ) |  |  | `[protected]`

Wait for a socket event, until a time-out.

The time-out is given with seconds and microseconds in parameter.

Parameters:

  | sec | seconds
  | usec | microseconds

Returns:
  1 if there are waiting events, 0 if the wait timed out

Exceptions:

  | NetworkSignal | and NetworkError

Definition at line 568 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, and SocketTCP::_socket_tcp.

Referenced by SocketHTTPProxy::sendHTTPConnect().

int open | ( |  | ) | `[private]`

Definition at line 454 of file SocketTCP.cc.

References SocketTCP::_socket_tcp.

Referenced by SocketTCP::createTCPClient(), and SocketTCP::createTCPServer().

int connect | ( | in_port_t | port,
|  | in_addr_t | addr |
| ) |  |  | `[private]`

Definition at line 137 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, SocketTCP::_socket_tcp, and SocketTCP::_sockIn.

Referenced by SocketTCP::createTCPClient().

int listen | ( | unsigned long | howMuch = `5` | ) | `[private]`

Definition at line 417 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, and SocketTCP::_socket_tcp.

Referenced by SocketTCP::createTCPServer().

int bind | ( | in_port_t | port = `0`,
|  | in_addr_t | addr = `INADDR_ANY` |
| ) |  |  | `[private]`

Definition at line 231 of file SocketTCP.cc.

References SocketTCP::_est_init_tcp, SocketTCP::_socket_tcp, and SocketTCP::_sockIn.

Referenced by SocketTCP::createTCPServer().

void setPort | ( | in_port_t | port | ) | `[private]`

Change the port value.

Definition at line 554 of file SocketTCP.cc.

References SocketTCP::_sockIn.

in_port_t getPort | ( |  | ) | const`[private]`

Definition at line 433 of file SocketTCP.cc.

References SocketTCP::_sockIn.

Referenced by SocketTCP::operator=().

in_addr_t getAddr | ( |  | ) | const`[private]`

Definition at line 426 of file SocketTCP.cc.

References SocketTCP::_sockIn.

Referenced by SocketTCP::operator=(), and SocketTCP::returnAdress().

## Member Data Documentation

ByteCount_t SentBytesCount`[protected]`

Definition at line 82 of file SocketTCP.hh.

Referenced by SocketTCP::send(), SocketTCP::SocketTCP(), and SocketTCP::~SocketTCP().

ByteCount_t RcvdBytesCount`[protected]`

Definition at line 83 of file SocketTCP.hh.

Referenced by SocketTCP::receive(), SocketHTTPProxy::receiveLine(), SocketTCP::SocketTCP(), and SocketTCP::~SocketTCP().

long _socket_tcp`[private]`

Definition at line 98 of file SocketTCP.hh.

Referenced by SocketTCP::accept(), SocketTCP::bind(), SocketTCP::close(), SocketTCP::connect(), SocketTCP::listen(), SocketTCP::open(), SocketTCP::operator=(), SocketTCP::receive(), SocketTCP::returnSocket(), SocketTCP::send(), SocketTCP::timeoutTCP(), and SocketTCP::~SocketTCP().

bool _est_init_tcp`[private]`

Definition at line 100 of file SocketTCP.hh.

Referenced by SocketTCP::accept(), SocketTCP::bind(), SocketTCP::close(), SocketTCP::connect(), SocketTCP::createTCPClient(), SocketTCP::createTCPServer(), SocketTCP::listen(), SocketTCP::receive(), SocketTCP::send(), SocketTCP::SocketTCP(), SocketTCP::timeoutTCP(), and SocketTCP::~SocketTCP().

struct sockaddr_in _sockIn`[read, private]`

Definition at line 101 of file SocketTCP.hh.

Referenced by SocketTCP::accept(), SocketTCP::bind(), SocketTCP::connect(), SocketTCP::getAddr(), SocketTCP::getPort(), SocketTCP::operator=(), and SocketTCP::setPort().

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

- SocketTCP.hh
- SocketTCP.cc