spocket Class Reference

#include <spocket.h>

Inheritance diagram for spocket:

Inheritance graph
[legend]
Collaboration diagram for spocket:

Collaboration graph
[legend]
List of all members.

Public Types

enum  sock_types { CONNECTED, BROADCAST, UNICAST, BOGUS_SOCK }
enum  outcomes {
  OKAY = common::OKAY, TIMED_OUT = common::TIMED_OUT, ACCESS_DENIED = common::ACCESS_DENIED, BAD_INPUT = common::BAD_INPUT,
  NONE_READY = common::NONE_READY, PARTIAL = common::PARTIAL, NO_CONNECTION = communication_commons::NO_CONNECTION, NO_ANSWER = communication_commons::NO_ANSWER,
  NOT_SERVER, server
}

Public Member Functions

 spocket (const internet_address &where, sock_types type=CONNECTED)
 ~spocket ()
 IMPLEMENT_CLASS_NAME ("spocket")
bool healthy ()
const internet_addresswhere () const
const internet_addressremote () const
istring text_form ()
bool was_connected () const
bool connected ()
bool is_client () const
bool is_server () const
bool is_root_server () const
u_int OS_socket ()
u_int OS_root_socket ()
void bind_client (const internet_address &source)
 when a client calls connect, this forces it to bind to "source".
outcome connect (int communication_wait=20 *SECOND_ms)
outcome accept (spocket *&sock, bool wait)
outcome disconnect ()
bool client () const
bool server () const
outcome send (const byte *buffer, int size, int &len_sent)
outcome send (const byte_array &to_send, int &len_sent)
outcome send_to (const internet_address &where_to, const byte *buffer, int size, int &len_sent)
outcome send_to (const internet_address &where_to, const byte_array &to_send, int &len_sent)
outcome receive (byte *buffer, int &size)
outcome receive (byte_array &buffer, int &size)
outcome receive_from (byte *buffer, int &size, internet_address &where_from)
outcome receive_from (byte_array &buffer, int &size, internet_address &where_from)
outcome await_readable (int timeout)
outcome await_writable (int timeout)
tcpip_stackstack () const
bool is_bogus () const
 returns true when this object is bogus.

Static Public Member Functions

static const char * outcome_name (const outcome &to_name)

Detailed Description

Definition at line 35 of file spocket.h.


Member Enumeration Documentation

enum spocket::sock_types

Enumerator:
CONNECTED 
BROADCAST 
UNICAST 
BOGUS_SOCK 

Definition at line 38 of file spocket.h.

enum spocket::outcomes

Enumerator:
OKAY 
TIMED_OUT 
ACCESS_DENIED 
BAD_INPUT 
NONE_READY 
PARTIAL 
NO_CONNECTION 
NO_ANSWER 
NOT_SERVER 
server 

Definition at line 67 of file spocket.h.


Constructor & Destructor Documentation

spocket::spocket ( const internet_address where,
sock_types  type = CONNECTED 
)

Definition at line 93 of file spocket.cpp.

References BOGUS_SOCK, BROADCAST, CONNECTED, FUNCDEF, LOG, and UNICAST.

Referenced by accept().

spocket::~spocket (  ) 

Definition at line 122 of file spocket.cpp.

References disconnect(), FUNCDEF, LOG, text_form(), and WHACK().


Member Function Documentation

spocket::IMPLEMENT_CLASS_NAME ( "spocket"   ) 

bool spocket::healthy (  ) 

const internet_address & spocket::where (  )  const

Definition at line 141 of file spocket.cpp.

Referenced by cromp_common::other_side().

const internet_address & spocket::remote (  )  const

Definition at line 142 of file spocket.cpp.

const char * spocket::outcome_name ( const outcome to_name  )  [static]

Definition at line 169 of file spocket.cpp.

References NOT_SERVER, communication_commons::outcome_name(), and outcome::value().

Referenced by spocket_tester::do_a_send(), cromp_server::look_for_clients(), and cromp_common::send_buffer().

istring spocket::text_form (  ) 

Definition at line 148 of file spocket.cpp.

References connected(), is_client(), is_root_server(), istring::s(), internet_address::text_form(), and was_connected().

Referenced by ~spocket().

bool spocket::was_connected (  )  const [inline]

Definition at line 90 of file spocket.h.

