S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_socket_tcp Class Reference

#include <s3_socket_tcp.h>

Inheritance diagram for s3_socket_tcp:

Inheritance graph
[legend]
List of all members.

Public Methods

 s3_socket_tcp (int newsock=INVALID_SOCKET, bool new_set_reuseaddr=true) throw (s3_generic_exception)
 Construct a new socket. More...

 s3_socket_tcp (const s3_socket_tcp &template_sock) throw (s3_generic_exception)
 Copy construct a new socket. More...

virtual ~s3_socket_tcp ()
bool bind (in_addr_t addr, in_port_t port)
 Bind the socket to local addr:port. More...

bool listen (int backlog)
 Put the socket in listen mode. More...

bool accept (s3_socket_tcp &newsock, sockaddr_in *clientname=0)
 Accept a connection on the socket. More...

bool connect (const std::string &IP_address, in_port_t port)
 Connect the socket to addr:port. More...

bool close (bool reinit=true) throw (s3_generic_exception)
 Close the socket. More...

std::string get_error () const
 Returns a string describing the most recent error. More...

int get_errno () const
 Returns the error number of the most recent error. More...

int get_h_errno () const
 Returns the error number of the most recent host error. More...

bool is_closed () const
 Returns whether the socket is closed. More...

bool is_valid () const
 Returns whether the socket is valid. More...

virtual bool read (void *data, int size, s3_semaphore *term=0)
 Reads data from socket in non-blocking mode, and is guaranteed to wait until all the data (as indicated by size) has been read from the socket. More...

virtual bool write (void *data, int size, int max_packet=-1, s3_semaphore *term=0)
 Writes data to a connect()ed socket, optionally limiting packet size to some reasonable value. More...

int select_rd (int timeout=1)
 Wait for socket to become readable. More...

int select_wr (int timeout=1)
 Wait for socket to become writeable or time out. More...


Protected Methods

void set_errnos (int new_errno=0, int new_h_errno=0)
void change_socket (int newsock)

Protected Attributes

bool set_reuseaddr
int sock
int my_errno
int my_h_errno

Private Methods

bool initialize ()

Friends

bool accept (s3_socket_tcp &newsock, sockaddr_in *clientname)
 allows accept to access newsock.change_socket(). More...


Constructor & Destructor Documentation

s3_socket_tcp::s3_socket_tcp int    newsock = INVALID_SOCKET,
bool    new_set_reuseaddr = true
throw (s3_generic_exception)
 

Construct a new socket.

Definition at line 41 of file s3_socket_tcp.cc.

References INVALID_SOCKET.

s3_socket_tcp::s3_socket_tcp const s3_socket_tcp &    template_sock throw (s3_generic_exception)
 

Copy construct a new socket.

Definition at line 59 of file s3_socket_tcp.cc.

s3_socket_tcp::~s3_socket_tcp   [virtual]
 

Definition at line 70 of file s3_socket_tcp.cc.

References close.


Member Function Documentation

bool s3_socket_tcp::accept s3_socket_tcp &    newsock,
sockaddr_in *    clientname = 0
 

Accept a connection on the socket.

Definition at line 145 of file s3_socket_tcp.cc.

References change_socket, S3FC_DBG2_, S3FC_DBG_, set_errnos, and sock.

Referenced by s3_socket_tcp_ssl::accept.

bool s3_socket_tcp::bind in_addr_t    addr,
in_port_t    port
 

Bind the socket to local addr:port.

Definition at line 113 of file s3_socket_tcp.cc.

References S3FC_DBG2_, S3FC_DBG_, set_errnos, and sock.

void s3_socket_tcp::change_socket int    newsock [protected]
 

Definition at line 107 of file s3_socket_tcp.cc.

References close, and sock.

Referenced by accept.

bool s3_socket_tcp::close bool    reinit = true throw (s3_generic_exception)
 

Close the socket.

Reimplemented in s3_socket_tcp_ssl.

Definition at line 205 of file s3_socket_tcp.cc.

References INVALID_SOCKET, S3FC_DBG2_, and S3FC_DBG_.

Referenced by change_socket, s3_socket_tcp_ssl::close, and ~s3_socket_tcp.

bool s3_socket_tcp::connect const std::string &    IP_address,
in_port_t    port
 

Connect the socket to addr:port.

Reimplemented in s3_socket_tcp_ssl.

Definition at line 168 of file s3_socket_tcp.cc.

References S3FC_DBG2_, S3FC_DBG_, set_errnos, and sock.

Referenced by s3_socket_tcp_ssl::connect.

int s3_socket_tcp::get_errno   const [inline]
 

Returns the error number of the most recent error.

Definition at line 100 of file s3_socket_tcp.h.

References my_errno.

std::string s3_socket_tcp::get_error   const
 

Returns a string describing the most recent error.

Reimplemented in s3_socket_tcp_ssl.

Definition at line 236 of file s3_socket_tcp.cc.

References my_errno, my_h_errno, S3FC_DBG2_, and S3FC_DBG_.

Referenced by s3_socket_tcp_ssl::get_error.

int s3_socket_tcp::get_h_errno   const [inline]
 

Returns the error number of the most recent host error.

Definition at line 106 of file s3_socket_tcp.h.

References my_h_errno.

