Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

Cabal::TCPSocket Class Reference

Encapsulates a TCP socket. More...

#include <cabal_tcpsocket.h>

Inheritance diagram for Cabal::TCPSocket:

Inheritance graph
[legend]
Collaboration diagram for Cabal::TCPSocket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TCPSocket (const long timeout=-1, const Address *local=0, const Address *remote=0) throw ( InitError )
 TCPSocket (const Address *local, const Address *remote=0) throw ( InitError )
 TCPSocket (const long timeout, const char *local_ip, const int port) throw ( InitError )
virtual bool close ()
 Closes the socket.

bool connect ()
 Conencects with a remote host.

bool connect (const Address &remote)
 Connect with a remote address.

bool connect (const char *ip_addr, const int port)
 Connects to a remote host.

int recvAll (void *buffer, const int len)
 Blocks until all the data is read.

int sendAll (const void *buffer, const int len)
 Blocks until all the data is sent.

std::string recvLine (const int maxCount=0)
 Blocks until a string terminated by CRLF is read.

int sendLine (const std::string &val)
int send (const std::string &val)
int sendLine (const char *data)
int sendString (const char *data)
bool continueOp ()
 Continue a previously timed out operation.


Protected Member Functions

virtual int rawRecv (void *data, const int len)
 Subclasses hook to receive data.

virtual int rawSend (const void *data, const int len)
 Subclasses hook to send data.


Protected Attributes

OpType m_opType
const void * m_buffer
int m_buflen
int m_bufdone

Detailed Description

Encapsulates a TCP socket.

This class encapsulates a TCPSocket; most notably, it is capable to connect with a remote server, and it is returned by Cabal::ServerSocket::accept() on client incoming.

Definition at line 27 of file cabal_tcpsocket.h.


Member Function Documentation

virtual bool Cabal::TCPSocket::close  )  [inline, virtual]
 

Closes the socket.

The other end of the connection is notified of the will of this side to stop transmissions. Then, the superclass method is called.

Returns:
true on success, false on failure.

Reimplemented from Cabal::Socket.

Definition at line 79 of file cabal_tcpsocket.h.

bool Cabal::TCPSocket::connect const char *  ip_addr,
const int  port
[inline]
 

Connects to a remote host.

This is an inline that builds an address and passes it to connect().

Parameters:
ip_addr a remote address in network format (ipv4 dot quad).
port a port number.
Returns:
true on success, false on error.

Definition at line 114 of file cabal_tcpsocket.h.

References connect(), and Cabal::Address::set().

bool Cabal::TCPSocket::connect const Address remote  )  [inline]
 

Connect with a remote address.

If the socket times out in the meanwhile, the connection can be continued with continueOp() until a connection is eshtablished or an error is returned.

Returns:
true on success, false on failure.

Definition at line 102 of file cabal_tcpsocket.h.

References connect().

bool Cabal::TCPSocket::connect  ) 
 

Conencects with a remote host.

The host must be set in the "remote" field of this socket prior to call this method, or the program will be aborted.

If the socket times out in the meanwhile, the connection can be continued with continueOp() until a connection is eshtablished or an error is returned.

Returns:
true on success, false on error.

Definition at line 18 of file ltlib/cabal_tcpsocket.cpp.

References Cabal::Address::address().

Referenced by connect().

bool Cabal::TCPSocket::continueOp  ) 
 

Continue a previously timed out operation.

Returns false on error.

Reimplemented from Cabal::Socket.

Definition at line 170 of file ltlib/cabal_tcpsocket.cpp.

virtual int Cabal::TCPSocket::rawRecv void *  data,
const int  len
[inline, protected, virtual]
 

Subclasses hook to receive data.

This is called by recv() method to allow subclasses to specialize the job. All the preparation and error handling part are done by recv(), subclasses just need to implement this abstract method.

Parameters:
data buffer of data be received.
len maximum length of received data (lenght of the buffer).
Returns:
amount of data received.

Implements Cabal::Socket.

Definition at line 37 of file cabal_tcpsocket.h.

virtual int Cabal::TCPSocket::rawSend const void *  data,
const int  len
[inline, protected, virtual]
 

Subclasses hook to send data.

This is called by send() method to allow subclasses to specialize the job. All the preparation and error handling part are done by send(), subclasses just need to implement this abstract method.

Parameters:
data buffer where to get the data to be sent.
len amount of data to be sent.
Returns:
amount of data received.

Implements Cabal::Socket.

Definition at line 42 of file cabal_tcpsocket.h.

Referenced by sendAll().

int Cabal::TCPSocket::recvAll void *  buffer,
const int  len
 

Blocks until all the data is read.

This function fills a given buffer with len bytes read from the socket. The function may return filling less than the requested amount of data if the socket times out; in this case, the return value is set to the amount of data read before the timeout has expired.

If all the data is read, then the returned value will equal the len parameter.

Parameters:
buffer the area where to store incoming data.
len the length of the buffer (and also the number of octects that must be read).
Returns:
the amount of data read before timeout has expired, or -1 on error.

Definition at line 150 of file ltlib/cabal_tcpsocket.cpp.

References Cabal::Socket::hasTimedOut(), and Cabal::Socket::recv().

int Cabal::TCPSocket::sendAll const void *  buffer,
const int  len
 

Blocks until all the data is sent.

This function will repeatedly send the data (when the network layer allows it) until all the data is finally sent, or until the timeout expires. In this case, the return value is set to the amount of data sent before the timeout has expired. If all the data is sent, then the returned value will equal the len parameter.

Parameters:
buffer the area where to store incoming data.
len the length of the buffer (and also the number of octects that must be read).
Returns:
the amount of data sent before timeout has expired, or -1 on error.

Definition at line 130 of file ltlib/cabal_tcpsocket.cpp.

References Cabal::Socket::hasTimedOut(), and rawSend().


The documentation for this class was generated from the following files:
Generated on Sat Apr 10 17:41:49 2004 for Cabal by doxygen 1.3.5