Conexus::Socket Class Reference
[Conexus]

#include <conexus/socket.h>

Inheritance diagram for Conexus::Socket:

Inheritance graph
[legend]
List of all members.

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


Public Types

typedef enum Conexus::Socket::SocketState SocketState
 These enumerations are used in the socket class methods, and use is also encouraged in children.
enum  SocketState {
  BOUND = LASTENDPOINTSTATE<<1, CONNECTED = LASTENDPOINTSTATE<<2, LISTENING = LASTENDPOINTSTATE<<3, ACCEPTED = LASTENDPOINTSTATE<<4,
  LASTSOCKETSTATE = ACCEPTED
}
 These enumerations are used in the socket class methods, and use is also encouraged in children. More...

Public 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 open () throw (open_error)
 Creates the socket; similar to the socket() call.
virtual void close (bool force=false) throw (close_error)
 Overloads the parent FileDescriptor class to ensure that the final state clears the BOUND, CONNECTED, LISTENING and ACCEPTED flags.
virtual void bind () throw (bind_error)
 Binding without an address (autobinding) is a child specific action.
virtual void bind (Conexus::Address &a) throw (bind_error)
 Binds the socket to the provided address.
virtual void connect () throw (connect_error)
 Connecting without an address (autoconnecting) is a child specific action.
virtual void connect (Address &a) throw (connect_error)
 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 sd () throw ()
 Returns the socket descriptor; alias for the parent accessor fd().
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 Data read (size_t s=0) throw (read_error)
virtual ssize_t write (const void *data, size_t size, IOMethod block=BLOCK) throw (write_error)
virtual ssize_t writeto (Address &a, const void *data, size_t size) throw (write_error)
virtual void set_option (int option, bool b)
template<typename T>
void set_option (int level, int optname, T &value)
template<typename T>
void option (int level, int optname, T &value)
virtual void change_state (long states) throw (state_error)
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 ()
virtual const std::string & object_type ()

Protected Member Functions

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 ()

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


Member Enumeration Documentation

enum Conexus::Socket::SocketState
 

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

Enumerator:
BOUND  The socket is bound to an interface.
CONNECTED  The socket is connected (TCP).
LISTENING  The socket is listening for connections (TCP).
ACCEPTED  The socket is an accepted connection (TCP).


Member Function Documentation

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

Binds the socket to the provided 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::UDPPoset, and Conexus::IPv6::UDPPoset.

void Conexus::Socket::bind  )  throw (bind_error) [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 error condition. Therefore children should modify this behavior if they wish to provide autobinding.

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

void Conexus::Socket::connect Address a  )  throw (connect_error) [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.

void Conexus::Socket::connect  )  throw (connect_error) [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 error condition. Therefore children should modify this behavior if they wish to provide autoconnection.

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

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.

void Conexus::Socket::open  )  throw (open_error) [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.

void Conexus::Socket::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.

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)

void Conexus::Socket::set_type int   )  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.


The documentation for this class was generated from the following files:
Generated on Sat Aug 26 17:34:58 2006 by  doxygen 1.4.6