ucc::TCPSocket Class Reference

A generic tcp socket class that offers i/o buffering. More...

#include <buffer.h>

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

Public Member Functions

void blocking (timeout_t timeout=Timer::inf)
 Set timeout interval and blocking.
void close (void)
 Close active connection.
void open (char *host, size_t size=536)
 Connect a tcp client session to a specific host uri.
void open (TCPServer *server, size_t size=536)
 Connect a tcp socket to a client from a listener.
bool pending (void)
 Check for pending tcp or ssl data.
 TCPSocket (char *service, char *host, size_t size=536)
 Construct a tcp client session connected to a specific host uri.
 TCPSocket (TCPServer *server, size_t size=536)
 Construct a tcp server session from a listening socket.
 TCPSocket (char *service)
 Construct an unconnected tcp client and specify our service profile.
virtual ~TCPSocket ()
 Destroy the tcp socket and release all resources.

Protected Member Functions

virtual size_t _pull (char *address, size_t size)
 Method to pull buffer from physical i/o (read).
virtual size_t _push (char *address, size_t size)
 Method to push buffer into physical i/o (write).
short getservice (void)
 Get the effective "service" port identifier of the socket.
socket_t getsocket (void)
 Get the low level socket object.
size_t peek (char *data, size_t size, timeout_t timeout=Timer::inf)
 Peek at socket input.
char * tag (void)
 Get the tag used for this socket.

Detailed Description

A generic tcp socket class that offers i/o buffering.

All user i/o operations are directly inherited from the IOBuffer base class public members. Some additional members are added for layering ssl services.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 493 of file buffer.h.


Constructor & Destructor Documentation

ucc::TCPSocket::TCPSocket ( char *  service  ) 

Construct an unconnected tcp client and specify our service profile.

Parameters:
service identifer, usually by name.
ucc::TCPSocket::TCPSocket ( TCPServer server,
size_t  size = 536 
)

Construct a tcp server session from a listening socket.

Parameters:
server socket we are created from.
size of buffer and tcp fragments.
ucc::TCPSocket::TCPSocket ( char *  service,
char *  host,
size_t  size = 536 
)

Construct a tcp client session connected to a specific host uri.

Parameters:
service identifier of our client.
host and optional :port we are connecting to.
size of buffer and tcp fragments.

Member Function Documentation

virtual size_t ucc::TCPSocket::_pull ( char *  address,
size_t  size 
) [protected, virtual]

Method to pull buffer from physical i/o (read).

The address is passed to this virtual since it is hidden as private.

Parameters:
address of buffer to pull data into.
size of buffer area being pulled..
Returns:
number of read written, 0 on error or end of data.

Reimplemented from ucc::IOBuffer.

Reimplemented in ucc::SSocket.

virtual size_t ucc::TCPSocket::_push ( char *  address,
size_t  size 
) [protected, virtual]

Method to push buffer into physical i/o (write).

The address is passed to this virtual since it is hidden as private.

Parameters:
address of data to push.
size of data to push.
Returns:
number of bytes written, 0 on error.

Reimplemented from ucc::IOBuffer.

Reimplemented in ucc::SSocket.

void ucc::TCPSocket::blocking ( timeout_t  timeout = Timer::inf  ) 

Set timeout interval and blocking.

Parameters:
timeout to use.
short ucc::TCPSocket::getservice ( void   )  [inline, protected]

Get the effective "service" port identifier of the socket.

If the socket was created from a listener, this will be the port number of the listening socket, and hence can be useful to determine which service connected and whether ssl is needed. If this is a client socket, it will be the service port of the peer socket.

Returns:
service identifier associated with the socket.

Definition at line 520 of file buffer.h.

socket_t ucc::TCPSocket::getsocket ( void   )  [inline, protected]

Get the low level socket object.

Returns:
socket we are using.

Definition at line 509 of file buffer.h.

void ucc::TCPSocket::open ( char *  host,
size_t  size = 536 
)

Connect a tcp client session to a specific host uri.

If the socket was already connected, it is automatically closed first.

Parameters:
host and optional :port we are connecting to.
size of buffer and tcp fragments.

Reimplemented in ucc::SSocket.

void ucc::TCPSocket::open ( TCPServer server,
size_t  size = 536 
)

Connect a tcp socket to a client from a listener.

If the socket was already connected, it is automatically closed first.

Parameters:
server we are connected from.
size of buffer and tcp fragments.

Reimplemented in ucc::SSocket.

size_t ucc::TCPSocket::peek ( char *  data,
size_t  size,
timeout_t  timeout = Timer::inf 
) [protected]

Peek at socket input.

This might be used to get a header at connection and to see if ssl/tls service is needed.

Parameters:
data buffer to store peek results.
size of data to peek.
timeout to wait for peek.
Returns:
number of bytes seen.
bool ucc::TCPSocket::pending ( void   )  [virtual]

Check for pending tcp or ssl data.

Returns:
true if data pending.

Reimplemented from ucc::IOBuffer.

Reimplemented in ucc::SSocket.

char* ucc::TCPSocket::tag ( void   )  [inline, protected]

Get the tag used for this socket.

Returns:
service tag associated with this socket.

Definition at line 527 of file buffer.h.


The documentation for this class was generated from the following file:
Generated by  doxygen 1.6.2-20100208