Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
rofl::csocket Class Referenceabstract

A single socket. More...

#include <csocket.h>

Public Types

enum  socket_type_t { SOCKET_TYPE_UNKNOWN = 0, SOCKET_TYPE_PLAIN = 1, SOCKET_TYPE_OPENSSL = 2 }
 

Public Member Functions

 csocket (csocket_env *env, enum socket_type_t socket_type)
 csocket constructor More...
 
virtual ~csocket ()
 csocket destructor
 
virtual void listen (const rofl::cparams &params)=0
 Open socket in listening mode (server side). More...
 
virtual void accept (const rofl::cparams &socket_params, int sd)=0
 Handle accepted socket descriptor obtained from external listening socket.
 
virtual void connect (const rofl::cparams &params)=0
 Open socket and connect to peer entity (client side). More...
 
virtual void reconnect ()=0
 Reconnect this socket. More...
 
virtual void close ()=0
 Closes this socket. More...
 
virtual ssize_t recv (void *buf, size_t count)=0
 Reads bytes from socket.
 
virtual ssize_t recv (void *buf, size_t count, int flags, rofl::csockaddr &from)=0
 
virtual void send (cmemory *mem, rofl::csockaddr const &dest=rofl::csockaddr())=0
 Store a packet for transmission. More...
 
virtual bool is_established () const =0
 
virtual bool write_would_block () const =0
 
int get_sd () const
 
enum rofl::csocket::socket_type_t get_socket_type () const
 
const rofl::cparamsget_socket_params () const
 
rofl::csockaddrset_laddr ()
 
rofl::csockaddr const & get_laddr () const
 
rofl::csockaddrset_raddr ()
 
rofl::csockaddr const & get_raddr () const
 
void set_domain (int domain)
 
int get_domain () const
 
void set_type (int type)
 
int get_type () const
 
void set_protocol (int protocol)
 
int get_protocol () const
 
- Public Member Functions inherited from rofl::ciosrv
 ciosrv (pthread_t tid=0)
 Initializes all structures for this ciosrv object.
 
virtual ~ciosrv ()
 Deallocates resources for this ciosrv object.
 
 ciosrv (const ciosrv &iosrv)
 Initializes all structures for this ciosrv object.
 
ciosrvoperator= (const ciosrv &iosrv)
 
void notify (const cevent &event)
 Sends a notification to this ciosrv instance. More...
 
pthread_t get_thread_id () const
 Returns thread-id of local thread. More...
 

Static Public Member Functions

static csocketcsocket_factory (enum socket_type_t socket_type, csocket_env *owner)
 
static cparams get_default_params (enum socket_type_t socket_type)
 
static bool supports_socket_type (enum socket_type_t socket_type)
 

Static Public Attributes

static std::string const PARAM_KEY_DO_RECONNECT
 
static std::string const PARAM_KEY_REMOTE_HOSTNAME
 
static std::string const PARAM_KEY_REMOTE_PORT
 
static std::string const PARAM_KEY_LOCAL_HOSTNAME
 
static std::string const PARAM_KEY_LOCAL_PORT
 
static std::string const PARAM_KEY_DOMAIN
 
static std::string const PARAM_KEY_TYPE
 
static std::string const PARAM_KEY_PROTOCOL
 
static std::string const PARAM_DOMAIN_VALUE_INET_ANY
 
static std::string const PARAM_DOMAIN_VALUE_INET
 
static std::string const PARAM_DOMAIN_VALUE_INET6
 
static std::string const PARAM_TYPE_VALUE_STREAM
 
static std::string const PARAM_TYPE_VALUE_DGRAM
 
static std::string const PARAM_PROTOCOL_VALUE_TCP
 
static std::string const PARAM_PROTOCOL_VALUE_UDP
 
static std::string const PARAM_SSL_KEY_CA_PATH
 
static std::string const PARAM_SSL_KEY_CA_FILE
 
static std::string const PARAM_SSL_KEY_CERT
 
static std::string const PARAM_SSL_KEY_PRIVATE_KEY
 
static std::string const PARAM_SSL_KEY_PRIVATE_KEY_PASSWORD
 
static std::string const PARAM_SSL_KEY_VERIFY_MODE
 
static std::string const PARAM_SSL_KEY_VERIFY_DEPTH
 
static std::string const PARAM_SSL_KEY_CIPHERS
 

Protected Attributes

csocket_envsocket_env
 
enum socket_type_t socket_type
 
int sd
 
csockaddr laddr
 
csockaddr raddr
 
int domain
 
int type
 
int protocol
 
int backlog
 
cparams socket_params
 

Friends

std::ostream & operator<< (std::ostream &os, csocket const &sock)
 

Additional Inherited Members

- Protected Member Functions inherited from rofl::ciosrv
ctimer get_next_timer ()
 
virtual void handle_event (const rofl::cevent &event)
 Handler for event notifications using cevent instances. More...
 
virtual void handle_revent (int fd)
 Handler for read events on file descriptors. More...
 
virtual void handle_wevent (int fd)
 Handler for write events on file descriptors. More...
 
