Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TCP_sock Class Reference

#include <TCP_sock.H>

List of all members.

Public Types

enum  {
  wrong_state = -1, internal_trouble = -2, environment_problem = -3, unknown_host = -4,
  unknown_port = -5, invalid_parameter = -6, partner_went_away = -7, read_timeout = -8,
  end_of_file = partner_went_away
}
enum  { default_sndbuffer_size = 8192, default_rcvbuffer_size = 8192 }

Public Member Functions

 TCP_sock (u_short port=0) throw (failure)
 ~TCP_sock () throw (failure)
void set_output_buffer_size (int bytes=default_sndbuffer_size) throw (failure)
void set_input_buffer_size (int bytes=default_rcvbuffer_size) throw (failure)
void enable_alerts () throw (failure)
void disable_alerts () throw (failure)
void alert () throw (failure)
bool test_alert () throw (failure)
void set_keepalive (bool state) throw (failure)
void enable_keepalive () throw (failure)
void disable_keepalive () throw (failure)
bool get_keepalive () throw (failure)
void enable_read_timeout (unsigned int seconds) throw (failure)
void disable_read_timeout () throw (failure)
bool get_read_timeout (unsigned int &seconds) throw ()
void get_local_addr (sockaddr_in &addr) throw (failure)
void get_remote_addr (sockaddr_in &addr) throw (failure)
bool alive () throw (failure)
fd_t get_fd () throw ()
void connect_to (const Text &hostname, const Text &port) throw (failure)
void connect_to (const Text &host_and_port) throw (failure)
void connect_to (sockaddr_in &addr) throw (failure)
void set_waiters (int waiters=1) throw (failure)
TCP_sockwait_for_connect () throw (alerted, failure)
void send_data (const char *buffer, int len, bool flush=false) throw (failure)
void flush () throw (failure)
int recv_data (char *buffer, int len) throw (alerted, failure)

Static Public Member Functions

static Text this_host () throw (failure)
static u_short parse_port (const Text &port) throw (failure)
static in_addr host_to_addr (const Text &hostname) throw (failure)
static void name_to_sockaddr (const Text &hostname, const Text &port, sockaddr_in &s) throw (failure)
static void name_to_sockaddr (const Text &host_and_port, sockaddr_in &s) throw (failure)

Private Types

enum  sock_state { fresh, listening, connected, dead }

Private Member Functions

 TCP_sock (TCP_sock &)
void operator= (TCP_sock &)
 TCP_sock (const empty_sock_marker &) throw (TCP_sock::failure)
void new_socket (u_short port) throw (failure)
void instance_init () throw ()
void ensure_state (sock_state should_be) throw (failure)
void ensure_sndbuffer () throw ()
void ensure_rcvbuffer () throw ()
void configure_blocking () throw (failure)
void controlled_wait () throw (alerted, failure)
int fill_rcvbuffer () throw (alerted, failure)

Static Private Member Functions

static void init () throw (failure)
static void ensure_init () throw (failure)
static void set_no_delay (int fd) throw (failure)

Private Attributes

Basics::mutex m
sock_state state
sockaddr_in me
sockaddr_in him
fd_t fd
char * sndbuff
int sndbuff_len
int sndbuff_size
char * rcvbuff
char * rcvcurp
char * rcvend
int rcvbuff_size
bool non_blocking
bool alerts_enabled
bool alert_flag
fd_t pipe_wr
fd_t pipe_rd
int bytes_in_pipe
bool read_timeout_enabled
unsigned int read_timeout_secs

Static Private Attributes

static pthread_once_t init_block = PTHREAD_ONCE_INIT
static Text my_hostname
static sockaddr_in defaultsock
static in_addr self_addr
static int tcp_protolevel

Friends

void TCP_sock_init ()

Classes