bool s3_socket_tcp::initialize   [private]
 

Definition at line 75 of file s3_socket_tcp.cc.

References INVALID_SOCKET, S3FC_DBG2_, set_errnos, and sock.

bool s3_socket_tcp::is_closed   const [inline]
 

Returns whether the socket is closed.

Definition at line 112 of file s3_socket_tcp.h.

References sock.

bool s3_socket_tcp::is_valid   const [inline]
 

Returns whether the socket is valid.

Definition at line 118 of file s3_socket_tcp.h.

References INVALID_SOCKET, and sock.

bool s3_socket_tcp::listen int    backlog
 

Put the socket in listen mode.

Definition at line 131 of file s3_socket_tcp.cc.

References S3FC_DBG2_, S3FC_DBG_, set_errnos, and sock.

bool s3_socket_tcp::read void *    data,
int    size,
s3_semaphore   term = 0
[virtual]
 

Reads data from socket in non-blocking mode, and is guaranteed to wait until all the data (as indicated by size) has been read from the socket.

It calls s3_thread_base::test_cancel() in the loop to ensure that this call will not block the thread termination process.

Parameters:
data  A pointer to the data buffer to write to
size  The number of bytes to read
term  A pointer to a semaphore that, when posted, indicates that the subroutine must return immidiately with -1 as a return value
Returns:
true if all is well, false otherwise

Reimplemented in s3_socket_tcp_ssl.

Definition at line 280 of file s3_socket_tcp.cc.

References S3FC_DBG2_, select_rd, set_errnos, sock, s3_thread_base::test_cancel, and s3_semaphore::try_wait.

int s3_socket_tcp::select_rd int    timeout = 1
 

Wait for socket to become readable.

This function returns true if something is waiting to be read at the socket using select(2). It returns true if there is something in the receive buffer (i.e. a recv will return a positive number). If it times out, or if there is nothing in the buffer, it returns false.

Parameters:
timeout  Delay in seconds before select(2) times out.
Returns:
1 if socket is available for writing, 0 if a timeout occurred or -1 if an error occured (get_errno() will return the error.

Definition at line 468 of file s3_socket_tcp.cc.

References set_errnos, and sock.

Referenced by s3_socket_tcp_ssl::read, and read.

int s3_socket_tcp::select_wr int    timeout = 1
 

Wait for socket to become writeable or time out.

This function returns true if the socket is writeable using select(2). It returns true if there is enough space in the send buffer (i.e. a send(2) will return a positive number). If it times out, or if the buffer is full, it returns false.

Parameters:
timeout  Delay in seconds before select(2) times out.
Returns:
1 if socket is available for reading, 0 if a timeout occurred or -1 if an error occured (get_errno() will return the error.

Definition at line 499 of file s3_socket_tcp.cc.

References set_errnos, and sock.

Referenced by s3_socket_tcp_ssl::write, and write.

void s3_socket_tcp::set_errnos int    new_errno = 0,
int    new_h_errno = 0
[protected]
 

Definition at line 101 of file s3_socket_tcp.cc.

References my_errno, and my_h_errno.

Referenced by accept, bind, connect, initialize, listen, s3_socket_tcp_ssl::read, read, select_rd, select_wr, s3_socket_tcp_ssl::set_errnos, s3_socket_tcp_ssl::write, and write.

bool s3_socket_tcp::write void *    data,
int    size,
int    max_packet = -1,
s3_semaphore   term = 0
[virtual]
 

Writes data to a connect()ed socket, optionally limiting packet size to some reasonable value.

It calls s3_thread_base::test_cancel() in the loop to ensure that this call will not block the thread termination process.

Parameters:
data  A pointer to the data buffer to read from
size  The number of bytes to write
max_packet  Limit the size of the packet to this. If max_packet is -1, then no limits are placed.
term  A pointer to a semaphore that, when posted, indicates that the subroutine must return immidiately with -1 as a return value
Returns:
true if all is well, false otherwise

Reimplemented in s3_socket_tcp_ssl.

Definition at line 390 of file s3_socket_tcp.cc.

References S3FC_DBG_, select_wr, set_errnos, sock, s3_thread_base::test_cancel, and s3_semaphore::try_wait.


Friends And Related Function Documentation

bool accept s3_socket_tcp &    newsock,
sockaddr_in *    clientname
[friend]
 

allows accept to access newsock.change_socket().


Member Data Documentation

int s3_socket_tcp::my_errno [protected]
 

Definition at line 67 of file s3_socket_tcp.h.

Referenced by get_errno, get_error, and set_errnos.

int s3_socket_tcp::my_h_errno [protected]
 

Definition at line 67 of file s3_socket_tcp.h.

Referenced by get_error, get_h_errno, and set_errnos.

bool s3_socket_tcp::set_reuseaddr [protected]
 

Definition at line 66 of file s3_socket_tcp.h.

int s3_socket_tcp::sock [protected]
 

Definition at line 67 of file s3_socket_tcp.h.

Referenced by accept, bind, change_socket, connect, initialize, is_closed, is_valid, listen, read, select_rd, select_wr, s3_socket_tcp_ssl::setup_ssl, and write.


The documentation for this class was generated from the following files:
Send comments to: s3fc@stonethree.com SourceForge Logo