libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Functions
Listen Point. Allows to listen at several ports with different protocols, and to add new protocols.

Data Structures

struct  onion_listen_point_t
 Stored common data for each listen point: address, port, protocol status data... More...

Functions

onion_listen_pointonion_listen_point_t::onion_listen_point_new ()
 Creates an empty listen point.
void onion_listen_point_t::onion_listen_point_free (onion_listen_point *op)
 Free and closes the listen point.
int onion_listen_point_t::onion_listen_point_accept (onion_listen_point *op)
 Called when a new connection appears on the listenfd.
void onion_listen_point_t::onion_listen_point_listen_stop (onion_listen_point *op)
 Stops listening the listen point.
int onion_listen_point_t::onion_listen_point_listen (onion_listen_point *op)
 Starts the listening phase for this listen point for sockets.
static int onion_listen_point_t::onion_listen_point_read_ready (onion_request *req)
 This listen point has data ready to read; calls the listen_point read_ready.
int onion_listen_point_t::onion_listen_point_request_init_from_socket (onion_request *req)
 Default implementation that initializes the request from a socket.
void onion_listen_point_t::onion_listen_point_request_close_socket (onion_request *oc)
 Default implementation that just closes the connection.

Detailed Description

Function Documentation

int onion_listen_point_accept ( onion_listen_point op)

Called when a new connection appears on the listenfd.

When the new connection appears, creates the request and adds it to the pollers.

It returns always 1 as any <0 would detach from the poller and close the listen point, and not accepting a request does not mean the connection point is corrupted. If a connection point may become corrupted should be the connection point itself who detaches from the poller.

Parameters
opThe listen point from where the request must be built
Returns
1 always. The poller needs one to keep listening for connections.

References onion_request_t::connection, onion_request_t::fd, onion_request_t::listen_point, ONION_ERROR, onion_listen_point_t::onion_listen_point_read_ready(), onion_poller_t::onion_poller_add(), onion_poller_slot_t::onion_poller_slot_new(), onion_poller_slot_t::onion_poller_slot_set_shutdown(), onion_poller_slot_t::onion_poller_slot_set_timeout(), onion_request_t::onion_request_free(), onion_request_t::onion_request_new(), onion_t::poller, onion_listen_point_t::server, and onion_t::timeout.

Referenced by onion_listen().

void onion_listen_point_free ( onion_listen_point op)

Free and closes the listen point.

Calls the custom listen_stop mathod, and frees all common structures.

Parameters
opthe listen point

References onion_listen_point_t::free_user_data, onion_listen_point_t::hostname, onion_listen_point_t::listenfd, ONION_DEBUG, onion_listen_point_t::onion_listen_point_listen_stop(), onion_low_free(), and onion_listen_point_t::port.

Referenced by onion_free(), onion_https_t::onion_https_new(), and onion_set_certificate_va().

int onion_listen_point_listen ( onion_listen_point op)

Starts the listening phase for this listen point for sockets.

Default listen implementation that listens on sockets. Opens sockets and setup everything properly.

Parameters
opThe listen point
Returns
0 if ok, !=0 some error; it will be the errno value.

References onion_t::flags, onion_listen_point_t::hostname, onion_listen_point_t::listen, onion_listen_point_t::listenfd, O_SYSTEMD, ONION_DEBUG, ONION_ERROR, ONION_WARNING, onion_listen_point_t::port, onion_listen_point_t::server, and SOCK_CLOEXEC.

Referenced by onion_listen().

void onion_listen_point_listen_stop ( onion_listen_point op)

Stops listening the listen point.

Calls the op->listen_stop if any, and if not just closes the listenfd.

Parameters
opThe listen point

References onion_listen_point_t::listen_stop, and onion_listen_point_t::listenfd.

Referenced by onion_listen_point_t::onion_listen_point_free(), and onion_listen_stop().

onion_listen_point * onion_listen_point_new ( )

Creates an empty listen point.

Called by real listen points to ease the creation.

Returns
An alloc'ed onion_listen_point pointer

References onion_low_calloc().

Referenced by onion_http_t::onion_http_new(), and onion_https_t::onion_https_new().

static int onion_listen_point_read_ready ( onion_request req)

This listen point has data ready to read; calls the listen_point read_ready.

Parameters
reqThe request with data ready
Returns
<0 in case of error and request connection should be closed.

References onion_request_t::connection, onion_request_t::listen_point, OCS_INTERNAL_ERROR, ONION_ERROR, and onion_listen_point_t::read_ready.

Referenced by onion_listen_point_t::onion_listen_point_accept().

void onion_listen_point_request_close_socket ( onion_request oc)
int onion_listen_point_request_init_from_socket ( onion_request req)

Default implementation that initializes the request from a socket.

Accepts the connection and initializes it.

Parameters
reqRequest to initialize
Returns
<0 if error opening the connection

Follows default socket implementation. If your protocol is socket based, just use it.

Thanks to Andrew Victor for pointing that without this client may block HTTPS connection. It could lead to DoS if occupies all connections.

References accept4, onion_request_t::cli_addr, onion_request_t::cli_len, onion_request_t::connection, onion_request_t::fd, onion_request_t::listen_point, onion_listen_point_t::listenfd, ONION_DEBUG, ONION_DEBUG0, ONION_ERROR, onion_listen_point_t::onion_listen_point_request_close_socket(), onion_listen_point_t::server, SOCK_CLOEXEC, and onion_t::timeout.

Referenced by onion_https_t::onion_https_request_init(), and onion_request_t::onion_request_new().