struct  alerted
struct  empty_sock_marker
struct  failure


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
wrong_state 
internal_trouble 
environment_problem 
unknown_host 
unknown_port 
invalid_parameter 
partner_went_away 
read_timeout 
end_of_file 

Definition at line 44 of file TCP_sock.H.

anonymous enum
 

Enumeration values:
default_sndbuffer_size 
default_rcvbuffer_size 

Definition at line 83 of file TCP_sock.H.

enum TCP_sock::sock_state [private]
 

Enumeration values:
fresh 
listening 
connected 
dead 

Definition at line 274 of file TCP_sock.H.


Constructor & Destructor Documentation

TCP_sock::TCP_sock u_short  port = 0  )  throw (failure)
 

Definition at line 371 of file TCP_sock.C.

References ensure_init().

TCP_sock::~TCP_sock  )  throw (failure)
 

Definition at line 475 of file TCP_sock.C.

References alerts_enabled, internal_trouble, rcvbuff, sndbuff, and SYSERROR.

TCP_sock::TCP_sock TCP_sock  )  [private]
 

TCP_sock::TCP_sock const empty_sock_marker  )  throw (TCP_sock::failure) [private]
 

Definition at line 378 of file TCP_sock.C.

References ensure_init(), and SYSERROR.


Member Function Documentation

void TCP_sock::alert  )  throw (failure)
 

Definition at line 565 of file TCP_sock.C.

References alert_flag, bytes_in_pipe, internal_trouble, SYSERROR, and wrong_state.

bool TCP_sock::alive  )  throw (failure)
 

Definition at line 690 of file TCP_sock.C.

References dead, fd, internal_trouble, state, and SYSERROR.

void TCP_sock::configure_blocking  )  throw (failure) [private]
 

Definition at line 150 of file TCP_sock.C.

References alerts_enabled, internal_trouble, non_blocking, read_timeout_enabled, and SYSERROR.

Referenced by disable_alerts(), disable_read_timeout(), and enable_alerts().

void TCP_sock::connect_to sockaddr_in &  addr  )  throw (failure)
 

Definition at line 1126 of file TCP_sock.C.

References connected, dead, fresh, inet_ntoa_r(), internal_trouble, invalid_parameter, unknown_host, and unknown_port.

void TCP_sock::connect_to const Text host_and_port  )  throw (failure)
 

Definition at line 1116 of file TCP_sock.C.

References dead, and name_to_sockaddr().

void TCP_sock::connect_to const Text hostname,
const Text port
throw (failure)
 

Definition at line 1106 of file TCP_sock.C.

References dead, and name_to_sockaddr().

void TCP_sock::controlled_wait  )  throw (alerted, failure) [private]
 

Definition at line 163 of file TCP_sock.C.

References alert_flag, alerts_enabled, bytes_in_pipe, dead, fd, internal_trouble, pipe_rd, read_timeout, read_timeout_enabled, read_timeout_secs, state, and SYSERROR.

Referenced by fill_rcvbuffer(), and wait_for_connect().

void TCP_sock::disable_alerts  )  throw (failure)
 

Definition at line 549 of file TCP_sock.C.

References alerts_enabled, configure_blocking(), and internal_trouble.

void TCP_sock::disable_keepalive  )  throw (failure) [inline]
 

Definition at line 118 of file TCP_sock.H.

References set_keepalive().

void TCP_sock::disable_read_timeout  )  throw (failure)
 

Definition at line 645 of file TCP_sock.C.

References configure_blocking(), and read_timeout_enabled.

void TCP_sock::enable_alerts  )  throw (failure)
 

Definition at line 527 of file TCP_sock.C.

References alert_flag, alerts_enabled, bytes_in_pipe, configure_blocking(), environment_problem, internal_trouble, pipe_rd, pipe_wr, and SYSERROR.

Referenced by Tool_Relay::body().

void TCP_sock::enable_keepalive  )  throw (failure) [inline]
 

Definition at line 116 of file TCP_sock.H.