Referenced by text_form().

bool spocket::connected (  ) 

Definition at line 198 of file spocket.cpp.

References CONNECTED, ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, RECOGNIZE_DISCO, raw_socket::select(), SI_DISCONNECTED, and SI_ERRONEOUS.

Referenced by connect(), cromp_client::connected(), cromp_common::push_outgoing(), receive(), receive_from(), send(), and text_form().

bool spocket::is_client (  )  const [inline]

Definition at line 100 of file spocket.h.

Referenced by text_form().

bool spocket::is_server (  )  const [inline]

Definition at line 101 of file spocket.h.

bool spocket::is_root_server (  )  const [inline]

Definition at line 102 of file spocket.h.

Referenced by text_form().

u_int spocket::OS_socket (  )  [inline]

Definition at line 104 of file spocket.h.

Referenced by cromp_common::send_buffer().

u_int spocket::OS_root_socket (  )  [inline]

Definition at line 109 of file spocket.h.

void spocket::bind_client ( const internet_address source  ) 

when a client calls connect, this forces it to bind to "source".

this has no effect on servers. it is also disabled again when the client is disconnected, so it should always be done before every time connect() is called.

Definition at line 163 of file spocket.cpp.

outcome spocket::connect ( int  communication_wait = 20 *SECOND_ms  ) 

Definition at line 256 of file spocket.cpp.

References ACCESS_DENIED, internet_address::ADDRESS_SIZE, BAD_INPUT, BROADCAST, CHECK_BOGUS, connected(), CONNECTED, tcpip_stack::convert(), FILT_LOG, tcpip_stack::full_resolve(), FUNCDEF, GRAB_LOCK, internet_address::hostname, INVALID_SOCKET, internet_address::ip_address, internet_address::is_nil_address(), array< contents >::length(), LOG, negative(), common::NETWORK_LOGGING, NIL, NO_ANSWER, NO_CONNECTION, OKAY, RESOLVE_INTERVAL, raw_socket::set_broadcast(), raw_socket::set_keep_alive(), raw_socket::set_non_blocking(), raw_socket::set_reuse_address(), portable::sleep_ms(), SOCK_ECONNREFUSED, SOCK_EINPROGRESS, SOCK_EISCONN, SOCK_EWOULDBLOCK, SOCKET_ERROR, array< contents >::stuff(), portable::system_error(), portable::system_error_text(), internet_address::text_form(), TIMED_OUT, and UNICAST.

Referenced by spocket_tester::connect(), and broadcast_spocket_tester::connect().

outcome spocket::accept ( spocket *&  sock,
bool  wait 
)

Definition at line 445 of file spocket.cpp.

References ACCESS_DENIED, BAD_INPUT, CHECK_BOGUS, raw_socket::close(), CONNECTED, tcpip_stack::convert(), FUNCDEF, INVALID_SOCKET, LOG, NIL, NO_CONNECTION, NOT_SERVER, OKAY, PENDING_CONNECTIONS_ALLOWED, raw_socket::set_non_blocking(), raw_socket::set_reuse_address(), SOCK_EWOULDBLOCK, spocket(), portable::system_error(), portable::system_error_text(), and internet_address::text_form().

Referenced by spocket_tester::accept().

outcome spocket::disconnect (  ) 

Definition at line 177 of file spocket.cpp.

References raw_socket::close(), FUNCDEF, LOG, OKAY, and RECOGNIZE_DISCO.

Referenced by cromp_common::close_common(), send(), and ~spocket().

bool spocket::client (  )  const [inline]

Definition at line 148 of file spocket.h.

Referenced by spocket_tester::perform_test().

bool spocket::server (  )  const [inline]

Definition at line 149 of file spocket.h.

outcome spocket::send ( const byte buffer,
int  size,
int &  len_sent 
)

Definition at line 561 of file spocket.cpp.

References ACCESS_DENIED, BAD_INPUT, CHECK_BOGUS, connected(), CONNECTED, disconnect(), ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, LOG, NO_CONNECTION, NONE_READY, OKAY, PARTIAL, SOCK_EWOULDBLOCK, SOCKET_ERROR, portable::system_error(), and portable::system_error_text().

Referenced by spocket_tester::do_a_send(), send(), and cromp_common::send_buffer().

