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 ¶ms)=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 ¶ms)=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::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... | |
Static Public Member Functions | |
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 Attributes | |
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 |
Friends | |
std::ostream & | operator<< (std::ostream &os, csocket const &sock) |
Additional Inherited Members | |
![]() | |
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::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. | |
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.
|
inline |
csocket constructor
env | environment for this csocket instance |
|
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.
|
pure 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 |
Implemented in rofl::csocket_plain, and rofl::csocket_openssl.
|
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.
params | parameters for this socket |
Implemented in rofl::csocket_plain, and rofl::csocket_openssl.
|
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.
|
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!
mem | cmemory instance to be sent out |
Implemented in rofl::csocket_plain, and rofl::csocket_openssl.
|
protected |
backlog value for listen() system call
|
protected |
socket domain (PF_INET, PF_UNIX, ...)
|
protected |
local address socket is bound to
|
protected |
socket protocol (TCP, UDP, SCTP, ...)
|
protected |
remote address of peer entity
|
protected |
the socket descriptor
|
protected |
environment of this csocket instance
|
protected |
parameters for a specific socket instance
|
protected |
socket type (plain, ssl, ...)
|
protected |
socket type (SOCK_STREAM, SOCK_DGRAM, ...)