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

A single unencrypted 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_plain_owner. More...

#include <csocket_plain.h>

Classes

struct  pout_entry_t
 

Public Member Functions

 csocket_plain (csocket_env *owner)
 Constructor for new empty csocket_plain instances. More...
 
virtual ~csocket_plain ()
 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, rofl::csockaddr const &dest=rofl::csockaddr())
 Store a packet for transmission. More...
 
virtual bool is_established () const
 
virtual bool write_would_block () const
 
std::string str () 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...
 

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 listen (const csockaddr &la, int domain=PF_INET, int type=SOCK_STREAM, int protocol=0, int backlog=10, std::string devname=std::string(""))
 Open socket in listening mode (server side). More...
 
virtual void connect (csockaddr ra, csockaddr la=csockaddr(), int domain=PF_INET, int type=SOCK_STREAM, int protocol=0, bool do_reconnect=false)
 Open socket and connect to peer entity (client side). More...
 
virtual void handle_accepted ()
 
virtual void handle_accept_refused ()
 
virtual void handle_connected ()
 
virtual void handle_conn_refused ()
 
virtual void handle_conn_failed ()
 
virtual void handle_listen (int newsd)
 
virtual void handle_closed ()
 
virtual void handle_read ()
 
virtual void handle_write ()
 
virtual void dequeue_packet ()
 
- Protected Member Functions inherited from rofl::ciosrv
ctimer get_next_timer ()
 
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.
 

Protected Attributes

bool had_short_write
 
pthread_rwlock_t pout_squeue_lock
 
std::list< pout_entry_tpout_squeue
 
- 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
 

Static Protected Attributes

static bool const PARAM_DEFAULT_VALUE_DO_RECONNECT = false
 
static std::string const PARAM_DEFAULT_VALUE_REMOTE_HOSTNAME
 
static std::string const PARAM_DEFAULT_VALUE_REMOTE_PORT
 
static std::string const PARAM_DEFAULT_VALUE_LOCAL_HOSTNAME
 
static std::string const PARAM_DEFAULT_VALUE_LOCAL_PORT
 
static std::string const PARAM_DEFAULT_VALUE_DOMAIN
 
static std::string const PARAM_DEFAULT_VALUE_TYPE
 
static std::string const PARAM_DEFAULT_VALUE_PROTOCOL
 

Friends

std::ostream & operator<< (std::ostream &os, csocket_plain 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
 

Detailed Description

A single unencrypted 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_plain_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_plain_owner::handle_accepted() will be called. The socket owner should create a new csocket_plain instance and assigning the new obtained socket descriptor to it.

See Also
csocket_plain_owner
Inheritance diagram for rofl::csocket_plain:
rofl::csocket rofl::ciosrv rofl::ctimer_env

Constructor & Destructor Documentation

csocket_plain::csocket_plain ( csocket_env owner)

Constructor for new empty csocket_plain instances.

Parameters
ownersocket owning entity implementing interface csocket_plain_owner

Member Function Documentation

void csocket_plain::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_plain::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_plain::connect ( csockaddr  ra,
csockaddr  la = csockaddr(),
int  domain = PF_INET,
int  type = SOCK_STREAM,
int  protocol = 0,
bool  do_reconnect = false 
)
protectedvirtual

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

This opens a socket and connects to a peer entity.

Parameters
raremote address of peer entity to connect to
laaddress used for binding socket locally
domainsocket domain
typesocket type
protocolsocket protocol
Exceptions
eSocketConnectFailedthrown if the connect() operation failed finally
eSocketErrorthrown for all other socket related errors
void csocket_plain::dequeue_packet ( )
protectedvirtual

Send packets in outgoing queue pout_squeue.

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

virtual void rofl::csocket_plain::handle_accept_refused ( )
inlineprotectedvirtual

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.

virtual void rofl::csocket_plain::handle_accepted ( )
inlineprotectedvirtual

Accept on socket succeeded (server 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.

virtual void rofl::csocket_plain::handle_closed ( )
inlineprotectedvirtual

Socket was closed.

This notification method is called when the socket is closed.

Parameters
sdthe socket descriptor
virtual void rofl::csocket_plain::handle_conn_failed ( )
inlineprotectedvirtual

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.

virtual void rofl::csocket_plain::handle_conn_refused ( )
inlineprotectedvirtual

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.

virtual void rofl::csocket_plain::handle_connected ( )
inlineprotectedvirtual

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.

virtual void rofl::csocket_plain::handle_listen ( int  newsd)
inlineprotectedvirtual

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
virtual void rofl::csocket_plain::handle_read ( )
inlineprotectedvirtual

Read data from socket.

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

Parameters
fdthe socket descriptor
virtual void rofl::csocket_plain::handle_write ( )
inlineprotectedvirtual

Write data to socket.

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

Parameters
fdthe socket descriptor
void csocket_plain::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_plain::listen ( const csockaddr la,
int  domain = PF_INET,
int  type = SOCK_STREAM,
int  protocol = 0,
int  backlog = 10,
std::string  devname = std::string("") 
)
protectedvirtual

Open socket in listening mode (server side).

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

Parameters
lathe local address for binding this socket
domainsocket domain
typesocket type
protocolsocket protocol
backlogbacklog value
Exceptions
eSocketListenFailedfailure in listen() system call
eSocketAddressInUsebind error while calling bind()
eSocketErrorthrown for all other socket related errors
void csocket_plain::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_plain::send ( cmemory mem,
rofl::csockaddr const &  dest = rofl::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_plain 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.

Member Data Documentation

std::list<pout_entry_t> rofl::csocket_plain::pout_squeue
protected

queue of outgoing packets

pthread_rwlock_t rofl::csocket_plain::pout_squeue_lock
protected

rwlock for access to pout_squeue


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