outcome spocket::send ( const byte_array to_send,
int &  len_sent 
)

Definition at line 556 of file spocket.cpp.

References array< contents >::length(), array< contents >::observe(), and send().

outcome spocket::send_to ( const internet_address where_to,
const byte buffer,
int  size,
int &  len_sent 
)

Definition at line 616 of file spocket.cpp.

References ACCESS_DENIED, BAD_INPUT, CHECK_BOGUS, CONNECTED, tcpip_stack::convert(), FUNCDEF, LOG, NONE_READY, OKAY, SOCK_EWOULDBLOCK, portable::system_error(), and tcpip_stack::tcpip_error_name().

Referenced by broadcast_spocket_tester::do_a_send(), and send_to().

outcome spocket::send_to ( const internet_address where_to,
const byte_array to_send,
int &  len_sent 
)

Definition at line 610 of file spocket.cpp.

References array< contents >::length(), array< contents >::observe(), and send_to().

outcome spocket::receive ( byte buffer,
int &  size 
)

Definition at line 652 of file spocket.cpp.

References ACCESS_DENIED, BAD_INPUT, CHECK_BOGUS, connected(), CONNECTED, ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, LOG, NO_CONNECTION, NONE_READY, OKAY, RECOGNIZE_DISCO, raw_socket::select(), raw_socket::SELECTING_JUST_READ, SI_DISCONNECTED, SOCK_EWOULDBLOCK, portable::system_error(), and portable::system_error_text().

Referenced by spocket_tester::do_a_receive(), and receive().

outcome spocket::receive ( byte_array buffer,
int &  size 
)

Definition at line 638 of file spocket.cpp.

References array< contents >::access(), BAD_INPUT, CHECK_BOGUS, CONNECTED, FUNCDEF, array< contents >::last(), NONE_READY, OKAY, receive(), array< contents >::reset(), and array< contents >::zap().

outcome spocket::receive_from ( byte buffer,
int &  size,
internet_address where_from 
)

Definition at line 701 of file spocket.cpp.

References ACCESS_DENIED, BAD_INPUT, CHECK_BOGUS, connected(), CONNECTED, tcpip_stack::convert(), ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, LOG, NO_CONNECTION, NONE_READY, OKAY, SOCK_ECONNRESET, SOCK_EWOULDBLOCK, portable::system_error(), and portable::system_error_text().

Referenced by broadcast_spocket_tester::do_a_receive(), and receive_from().

outcome spocket::receive_from ( byte_array buffer,
int &  size,
internet_address where_from 
)

Definition at line 685 of file spocket.cpp.

References array< contents >::access(), BAD_INPUT, CHECK_BOGUS, CONNECTED, FUNCDEF, array< contents >::last(), NONE_READY, OKAY, receive_from(), array< contents >::reset(), and array< contents >::zap().

outcome spocket::await_readable ( int  timeout  ) 

Definition at line 220 of file spocket.cpp.

References CHECK_BOGUS, ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, NO_CONNECTION, NONE_READY, OKAY, RECOGNIZE_DISCO, raw_socket::select(), raw_socket::SELECTING_JUST_READ, SI_DISCONNECTED, and SI_READABLE.

Referenced by spocket_tester::do_a_receive().

outcome spocket::await_writable ( int  timeout  ) 

Definition at line 238 of file spocket.cpp.

References CHECK_BOGUS, ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, NO_CONNECTION, NONE_READY, OKAY, RECOGNIZE_DISCO, raw_socket::select(), raw_socket::SELECTING_JUST_WRITE, SI_DISCONNECTED, and SI_WRITABLE.

Referenced by spocket_tester::do_a_send(), and cromp_common::push_outgoing().

tcpip_stack & spocket::stack (  )  const

Definition at line 144 of file spocket.cpp.

bool spocket::is_bogus (  )  const [inline]

returns true when this object is bogus.

a spocket constructed as BOGUS_SOCK does not open a network connection to anywhere, and it also never sends or receives any data. it allows code based on spockets to be disabled when appropriate, so that the spocket is still constructed and all methods can be invoked, but it does nothing.

Definition at line 207 of file spocket.h.


The documentation for this class was generated from the following files:
Generated on Sat Aug 30 04:33:27 2008 for HOOPLE Libraries by  doxygen 1.5.1