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

A single TLS encrypted 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_impl_owner. More...

#include <csocket_openssl.h>

Public Member Functions

 csocket_openssl (csocket_env *owner)
 Constructor for new empty csocket_impl instances. More...
 
virtual ~csocket_openssl ()
 Destructor.
 
virtual void listen (cparams const &params)
 Open socket in listening mode (server side). More...
 
virtual void accept (cparams const &socket_params, int sd)
 Handle accepted socket descriptor obtained from external listening socket.
 
virtual void connect (cparams const &params)
 Open socket and connect to peer entity (client side). More...
 
virtual void reconnect ()
 Reconnect this socket. More...
 
virtual void close ()
 Closes this socket. More...
 
virtual ssize_t recv (void *buf, size_t count)
 Reads bytes from socket.
 
virtual ssize_t recv (void *buf, size_t count, int flags, rofl::csockaddr &from)
 
virtual void send (cmemory *mem, csockaddr const &dest=csockaddr())
 Store a packet for transmission. More...
 
virtual bool is_established () const
 
virtual bool write_would_block () const
 
void set_capath (std::string const &capath)
 
std::string const & get_capath () const
 
void set_cafile (std::string const &cafile)
 
std::string const & get_cafile () const
 
void set_certfile (std::string const &certfile)
 
std::string const & get_certfile () const
 
void set_keyfile (std::string const &keyfile)
 
std::string const & get_keyfile () const
 
void set_password (std::string const &password)
 
std::string const & get_password () const
 
- Public Member Functions inherited from rofl::csocket
 csocket (csocket_env *env, enum socket_type_t socket_type)
 csocket constructor More...
 
virtual ~csocket ()
 csocket destructor
 
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...
 
- Public Member Functions inherited from rofl::csocket_env
virtual ~csocket_env ()
 Destructor.
 

Static Public Member Functions

static cparams get_default_params ()
 
- Static Public Member Functions inherited from rofl::csocket
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)
 

Protected Member Functions

virtual void handle_accepted (rofl::csocket &socket)
 
virtual void handle_accept_refused (rofl::csocket &socket)
 
virtual void handle_connected (rofl::csocket &socket)
 
virtual void handle_connect_refused (rofl::csocket &socket)
 
virtual void handle_connect_failed (rofl::csocket &socket)
 
virtual void handle_listen (rofl::csocket &socket, int newsd)
 
virtual void handle_closed (rofl::csocket &socket)
 
virtual void handle_read (rofl::csocket &socket)
 
virtual void handle_write (rofl::csocket &socket)
 
virtual void dequeue_packet ()
 
- Protected Member Functions inherited from rofl::ciosrv
ctimer get_next_timer ()
 
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.
 

Friends

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

Additional Inherited Members

- Public Types inherited from rofl::csocket
enum  socket_type_t { SOCKET_TYPE_UNKNOWN = 0, SOCKET_TYPE_PLAIN = 1, SOCKET_TYPE_OPENSSL = 2 }
 
- Static Public Attributes inherited from rofl::csocket
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 inherited from rofl::csocket
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
 

Detailed Description

A single TLS encrypted 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_impl_owner.

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 csocket_impl_owner::handle_accepted() will be called. The socket owner should create a new csocket_impl instance and assigning the new obtained socket descriptor to it.

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

Constructor & Destructor Documentation

csocket_openssl::csocket_openssl ( csocket_env owner)

Constructor for new empty csocket_impl instances.

Parameters
ownersocket owning entity implementing interface csocket_impl_owner

Member Function Documentation

void csocket_openssl::close ( )
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.

Implements rofl::csocket.

void csocket_openssl::connect ( cparams const &  params)
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

Implements rofl::csocket.

void csocket_openssl::dequeue_packet ( )
protectedvirtual

Send packets in outgoing queue pout_squeue.

This method transmits all pending packets from the transmission queue pout_squeue.

void csocket_openssl::handle_accept_refused ( rofl::csocket socket)
protectedvirtual

Accept on socket failed (server mode).

This notification method is called if the accept() operation fails on the socket. It should be overwritten by a derived class if the derived class wants to act upon this condition.

Implements rofl::csocket_env.

void csocket_openssl::handle_accepted ( rofl::csocket socket)
protectedvirtual

Connect on socket succeeded (client mode).

This notification method is called if the connect() operation succeeds on the socket. It should be overwritten by a derived class if this signal is required for further operation.

Implements rofl::csocket_env.

void csocket_openssl::handle_closed ( rofl::csocket socket)
protectedvirtual

Socket was closed.

This notification method is called when the socket is closed.

Parameters
sdthe socket descriptor

Implements rofl::csocket_env.

void csocket_openssl::handle_connect_failed ( rofl::csocket socket)
protectedvirtual

Connect on socket failed (client mode).

This notification method is called if the connect() operation fails on the socket. It should be overwritten by a derived class if the derived class wants to act upon this condition.

Implements rofl::csocket_env.

void csocket_openssl::handle_connect_refused ( rofl::csocket socket)
protectedvirtual

Connect on socket failed (client mode).

This notification method is called if the connect() operation fails on the socket. It should be overwritten by a derived class if the derived class wants to act upon this condition.

Implements rofl::csocket_env.

void csocket_openssl::handle_connected ( rofl::csocket socket)
protectedvirtual

Connect on socket succeeded (client mode).

This notification method is called if the connect() operation succeeds on the socket. It should be overwritten by a derived class if this signal is required for further operation.

Implements rofl::csocket_env.

void csocket_openssl::handle_listen ( rofl::csocket socket,
int  newsd 
)
protectedvirtual

A new incoming connection was accepted (listening mode).

This notification method is called upon receipt of a new incoming connection request. It should be overwritten by a derived class for creation of a new instance or direct handling.

Parameters
newsdthe new socket descriptor
rareference to the peer entity's address

Implements rofl::csocket_env.

void csocket_openssl::handle_read ( rofl::csocket socket)
protectedvirtual

Read data from socket.

This notification method is called from within csocket_impl::handle_revent(). A derived class should read data from the socket. This method must be overwritten by a derived class.

Parameters
fdthe socket descriptor

Implements rofl::csocket_env.

void csocket_openssl::handle_write ( rofl::csocket socket)
protectedvirtual

Write data to socket.

This notification method is called from within csocket_impl::handle_revent(). A derived class should write data to the socket. This method must be overwritten by a derived class.

Parameters
fdthe socket descriptor

Implements rofl::csocket_env.

void csocket_openssl::listen ( cparams const &  params)
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

Implements rofl::csocket.

void csocket_openssl::reconnect ( )
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.

Implements rofl::csocket.

void csocket_openssl::send ( cmemory mem,
csockaddr const &  dest = csockaddr() 
)
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

Implements rofl::csocket.


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