feisty meow concerns codebase  2.140
sockets::spocket Class Reference

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

#include <spocket.h>

Inheritance diagram for sockets::spocket:
Collaboration diagram for sockets::spocket:

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". More...
 
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. More...
 

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

◆ outcomes

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.

◆ sock_types

Enumerator
CONNECTED 
BROADCAST 
UNICAST 
BOGUS_SOCK 

Definition at line 42 of file spocket.h.

Constructor & Destructor Documentation

◆ spocket()

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

Definition at line 99 of file spocket.cpp.

References FUNCDEF, and LOG.

◆ ~spocket()

sockets::spocket::~spocket ( )

Definition at line 128 of file spocket.cpp.

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

Member Function Documentation

◆ accept()

◆ await_readable()

outcome sockets::spocket::await_readable ( int  timeout)

◆ await_writable()

outcome sockets::spocket::await_writable ( int  timeout)

◆ bind_client()

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.

◆ client()

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

Definition at line 152 of file spocket.h.

Referenced by spocket_tester::perform_test().

◆ connect()

◆ connected()

bool sockets::spocket::connected ( )

◆ DEFINE_CLASS_NAME()

sockets::spocket::DEFINE_CLASS_NAME ( "spocket"  )

◆ disconnect()

outcome sockets::spocket::disconnect ( )

Definition at line 188 of file spocket.cpp.

References FUNCDEF, LOG, and RECOGNIZE_DISCO.

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

◆ healthy()

bool sockets::spocket::healthy ( )

◆ is_bogus()

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.

◆ is_client()

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

Definition at line 104 of file spocket.h.

◆ is_root_server()

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

Definition at line 106 of file spocket.h.

References is_server().

◆ is_server()

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

Definition at line 105 of file spocket.h.

Referenced by is_root_server().

◆ OS_root_socket()

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

Definition at line 113 of file spocket.h.

◆ OS_socket()

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

Definition at line 108 of file spocket.h.

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

◆ outcome_name()

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

Definition at line 180 of file spocket.cpp.

References basis::outcome::value().

◆ receive() [1/2]

outcome sockets::spocket::receive ( basis::abyte buffer,
int &  size 
)

◆ receive() [2/2]

◆ receive_from() [1/2]

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

◆ receive_from() [2/2]

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

◆ remote()

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

Definition at line 148 of file spocket.cpp.

◆ send() [1/2]

outcome sockets::spocket::send ( const basis::abyte buffer,
int  size,
int &  len_sent 
)

◆ send() [2/2]

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

◆ send_to() [1/2]

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 CHECK_BOGUS, FUNCDEF, LOG, and SOCK_EWOULDBLOCK.

Referenced by broadcast_spocket_tester::do_a_send().

◆ send_to() [2/2]

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

◆ server()

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

Definition at line 153 of file spocket.h.

◆ stack()

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

Definition at line 150 of file spocket.cpp.

◆ text_form()

astring sockets::spocket::text_form ( )

Definition at line 154 of file spocket.cpp.

References FUNCDEF, and basis::astring::text_form().

◆ was_connected()

bool sockets::spocket::was_connected ( ) const
inline

Definition at line 94 of file spocket.h.

◆ where()

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

Definition at line 147 of file spocket.cpp.

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


The documentation for this class was generated from the following files: