conexus logo

Conexus::Socket Class Reference
[Conexus I/O Endpoints]

This class encapsulates Linux's BSD Socket API and serves as the base class for all objects performing socket I/O. More...

#include <socket.h>

Inheritance diagram for Conexus::Socket:

Inheritance graph
[legend]

List of all members.

Public Types

typedef ConexusPointer< Socketpointer

Public Member Functions

virtual ~Socket () throw ()
virtual void open () throw ( open_exception )
 Creates the socket; similar to the socket() call.
virtual void close (bool force=false) throw ( close_exception )
 Overloads the parent FileDescriptor class to ensure that the final state clears the BOUND, CONNECTED, LISTENING and ACCEPTED flags.
virtual void bind () throw ( bind_exception )
 Binding without an address (autobinding) is a child specific action.
virtual void bind (const Conexus::Address &a) throw ( bind_exception )
 Binds the socket to the specified address.
virtual void connect () throw ( connect_exception )
 Connecting without an address (autoconnecting) is a child specific action.
virtual void connect (const Address &a) throw ( connect_exception )
 Connects the socket to the provided address.
virtual void listen (int backlog=0)
 Places the socket in a listening mode; nearly identical to calling listen() on the socket.
int domain () throw ()
 Returns the communication domain which specifies the protocol family of the socket.
void set_domain (int) throw ()
 Sets the communication domain which specifies the protocol family of the socket; this will only set the domain internally, but will not have an actual effect until the socket is created, or if the socket is already created it will not have an effect until the socket is closed and recreated.
int type () throw ()
 Returns the socket type, which defines the communication mechanism of the socket.
void set_type (int) throw ()
 Sets the socket type, which defines the communication mechanism of the socket.
int protocol () throw ()
 Returns the specific protocol within the socket's protocol family.
void set_protocol (int) throw ()
 Sets the specific protocol within the socket's protocol family, but is normally 0.
virtual size_t writeto (Address &a, const void *data, size_t size, Timeout timeout=Timeout(-1)) throw ( write_exception )
virtual size_t writeto (Address &a, const Data data, Timeout timeout=Timeout(-1)) throw ( write_exception )
virtual void set_option (int option, bool b, long required_state=SOCKET_BOUND)
template<typename T >
void set_option (int level, int optname, T &value, long required_state=SOCKET_BOUND)
template<typename T >
void option (int level, int optname, T &value, long required_state=SOCKET_BOUND)
void enable_reuse_address (bool enable=true)
virtual void change_state (long states) throw ( state_exception )
sigc::signal< void > signal_bound ()
sigc::signal< void > signal_connected ()
sigc::signal< void > signal_listening ()
bool is_bound ()
bool is_connected ()
bool is_listening ()
bool is_accepted ()

Static Public Member Functions

static pointer create (int domain=-1, int type=-1, int protocol=0) throw ()

Protected Member Functions

 Socket (int domain=-1, int type=-1, int protocol=0) throw ()
 This default constructor is primarily for children to specify a domain, type and socket protocol.
virtual void read_thread_main ()
virtual void set_state_closed ()
virtual void set_state_bound ()
virtual void set_state_connected ()
virtual void set_state_listening ()
virtual size_t write_data (const Data data, Timeout timeout) throw ( write_exception )
virtual Data read_data (size_t size, Timeout timeout) throw ( read_exception )
 Reimplements Endpoint::read_data() using FileDescriptor::read_data().

Protected Attributes

int m_domain
int m_type
int m_protocol
sigc::signal< void > m_signal_bound
sigc::signal< void > m_signal_connected
sigc::signal< void > m_signal_listening

Related Functions

(Note that these are not member functions.)

enum  SocketState {
  SOCKET_BOUND = ENDPOINT_LAST_STATE << 1, SOCKET_CONNECTED = ENDPOINT_LAST_STATE << 2, SOCKET_LISTENING = ENDPOINT_LAST_STATE << 3, SOCKET_ACCEPTED = ENDPOINT_LAST_STATE << 4,
  SOCKET_LAST_STATE = SOCKET_ACCEPTED
}


Detailed Description

This class encapsulates Linux's BSD Socket API and serves as the base class for all objects performing socket I/O.

This class provides the following propertymm properties:

Author:
Rick L Vinyard Jr

Member Typedef Documentation

typedef ConexusPointer<Socket> Conexus::Socket::pointer


Constructor & Destructor Documentation

Conexus::Socket::Socket ( int  domain = -1,
int  type = -1,
int  protocol = 0 
) throw () [protected]

This default constructor is primarily for children to specify a domain, type and socket protocol.

Conexus::Socket::~Socket (  )  throw () [virtual]


Member Function Documentation

void Conexus::Socket::bind ( const Conexus::Address a  )  throw ( bind_exception ) [virtual]

Binds the socket to the specified address.

The socket should already be in the OPENED state before this call.

If the socket is in the CLOSED state, then set_state(OPENED) will be automatically called.

Reimplemented in Conexus::IPv4::IP, Conexus::IPv4::UDP, Conexus::IPv4::UDPPoset, Conexus::IPv6::IP, Conexus::IPv6::UDP, and Conexus::IPv6::UDPPoset.

References Conexus::ENDPOINT_OPENED, and Conexus::throw_bind_exception().

void Conexus::Socket::bind (  )  throw ( bind_exception ) [virtual]

Binding without an address (autobinding) is a child specific action.

By default an attempt to bind without providing an address will result in a thrown exception condition. Therefore children should modify this behavior if they wish to provide autobinding.

Reimplemented in Conexus::IPv4::IP, Conexus::IPv4::UDP, Conexus::IPv4::UDPPoset, Conexus::IPv6::IP, Conexus::IPv6::UDP, Conexus::IPv6::UDPPoset, and Conexus::LL::Packet.

Referenced by Conexus::LL::Packet::bind(), Conexus::IPv6::IP::bind(), and Conexus::IPv4::IP::bind().

void Conexus::Socket::change_state ( long  states  )  throw ( state_exception ) [virtual]

void Conexus::Socket::close ( bool  force = false  )  throw ( close_exception ) [virtual]

Overloads the parent FileDescriptor class to ensure that the final state clears the BOUND, CONNECTED, LISTENING and ACCEPTED flags.

Reimplemented from Conexus::FileDescriptor.

References Conexus::throw_close_exception().

void Conexus::Socket::connect ( const Address a  )  throw ( connect_exception ) [virtual]

Connects the socket to the provided address.

If the socket is in the CLOSED state, then set_state(OPENED) will be automatically called.

If the provided address is a broadcast address, will also set the broadcast socket option.

References Conexus::ENDPOINT_OPENED, and Conexus::throw_connect_exception().

void Conexus::Socket::connect (  )  throw ( connect_exception ) [virtual]

Connecting without an address (autoconnecting) is a child specific action.

By default an attempt to connect without providing an address will result in a thrown exception condition. Therefore children should modify this behavior if they wish to provide autoconnection.

Reimplemented in Conexus::IPv4::IP, Conexus::IPv4::UDP, Conexus::IPv4::UDPPoset, Conexus::IPv6::IP, Conexus::IPv6::UDP, Conexus::IPv6::UDPPoset, Conexus::SSL::IPv4::TCP, Conexus::SSL::IPv4::UDP, and Conexus::SSL::IPv6::TCP.

Referenced by Conexus::IPv6::IP::connect(), and Conexus::IPv4::IP::connect().

Socket::pointer Conexus::Socket::create ( int  domain = -1,
int  type = -1,
int  protocol = 0 
) throw () [static]

int Conexus::Socket::domain (  )  throw ()

Returns the communication domain which specifies the protocol family of the socket.

References m_domain.

void Conexus::Socket::enable_reuse_address ( bool  enable = true  ) 

bool Conexus::Socket::is_accepted (  ) 

bool Conexus::Socket::is_bound (  ) 

bool Conexus::Socket::is_connected (  ) 

bool Conexus::Socket::is_listening (  ) 

void Conexus::Socket::listen ( int  backlog = 0  )  [virtual]

Places the socket in a listening mode; nearly identical to calling listen() on the socket.

The socket should already be in the BOUND state before this call.

If the socket is in the CLOSED or OPENED states, then set_state(BOUND) will be automatically called.

References change_state(), is_bound(), Conexus::FileDescriptor::m_fd, set_state_listening(), Conexus::SOCKET_BOUND, and Conexus::throw_listen_exception().

void Conexus::Socket::open (  )  throw ( open_exception ) [virtual]

Creates the socket; similar to the socket() call.

Ideally, the socket will be in the CLOSED state before this call.

If the socket is in the OPENED state (not BOUND, CONNECTED, LISTENING, ACCEPTED...) this method will return without performing any action.

If the socket is in any state other than CLOSED or OPENED the socket will be closed and reopened.

Implements Conexus::Endpoint.

Reimplemented in Conexus::SSL::IPv4::TCP, Conexus::SSL::IPv4::UDP, and Conexus::SSL::IPv6::TCP.

References change_state(), Conexus::ENDPOINT_CLOSED, Conexus::Endpoint::is_open(), m_domain, Conexus::FileDescriptor::m_fd, m_protocol, m_type, Conexus::Endpoint::set_state_opened(), and Conexus::throw_open_exception().

template<typename T >
void Conexus::Socket::option ( int  level,
int  optname,
T &  value,
long  required_state = SOCKET_BOUND 
) [inline]

int Conexus::Socket::protocol (  )  throw ()

Returns the specific protocol within the socket's protocol family.

References m_protocol.

Data Conexus::Socket::read_data ( size_t  size,
Timeout  timeout 
) throw ( read_exception ) [protected, virtual]

Reimplements Endpoint::read_data() using FileDescriptor::read_data().

Changes from FileDescriptor::read_data()

Reimplemented from Conexus::FileDescriptor.