virtual void handle_xevent (int fd)
 Handler for exceptions on file descriptors. More...
 
virtual void handle_timeout (int opaque, void *data=(void *) 0)
 Handler for timer events. More...
 
void register_filedesc_r (int fd)
 Registers a file descriptor for read events. More...
 
void deregister_filedesc_r (int fd)
 Deregisters a file descriptor from read events. More...
 
void register_filedesc_w (int fd)
 Registers a file descriptor for write events. More...
 
void deregister_filedesc_w (int fd)
 Deregisters a file descriptor from write events. More...
 
const rofl::ctimeridregister_timer (int opaque, const rofl::ctimespec &timespec)
 Installs a new timer to fire in t seconds. More...
 
const rofl::ctimeridreset_timer (const rofl::ctimerid &timer_id, const rofl::ctimespec &timespec)
 Resets a running timer of type opaque. More...
 
ctimeridrestart_timer (rofl::ctimerid &timer_id, int opaque, const rofl::ctimespec &timespec)
 Resets an existing or creates a new timer. More...
 
bool pending_timer (const rofl::ctimerid &timer_id)
 Checks for a pending timer of type opaque. More...
 
void cancel_timer (const rofl::ctimerid &timer_id)
 Cancels a pending timer. More...
 
void cancel_all_timers ()
 Cancels all pending timers of this instance.
 
void cancel_all_events ()
 Cancels all pending events of this instance.
 

Detailed Description

A single socket.

This class provides basic support for socket based communication. Its aim is to encapsulate functionality for establishing a socket in active and passive mode. For using a socket, the owning class must implement the interface defined in csocket_env.

The socket is set to non-blocking mode, thus it does not block indefinitely during read or write operations, rather it returns control to the calling entity asap.

For listening sockets, method rofl::csocket_env::handle_accepted() will be called. The socket owner should create a new csocket instance and assigning the new obtained socket descriptor to it.

See Also
csocket_env
Inheritance diagram for rofl::csocket:
rofl::ciosrv rofl::ctimer_env rofl::csocket_openssl rofl::csocket_plain

Constructor & Destructor Documentation

rofl::csocket::csocket ( csocket_env env,
enum socket_type_t  socket_type 
)
inline

csocket constructor

Parameters
envenvironment for this csocket instance

Member Function Documentation

virtual void rofl::csocket::close ( )
pure virtual

Closes this socket.

Calls the shutdown() system call and closes the socket. Also deletes all packets queued in pout_squeue for transmission. After calling cclose() it is safe to call caopen() or cpopen() again.

Implemented in rofl::csocket_plain, and rofl::csocket_openssl.

virtual void rofl::csocket::connect ( const rofl::cparams params)
pure virtual

Open socket and connect to peer entity (client side).

This opens a socket and connects to a peer entity.

Parameters
paramsparameters for this socket

Implemented in rofl::csocket_plain, and rofl::csocket_openssl.

virtual void rofl::csocket::listen ( const rofl::cparams params)
pure virtual

Open socket in listening mode (server side).

This opens a socket in listening mode bound to address 'la' with the specified socket parameters.

Parameters
paramsparameters for this socket

Implemented in rofl::csocket_plain, and rofl::csocket_openssl.

virtual void rofl::csocket::reconnect ( )
pure virtual

Reconnect this socket.

Reconnects this socket to the previously connected peer. The socket must be an active one, i.e. we have all data required for calling ::connect() towards the peer. A passive socket is throwing an exception of type eSocketError.

Implemented in rofl::csocket_plain, and rofl::csocket_openssl.

virtual void rofl::csocket::send ( cmemory mem,
rofl::csockaddr const &  dest = rofl::csockaddr() 
)
pure virtual

Store a packet for transmission.

This method stores the packet in the outgoing queue for transmission. If the socket is not connected and not a raw socket, the packet will be deleted and thus dropped. After pushing the packet pointer onto the outgoing queue, the method registers the socket descriptor for a write operation and returns, giving the calling entity back control.

csocket will call mem's destructor in order to remove the packet from heap once it has been sent out. Make sure, that mem is pointing to a heap allocated cmemory instance!

Parameters
memcmemory instance to be sent out

Implemented in rofl::csocket_plain, and rofl::csocket_openssl.

Member Data Documentation

int rofl::csocket::backlog
protected

backlog value for listen() system call

int rofl::csocket::domain
protected

socket domain (PF_INET, PF_UNIX, ...)

csockaddr rofl::csocket::laddr
protected

local address socket is bound to

int rofl::csocket::protocol
protected

socket protocol (TCP, UDP, SCTP, ...)

csockaddr rofl::csocket::raddr
protected

remote address of peer entity

int rofl::csocket::sd
protected

the socket descriptor

csocket_env* rofl::csocket::socket_env
protected

environment of this csocket instance

cparams rofl::csocket::socket_params
protected

parameters for a specific socket instance

enum socket_type_t rofl::csocket::socket_type
protected

socket type (plain, ssl, ...)

int rofl::csocket::type
protected

socket type (SOCK_STREAM, SOCK_DGRAM, ...)


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