sockets::spocket Class Reference

Abstraction for a higher-level BSD socket that is platform independent. More...

#include <spocket.h>

Inheritance diagram for sockets::spocket:
Inheritance graph
[legend]
Collaboration diagram for sockets::spocket:
Collaboration graph
[legend]

List of all members.

Public Types

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

Public Member Functions

 spocket (const internet_address &where, sock_types type=CONNECTED)
 ~spocket ()
 DEFINE_CLASS_NAME ("spocket")
bool healthy ()
const internet_addresswhere () const
const internet_addressremote () const
basis::astring text_form ()
bool was_connected () const
bool connected ()
bool is_client () const
bool is_server () const
bool is_root_server () const
basis::un_int OS_socket ()
basis::un_int OS_root_socket ()
void bind_client (const internet_address &source)
 when a client calls connect, this forces it to bind to "source".
basis::outcome connect (int communication_wait=20 *basis::SECOND_ms)
basis::outcome accept (spocket *&sock, bool wait)
basis::outcome disconnect ()
bool client () const
bool server () const
basis::outcome send (const basis::abyte *buffer, int size, int &len_sent)
basis::outcome send (const basis::byte_array &to_send, int &len_sent)
basis::outcome send_to (const internet_address &where_to, const basis::abyte *buffer, int size, int &len_sent)
basis::outcome send_to (const internet_address &where_to, const basis::byte_array &to_send, int &len_sent)
basis::outcome receive (basis::abyte *buffer, int &size)
basis::outcome receive (basis::byte_array &buffer, int &size)
basis::outcome receive_from (basis::abyte *buffer, int &size, internet_address &where_from)
basis::outcome receive_from (basis::byte_array &buffer, int &size, internet_address &where_from)
basis::outcome await_readable (int timeout)
basis::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 basis::outcome &to_name)

Detailed Description

Abstraction for a higher-level BSD socket that is platform independent.

The class works on Unix and Win32 style operating systems. This class is named in honor of the venerable Vulcan Spock, which also avoid naming conflicts with the OS's socket() function.

Definition at line 39 of file spocket.h.


Member Enumeration Documentation

Enumerator:
OKAY 
TIMED_OUT 
ACCESS_DENIED 
BAD_INPUT 
NONE_READY 
PARTIAL 
NO_CONNECTION 
NO_ANSWER 
DEFINE_OUTCOME 

Definition at line 71 of file spocket.h.

Enumerator:
CONNECTED 
BROADCAST 
UNICAST 
BOGUS_SOCK 

Definition at line 42 of file spocket.h.


Constructor & Destructor Documentation

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

Definition at line 94 of file spocket.cpp.

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

Referenced by accept().

sockets::spocket::~spocket (  ) 

Definition at line 123 of file spocket.cpp.

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


Member Function Documentation

outcome sockets::spocket::accept ( spocket *&  sock,
bool  wait 
)
outcome sockets::spocket::await_readable ( int  timeout  ) 
outcome sockets::spocket::await_writable ( int  timeout  ) 
void sockets::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 164 of file spocket.cpp.

bool sockets::spocket::client (  )  const [inline]

Definition at line 152 of file spocket.h.

Referenced by spocket_tester::perform_test().

outcome sockets::spocket::connect ( int  communication_wait = 20 * basis::SECOND_ms  ) 
bool sockets::spocket::connected (  ) 
sockets::spocket::DEFINE_CLASS_NAME ( "spocket"   ) 
outcome sockets::spocket::disconnect (  ) 

Definition at line 178 of file spocket.cpp.

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

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

bool sockets::spocket::healthy (  ) 
bool sockets::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 211 of file spocket.h.

References BOGUS_SOCK.

bool sockets::spocket::is_client (  )  const [inline]

Definition at line 104 of file spocket.h.

Referenced by text_form().

bool sockets::spocket::is_root_server (  )  const [inline]

Definition at line 106 of file spocket.h.

References is_server().

Referenced by text_form().

bool sockets::spocket::is_server (  )  const [inline]

Definition at line 105 of file spocket.h.

Referenced by is_root_server().

basis::un_int sockets::spocket::OS_root_socket (  )  [inline]

Definition at line 113 of file spocket.h.

basis::un_int sockets::spocket::OS_socket (  )  [inline]

Definition at line 108 of file spocket.h.

Referenced by cromp::cromp_common::send_buffer().

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

Definition at line 170 of file spocket.cpp.

References basis::outcome::value().

outcome sockets::spocket::receive ( basis::byte_array buffer,
int &  size 
)
basis::outcome sockets::spocket::receive ( basis::abyte buffer,
int &  size 
)
outcome sockets::spocket::receive_from ( basis::byte_array buffer,
int &  size,
internet_address where_from 
)
basis::outcome sockets::spocket::receive_from ( basis::abyte buffer,
int &  size,
internet_address where_from 
)
const internet_address & sockets::spocket::remote (  )  const

Definition at line 143 of file spocket.cpp.

outcome sockets::spocket::send ( const basis::byte_array to_send,
int &  len_sent 
)
basis::outcome sockets::spocket::send ( const basis::abyte buffer,
int  size,
int &  len_sent 
)
outcome sockets::spocket::send_to ( const internet_address where_to,
const basis::byte_array to_send,
int &  len_sent 
)
basis::outcome sockets::spocket::send_to ( const internet_address where_to,
const basis::abyte buffer,
int  size,
int &  len_sent 
)

Referenced by send_to().

bool sockets::spocket::server (  )  const [inline]

Definition at line 153 of file spocket.h.

tcpip_stack & sockets::spocket::stack (  )  const

Definition at line 145 of file spocket.cpp.

astring sockets::spocket::text_form (  ) 
bool sockets::spocket::was_connected (  )  const [inline]

Definition at line 94 of file spocket.h.

Referenced by text_form().

const internet_address & sockets::spocket::where (  )  const

Definition at line 142 of file spocket.cpp.

Referenced by cromp::cromp_common::other_side().


The documentation for this class was generated from the following files:
Generated on Sat Jan 28 04:25:54 2012 for hoople2 project by  doxygen 1.6.3