References set_keepalive().

Referenced by SRPC_listener::create().

void TCP_sock::enable_read_timeout unsigned int  seconds  )  throw (failure)
 

Definition at line 634 of file TCP_sock.C.

void TCP_sock::ensure_init  )  throw (failure) [static, private]
 

Definition at line 108 of file TCP_sock.C.

References init_block, internal_trouble, and TCP_sock_init.

Referenced by name_to_sockaddr(), TCP_sock(), and this_host().

void TCP_sock::ensure_rcvbuffer  )  throw () [private]
 

Definition at line 143 of file TCP_sock.C.

References NEW_PTRFREE_ARRAY, rcvbuff, rcvcurp, and rcvend.

void TCP_sock::ensure_sndbuffer  )  throw () [private]
 

Definition at line 136 of file TCP_sock.C.

References NEW_PTRFREE_ARRAY, sndbuff, and sndbuff_len.

void TCP_sock::ensure_state sock_state  should_be  )  throw (failure) [private]
 

Definition at line 124 of file TCP_sock.C.

References dead, and wrong_state.

Referenced by wait_for_connect().

int TCP_sock::fill_rcvbuffer  )  throw (alerted, failure) [private]
 

Definition at line 1355 of file TCP_sock.C.

References controlled_wait(), dead, default_rcvbuffer_size, fd, internal_trouble, partner_went_away, rcvbuff, state, and SYSERROR.

void TCP_sock::flush  )  throw (failure) [inline]
 

Definition at line 245 of file TCP_sock.H.

References send_data().

fd_t TCP_sock::get_fd  )  throw () [inline]
 

Definition at line 208 of file TCP_sock.H.

References fd.

bool TCP_sock::get_keepalive  )  throw (failure)
 

Definition at line 615 of file TCP_sock.C.

References internal_trouble, and SYSERROR.

void TCP_sock::get_local_addr sockaddr_in &  addr  )  throw (failure)
 

Definition at line 665 of file TCP_sock.C.

References self_addr.

Referenced by Tool_Relay::get_sockaddr(), and SRPC::local_socket().

bool TCP_sock::get_read_timeout unsigned int &  seconds  )  throw () [inline]
 

Definition at line 129 of file TCP_sock.H.

References read_timeout_enabled, and read_timeout_secs.

void TCP_sock::get_remote_addr sockaddr_in &  addr  )  throw (failure)
 

Definition at line 679 of file TCP_sock.C.

References connected, and dead.

Referenced by SRPC::remote_socket().

in_addr TCP_sock::host_to_addr const Text hostname  )  throw (failure) [static]
 

Definition at line 841 of file TCP_sock.C.

References SYSERROR, SYSOK, and unknown_host.

Referenced by init(), MastershipInit1(), name_to_sockaddr(), and UniqueIdInit::UniqueIdInit().

void TCP_sock::init  )  throw (failure) [static, private]
 

Definition at line 314 of file TCP_sock.C.

References Text::cchars(), defaultsock, VestaConfig::get(), host_to_addr(), internal_trouble, self_addr, SYSERROR, and tcp_protolevel.

Referenced by TCP_sock_init().

void TCP_sock::instance_init  )  throw () [private]
 

Definition at line 402 of file TCP_sock.C.

References alerts_enabled, default_rcvbuffer_size, default_sndbuffer_size, fresh, non_blocking, rcvbuff, rcvbuff_size, rcvcurp, rcvend, read_timeout_enabled, sndbuff, sndbuff_len, sndbuff_size, and state.

void TCP_sock::name_to_sockaddr const Text host_and_port,
sockaddr_in &  s
throw (failure) [static]
 

Definition at line 1092 of file TCP_sock.C.

References invalid_parameter.

void TCP_sock::name_to_sockaddr const Text hostname,
const Text port,
sockaddr_in &  s
throw (failure) [static]
 

Definition at line 1068 of file TCP_sock.C.

