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 ¶ms) |
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 ¶ms) |
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 |
![]() | |
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::cparams & | get_socket_params () const |
rofl::csockaddr & | set_laddr () |
rofl::csockaddr const & | get_laddr () const |
rofl::csockaddr & | set_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 |
![]() | |
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. | |
ciosrv & | operator= (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... | |
![]() | |
virtual | ~csocket_env () |
Destructor. | |
Static Public Member Functions | |
static cparams | get_default_params () |
![]() | |
static csocket * | csocket_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 () |
![]() | |
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::ctimerid & | register_timer (int opaque, const rofl::ctimespec ×pec) |
Installs a new timer to fire in t seconds. More... | |
const rofl::ctimerid & | reset_timer (const rofl::ctimerid &timer_id, const rofl::ctimespec ×pec) |
Resets a running timer of type opaque. More... | |
ctimerid & | restart_timer (rofl::ctimerid &timer_id, int opaque, const rofl::ctimespec ×pec) |
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 | |
![]() | |
enum | socket_type_t { SOCKET_TYPE_UNKNOWN = 0, SOCKET_TYPE_PLAIN = 1, SOCKET_TYPE_OPENSSL = 2 } |
![]() | |
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 |
![]() | |
csocket_env * | socket_env |
enum socket_type_t | socket_type |
int | sd |
csockaddr | laddr |
csockaddr | raddr |
int | domain |
int | type |
int | protocol |
int | backlog |
cparams | socket_params |
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.
csocket_openssl::csocket_openssl | ( | csocket_env * | owner | ) |
Constructor for new empty csocket_impl instances.
owner | socket owning entity implementing interface csocket_impl_owner |
|
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.
|
virtual |
Open socket and connect to peer entity (client side).
This opens a socket and connects to a peer entity.
params | parameters for this socket |
Implements rofl::csocket.
|
protectedvirtual |
Send packets in outgoing queue pout_squeue.
This method transmits all pending packets from the transmission queue pout_squeue.
|
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.
|
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.
|
protectedvirtual |
Socket was closed.
This notification method is called when the socket is closed.
sd | the socket descriptor |
Implements rofl::csocket_env.
|
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.
|
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.
|
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.
|
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.
newsd | the new socket descriptor |
ra | reference to the peer entity's address |
Implements rofl::csocket_env.
|
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.
fd | the socket descriptor |
Implements rofl::csocket_env.
|
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.
fd | the socket descriptor |
Implements rofl::csocket_env.
|
virtual |
Open socket in listening mode (server side).
This opens a socket in listening mode bound to address 'la' with the specified socket parameters.
params | parameters for this socket |
Implements rofl::csocket.
|
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.
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!
mem | cmemory instance to be sent out |
Implements rofl::csocket.