Reimplemented in Conexus::SSL::IPv4::TCP, Conexus::SSL::IPv4::UDP, and Conexus::SSL::IPv6::TCP.

References Conexus::FileDescriptor::read_data(), Conexus::Data::size(), and Conexus::SOCKET_BOUND.

void Conexus::Socket::read_thread_main (  )  [protected, virtual]

Reimplemented from Conexus::Endpoint.

References change_state(), is_bound(), and Conexus::SOCKET_BOUND.

void Conexus::Socket::set_domain ( int  d  )  throw ()

Sets the communication domain which specifies the protocol family of the socket; this will only set the domain internally, but will not have an actual effect until the socket is created, or if the socket is already created it will not have an effect until the socket is closed and recreated.

Linux currently defines the following protocol families:
Name Purpose Man page
PF_UNIX, PF_LOCALLocal communication unix(7)
PF_INET IPv4 Internet protocols ip(7)
PF_INET6 IPv6 Internet protocols
PF_IPX IPX - Novell protocols
PF_NETLINK Kernel user interface device netlink(7)
PF_X25 ITU-T X.25 / ISO-8208 protocolx25(7)
PF_AX25 Amateur radio AX.25 protocol
PF_ATMPVC Access to raw ATM PVCs
PF_APPLETALK Appletalkddp(7)
PF_PACKET Low level packet interface packet(7)

template<typename T >
void Conexus::Socket::set_option ( int  level,
int  optname,
T &  value,
long  required_state = SOCKET_BOUND 
) [inline]

void Conexus::Socket::set_option ( int  option,
bool  b,
long  required_state = SOCKET_BOUND 
) [virtual]

void Conexus::Socket::set_protocol ( int  p  )  throw ()

Sets the specific protocol within the socket's protocol family, but is normally 0.

void Conexus::Socket::set_state_bound (  )  [protected, virtual]

void Conexus::Socket::set_state_closed (  )  [protected, virtual]

void Conexus::Socket::set_state_connected (  )  [protected, virtual]

void Conexus::Socket::set_state_listening (  )  [protected, virtual]

void Conexus::Socket::set_type ( int  t  )  throw ()

Sets the socket type, which defines the communication mechanism of the socket.

Linux currently defines the following communication types:

  • SOCK_STREAM
    • Provides sequenced, reliable, two-way, connection-based byte streams. An out-of-band data transmission mechanism may be supported.
  • SOCK_DGRAM
    • Supports datagrams (connectionless, unreliable messages of a fixed maximum length).
  • SOCK_SEQPACKET
    • Provides a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length; a consumer is required to read an entire packet with each read system call.
  • SOCK_RAW
    • Provides raw network protocol access.
  • SOCK_RDM
    • Provides a reliable datagram layer that does not guarantee ordering.
  • SOCK_PACKET
    • Obsolete and should not be used in new programs; see packet(7).

Some socket types may not be implemented by all protocol families; for example, SOCK_SEQPACKET is not implemented for AF_INET.

sigc::signal< void > Conexus::Socket::signal_bound (  ) 

References m_signal_bound.

sigc::signal< void > Conexus::Socket::signal_connected (  ) 

References m_signal_connected.

sigc::signal< void > Conexus::Socket::signal_listening (  ) 

References m_signal_listening.

int Conexus::Socket::type (  )  throw ()

Returns the socket type, which defines the communication mechanism of the socket.

References m_type.

size_t Conexus::Socket::write_data ( const Data  data,
Timeout  timeout 
) throw ( write_exception ) [protected, virtual]

size_t Conexus::Socket::writeto ( Address a,
const Data  data,
Timeout  timeout = Timeout(-1) 
) throw ( write_exception ) [virtual]

size_t Conexus::Socket::writeto ( Address a,
const void *  data,
size_t  size,
Timeout  timeout = Timeout(-1) 
) throw ( write_exception ) [virtual]


Friends And Related Function Documentation

enum SocketState [related]

These enumerations are used in the socket class methods, and use is also encouraged in children.

Enumerator:
SOCKET_BOUND  The socket is bound to an interface.
SOCKET_CONNECTED  The socket is connected (TCP).
SOCKET_LISTENING  The socket is listening for connections (TCP).
SOCKET_ACCEPTED  The socket is an accepted connection (TCP).
SOCKET_LAST_STATE 


Member Data Documentation

int Conexus::Socket::m_domain [protected]

Referenced by domain(), and open().

int Conexus::Socket::m_protocol [protected]

Reimplemented in Conexus::LL::Packet.

Referenced by open(), and protocol().

sigc::signal<void> Conexus::Socket::m_signal_bound [protected]

Referenced by set_state_bound(), and signal_bound().

sigc::signal<void> Conexus::Socket::m_signal_connected [protected]

sigc::signal<void> Conexus::Socket::m_signal_listening [protected]

int Conexus::Socket::m_type [protected]

Referenced by open(), and type().


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

Generated on Wed Jul 8 15:51:21 2009 for conexus by doxygen 1.5.8