References ensure_init(), host_to_addr(), and parse_port().

Referenced by connect_to(), and RunTool::send_vdir().

void TCP_sock::new_socket u_short  port  )  throw (failure) [private]
 

Definition at line 426 of file TCP_sock.C.

References defaultsock, environment_problem, inet_ntoa_r(), internal_trouble, invalid_parameter, set_no_delay(), SYSERROR, and tcp_protolevel.

void TCP_sock::operator= TCP_sock  )  [private]
 

u_short TCP_sock::parse_port const Text port  )  throw (failure) [static]
 

Definition at line 739 of file TCP_sock.C.

References SYSOK, TCP_NAME, and unknown_port.

Referenced by name_to_sockaddr().

int TCP_sock::recv_data char *  buffer,
int  len
throw (alerted, failure)
 

Definition at line 1460 of file TCP_sock.C.

References connected, and min().

Referenced by Tool_Relay::body().

void TCP_sock::send_data const char *  buffer,
int  len,
bool  flush = false
throw (failure)
 

Definition at line 1258 of file TCP_sock.C.

References connected, dead, environment_problem, FdCache::flush(), internal_trouble, min(), and SYSERROR.

Referenced by flush().

void TCP_sock::set_input_buffer_size int  bytes = default_rcvbuffer_size  )  throw (failure)
 

Definition at line 510 of file TCP_sock.C.

References invalid_parameter, and wrong_state.

void TCP_sock::set_keepalive bool  state  )  throw (failure)
 

Definition at line 599 of file TCP_sock.C.

References internal_trouble, and SYSERROR.

Referenced by disable_keepalive(), and enable_keepalive().

void TCP_sock::set_no_delay int  fd  )  throw (failure) [static, private]
 

Definition at line 390 of file TCP_sock.C.

References internal_trouble, SYSERROR, and tcp_protolevel.

Referenced by new_socket(), and wait_for_connect().

void TCP_sock::set_output_buffer_size int  bytes = default_sndbuffer_size  )  throw (failure)
 

Definition at line 493 of file TCP_sock.C.

References invalid_parameter, and wrong_state.

void TCP_sock::set_waiters int  waiters = 1  )  throw (failure)
 

Definition at line 1196 of file TCP_sock.C.

References fresh, internal_trouble, listening, and SYSERROR.

Referenced by SRPC_listener::create(), and wait_for_connect().

bool TCP_sock::test_alert  )  throw (failure)
 

Definition at line 584 of file TCP_sock.C.

References alert_flag, and wrong_state.

Referenced by Tool_Relay::body().

Text TCP_sock::this_host  )  throw (failure) [static]
 

Definition at line 659 of file TCP_sock.C.

References ensure_init().

Referenced by RunToolHostInit(), and SRPC::this_host().

TCP_sock * TCP_sock::wait_for_connect  )  throw (alerted, failure)
 

Definition at line 1205 of file TCP_sock.C.

References connected, controlled_wait(), dead, ensure_state(), environment_problem, fd, fresh, him, inet_ntoa_r(), internal_trouble, listening, me, NEW_CONSTR, set_no_delay(), set_waiters(), state, and SYSERROR.

Referenced by Tool_Relay::body(), and SRPC_impl::read_item_code().


Friends And Related Function Documentation

void TCP_sock_init  )  [friend]
 

Definition at line 101 of file TCP_sock.C.

Referenced by ensure_init().


Member Data Documentation

bool TCP_sock::alert_flag [private]
 

Definition at line 291 of file TCP_sock.H.

Referenced by alert(), controlled_wait(), enable_alerts(), and test_alert().

bool TCP_sock::alerts_enabled [private]
 

Definition at line 290 of file TCP_sock.H.

Referenced by configure_blocking(), controlled_wait(), disable_alerts(), enable_alerts(), instance_init(), and ~TCP_sock().

