Abstraction for a higher-level BSD socket that is platform independent. More...
#include <spocket.h>


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_address & | where () const |
| const internet_address & | remote () 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_stack & | stack () 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) |
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.
| 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().
Definition at line 451 of file spocket.cpp.
References ACCESS_DENIED, BAD_INPUT, CHECK_BOGUS, sockets::raw_socket::close(), CONNECTED, sockets::tcpip_stack::convert(), FUNCDEF, INVALID_SOCKET, LOG, NIL, NO_CONNECTION, OKAY, sockets::PENDING_CONNECTIONS_ALLOWED, sockets::raw_socket::set_non_blocking(), sockets::raw_socket::set_reuse_address(), SOCK_EWOULDBLOCK, spocket(), and sockets::internet_address::text_form().
Referenced by spocket_tester::accept().
| outcome sockets::spocket::await_readable | ( | int | timeout | ) |
Definition at line 225 of file spocket.cpp.
References CHECK_BOGUS, ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, NO_CONNECTION, NONE_READY, OKAY, RECOGNIZE_DISCO, sockets::raw_socket::select(), sockets::raw_socket::SELECTING_JUST_READ, sockets::SI_DISCONNECTED, and sockets::SI_READABLE.
Referenced by spocket_tester::do_a_receive().
| outcome sockets::spocket::await_writable | ( | int | timeout | ) |
Definition at line 245 of file spocket.cpp.
References CHECK_BOGUS, ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, NO_CONNECTION, NONE_READY, OKAY, RECOGNIZE_DISCO, sockets::raw_socket::select(), sockets::raw_socket::SELECTING_JUST_WRITE, sockets::SI_DISCONNECTED, and sockets::SI_WRITABLE.
Referenced by cromp::cromp_common::push_outgoing().
| 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 |
) |
Definition at line 265 of file spocket.cpp.
References ACCESS_DENIED, sockets::internet_address::ADDRESS_SIZE, BAD_INPUT, BROADCAST, CHECK_BOGUS, connected(), CONNECTED, sockets::tcpip_stack::convert(), sockets::tcpip_stack::full_resolve(), FUNCDEF, GRAB_LOCK, sockets::internet_address::hostname, INVALID_SOCKET, sockets::internet_address::ip_address, basis::array< contents >::length(), LOG, basis::negative(), NIL, NO_ANSWER, NO_CONNECTION, OKAY, sockets::raw_socket::set_broadcast(), sockets::raw_socket::set_keep_alive(), sockets::raw_socket::set_non_blocking(), sockets::raw_socket::set_reuse_address(), SOCK_ECONNREFUSED, SOCK_EINPROGRESS, SOCK_EISCONN, SOCK_EWOULDBLOCK, SOCKET_ERROR, basis::array< contents >::stuff(), sockets::internet_address::text_form(), TIMED_OUT, and UNICAST.
Referenced by spocket_tester::connect(), and broadcast_spocket_tester::connect().
| bool sockets::spocket::connected | ( | ) |
Definition at line 201 of file spocket.cpp.
References CONNECTED, ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, RECOGNIZE_DISCO, sockets::raw_socket::select(), sockets::SI_DISCONNECTED, and sockets::SI_ERRONEOUS.
Referenced by connect(), cromp::cromp_client::connected(), cromp::cromp_common::push_outgoing(), and text_form().
| 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] |
| 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] |
| 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 | |||
| ) |
Definition at line 646 of file spocket.cpp.
References basis::array< contents >::access(), BAD_INPUT, CHECK_BOGUS, CONNECTED, FUNCDEF, basis::array< contents >::last(), NONE_READY, OKAY, receive(), basis::array< contents >::reset(), and basis::array< contents >::zap().
| basis::outcome sockets::spocket::receive | ( | basis::abyte * | buffer, | |
| int & | size | |||
| ) |
Referenced by spocket_tester::do_a_receive(), and receive().
| outcome sockets::spocket::receive_from | ( | basis::byte_array & | buffer, | |
| int & | size, | |||
| internet_address & | where_from | |||
| ) |
Definition at line 697 of file spocket.cpp.
References basis::array< contents >::access(), BAD_INPUT, CHECK_BOGUS, CONNECTED, FUNCDEF, basis::array< contents >::last(), NONE_READY, OKAY, receive_from(), basis::array< contents >::reset(), and basis::array< contents >::zap().
| basis::outcome sockets::spocket::receive_from | ( | basis::abyte * | buffer, | |
| int & | size, | |||
| internet_address & | where_from | |||
| ) |
Referenced by broadcast_spocket_tester::do_a_receive(), and receive_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 | |||
| ) |
Definition at line 562 of file spocket.cpp.
References basis::array< contents >::length(), basis::array< contents >::observe(), and send().
| basis::outcome sockets::spocket::send | ( | const basis::abyte * | buffer, | |
| int | size, | |||
| int & | len_sent | |||
| ) |
Referenced by send(), and cromp::cromp_common::send_buffer().
| outcome sockets::spocket::send_to | ( | const internet_address & | where_to, | |
| const basis::byte_array & | to_send, | |||
| int & | len_sent | |||
| ) |
Definition at line 618 of file spocket.cpp.
References basis::array< contents >::length(), basis::array< contents >::observe(), and send_to().
| basis::outcome sockets::spocket::send_to | ( | const internet_address & | where_to, | |
| const basis::abyte * | buffer, | |||
| int | size, | |||
| int & | len_sent | |||
| ) |
Referenced by send_to().
| tcpip_stack & sockets::spocket::stack | ( | ) | const |
Definition at line 145 of file spocket.cpp.
| astring sockets::spocket::text_form | ( | ) |
Definition at line 149 of file spocket.cpp.
References connected(), is_client(), is_root_server(), basis::astring::s(), sockets::internet_address::text_form(), and was_connected().
Referenced by ~spocket().
| 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().
1.6.3