|
feisty meow concerns codebase 2.140
|
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 } |
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.
| sockets::spocket::spocket | ( | const internet_address & | where, |
| sock_types | type = CONNECTED |
||
| ) |
Definition at line 99 of file spocket.cpp.
| sockets::spocket::~spocket | ( | ) |
Definition at line 128 of file spocket.cpp.
References disconnect(), FUNCDEF, LOG, text_form(), and basis::WHACK().
Definition at line 460 of file spocket.cpp.
References accept(), ACCESS_DENIED, BAD_INPUT, CHECK_BOGUS, sockets::raw_socket::close(), CONNECTED, sockets::tcpip_stack::convert(), FUNCDEF, INVALID_SOCKET, LOG, NO_CONNECTION, NULL_POINTER, OKAY, sockets::PENDING_CONNECTIONS_ALLOWED, sockets::raw_socket::set_non_blocking(), sockets::raw_socket::set_reuse_address(), SOCK_EWOULDBLOCK, loggers::critical_events::system_error(), loggers::critical_events::system_error_text(), and sockets::internet_address::text_form().
Referenced by spocket_tester::accept(), and accept().
| outcome sockets::spocket::await_readable | ( | 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, 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 256 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 spocket_tester::do_a_send(), and 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 174 of file spocket.cpp.
|
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 274 of file spocket.cpp.
References ACCESS_DENIED, sockets::internet_address::ADDRESS_SIZE, BAD_INPUT, BROADCAST, CHECK_BOGUS, connect(), 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(), 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(), timely::time_control::sleep_ms(), SOCK_ECONNREFUSED, SOCK_EINPROGRESS, SOCK_EISCONN, SOCK_EWOULDBLOCK, SOCKET_ERROR, basis::array< contents >::stuff(), loggers::critical_events::system_error(), loggers::critical_events::system_error_text(), sockets::internet_address::text_form(), TIMED_OUT, UNICAST, and was_connected().
Referenced by broadcast_spocket_tester::connect(), spocket_tester::connect(), and connect().
| bool sockets::spocket::connected | ( | ) |
Definition at line 209 of file spocket.cpp.
References CONNECTED, ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, LOG, RECOGNIZE_DISCO, sockets::raw_socket::select(), sockets::SI_DISCONNECTED, sockets::SI_ERRONEOUS, and was_connected().
Referenced by connect(), cromp::cromp_client::connected(), cromp::cromp_common::push_outgoing(), receive(), receive_from(), send(), and text_form().
| sockets::spocket::DEFINE_CLASS_NAME | ( | "spocket" | ) |
| outcome sockets::spocket::disconnect | ( | ) |
Definition at line 188 of file spocket.cpp.
References sockets::raw_socket::close(), FUNCDEF, LOG, OKAY, and RECOGNIZE_DISCO.
Referenced by cromp::cromp_common::close_common(), send(), and ~spocket().
| bool sockets::spocket::healthy | ( | ) |
|
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.
|
inline |
Definition at line 104 of file spocket.h.
Referenced by text_form().
|
inline |
|
inline |
Definition at line 105 of file spocket.h.
Referenced by is_root_server().
|
inline |
|
inline |
Definition at line 108 of file spocket.h.
Referenced by cromp::cromp_common::send_buffer().
|
static |
Definition at line 180 of file spocket.cpp.
References sockets::communication_commons::outcome_name(), and basis::outcome::value().
Referenced by spocket_tester::do_a_send(), cromp::cromp_server::look_for_clients(), and cromp::cromp_common::send_buffer().
| outcome sockets::spocket::receive | ( | basis::abyte * | buffer, |
| int & | size | ||
| ) |
Definition at line 664 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, sockets::raw_socket::select(), sockets::raw_socket::SELECTING_JUST_READ, sockets::SI_DISCONNECTED, SOCK_EWOULDBLOCK, loggers::critical_events::system_error(), and loggers::critical_events::system_error_text().
Referenced by spocket_tester::do_a_receive(), and receive().
| outcome sockets::spocket::receive | ( | basis::byte_array & | buffer, |
| int & | size | ||
| ) |
Definition at line 650 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().
| outcome sockets::spocket::receive_from | ( | basis::abyte * | buffer, |
| int & | size, | ||
| internet_address & | where_from | ||
| ) |
Definition at line 713 of file spocket.cpp.
References ACCESS_DENIED, BAD_INPUT, CHECK_BOGUS, CONNECTED, connected(), sockets::tcpip_stack::convert(), ENSURE_HEALTH, FUNCDEF, GRAB_LOCK, LOG, NO_CONNECTION, NONE_READY, OKAY, SOCK_ECONNRESET, SOCK_EWOULDBLOCK, loggers::critical_events::system_error(), and loggers::critical_events::system_error_text().
Referenced by broadcast_spocket_tester::do_a_receive(), and receive_from().
| 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().
| const internet_address & sockets::spocket::remote | ( | ) | const |
Definition at line 148 of file spocket.cpp.
| outcome sockets::spocket::send | ( | const basis::abyte * | buffer, |
| int | size, | ||
| int & | len_sent | ||
| ) |
Definition at line 573 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, send(), SOCK_EWOULDBLOCK, SOCKET_ERROR, loggers::critical_events::system_error(), and loggers::critical_events::system_error_text().
Referenced by spocket_tester::do_a_send(), send(), send(), and cromp::cromp_common::send_buffer().
| outcome sockets::spocket::send | ( | const basis::byte_array & | to_send, |
| int & | len_sent | ||
| ) |
Definition at line 568 of file spocket.cpp.
References basis::array< contents >::length(), basis::array< contents >::observe(), and send().
| outcome sockets::spocket::send_to | ( | const internet_address & | where_to, |
| const basis::abyte * | buffer, | ||
| int | size, | ||
| int & | len_sent | ||
| ) |
Definition at line 628 of file spocket.cpp.
References ACCESS_DENIED, BAD_INPUT, CHECK_BOGUS, CONNECTED, sockets::tcpip_stack::convert(), FUNCDEF, LOG, NONE_READY, OKAY, SOCK_EWOULDBLOCK, loggers::critical_events::system_error(), and sockets::tcpip_stack::tcpip_error_name().
Referenced by broadcast_spocket_tester::do_a_send(), and send_to().
| outcome sockets::spocket::send_to | ( | const internet_address & | where_to, |
| const basis::byte_array & | to_send, | ||
| int & | len_sent | ||
| ) |
Definition at line 622 of file spocket.cpp.
References basis::array< contents >::length(), basis::array< contents >::observe(), and send_to().
| tcpip_stack & sockets::spocket::stack | ( | ) | const |
Definition at line 150 of file spocket.cpp.
| astring sockets::spocket::text_form | ( | ) |
Definition at line 154 of file spocket.cpp.
References connected(), FUNCDEF, is_client(), is_root_server(), basis::astring::s(), sockets::internet_address::text_form(), and was_connected().
Referenced by ~spocket().
|
inline |
Definition at line 94 of file spocket.h.
Referenced by connect(), connected(), and text_form().
| const internet_address & sockets::spocket::where | ( | ) | const |
Definition at line 147 of file spocket.cpp.
Referenced by cromp::cromp_common::other_side().