int TCP_sock::bytes_in_pipe [private]
 

Definition at line 294 of file TCP_sock.H.

Referenced by alert(), controlled_wait(), and enable_alerts().

sockaddr_in TCP_sock::defaultsock [static, private]
 

Definition at line 73 of file TCP_sock.C.

Referenced by init(), and new_socket().

fd_t TCP_sock::fd [private]
 

Definition at line 279 of file TCP_sock.H.

Referenced by alive(), controlled_wait(), fill_rcvbuffer(), get_fd(), and wait_for_connect().

sockaddr_in TCP_sock::him [private]
 

Definition at line 278 of file TCP_sock.H.

Referenced by wait_for_connect().

pthread_once_t TCP_sock::init_block = PTHREAD_ONCE_INIT [static, private]
 

Definition at line 69 of file TCP_sock.C.

Referenced by ensure_init().

Basics::mutex TCP_sock::m [private]
 

Definition at line 272 of file TCP_sock.H.

sockaddr_in TCP_sock::me [private]
 

Definition at line 277 of file TCP_sock.H.

Referenced by wait_for_connect().

Text TCP_sock::my_hostname [static, private]
 

Definition at line 72 of file TCP_sock.C.

bool TCP_sock::non_blocking [private]
 

Definition at line 288 of file TCP_sock.H.

Referenced by configure_blocking(), and instance_init().

fd_t TCP_sock::pipe_rd [private]
 

Definition at line 293 of file TCP_sock.H.

Referenced by controlled_wait(), and enable_alerts().

fd_t TCP_sock::pipe_wr [private]
 

Definition at line 292 of file TCP_sock.H.

Referenced by enable_alerts().

char* TCP_sock::rcvbuff [private]
 

Definition at line 283 of file TCP_sock.H.

Referenced by ensure_rcvbuffer(), fill_rcvbuffer(), instance_init(), and ~TCP_sock().

int TCP_sock::rcvbuff_size [private]
 

Definition at line 286 of file TCP_sock.H.

Referenced by instance_init().

char* TCP_sock::rcvcurp [private]
 

Definition at line 284 of file TCP_sock.H.

Referenced by ensure_rcvbuffer(), and instance_init().

char* TCP_sock::rcvend [private]
 

Definition at line 285 of file TCP_sock.H.

Referenced by ensure_rcvbuffer(), and instance_init().

bool TCP_sock::read_timeout_enabled [private]
 

Definition at line 297 of file TCP_sock.H.

Referenced by configure_blocking(), controlled_wait(), disable_read_timeout(), get_read_timeout(), and instance_init().

unsigned int TCP_sock::read_timeout_secs [private]
 

Definition at line 298 of file TCP_sock.H.

Referenced by controlled_wait(), and get_read_timeout().

in_addr TCP_sock::self_addr [static, private]
 

Definition at line 74 of file TCP_sock.C.

Referenced by get_local_addr(), and init().

char* TCP_sock::sndbuff [private]
 

Definition at line 280 of file TCP_sock.H.

Referenced by ensure_sndbuffer(), instance_init(), and ~TCP_sock().

int TCP_sock::sndbuff_len [private]
 

Definition at line 281 of file TCP_sock.H.

Referenced by ensure_sndbuffer(), and instance_init().

int TCP_sock::sndbuff_size [private]
 

Definition at line 282 of file TCP_sock.H.

Referenced by instance_init().

sock_state TCP_sock::state [private]
 

Definition at line 275 of file TCP_sock.H.

Referenced by alive(), controlled_wait(), fill_rcvbuffer(), instance_init(), and wait_for_connect().

int TCP_sock::tcp_protolevel [static, private]
 

Definition at line 75 of file TCP_sock.C.

Referenced by init(), new_socket(), and set_no_delay().


The documentation for this class was generated from the following files:
Generated on Mon May 8 00:49:14 2006 for Vesta by  doxygen 1.4.2