HomePort
|
Go to the source code of this file.
Data Structures | |
struct | hpd_tcpd_settings |
Settings struct for tcpd. More... | |
Macros | |
#define | HPD_TCPD_SETTINGS_DEFAULT |
Default settings for tcpd. More... | |
Typedefs | |
typedef struct hpd_tcpd_conn | hpd_tcpd_conn_t |
typedef hpd_tcpd_return_t(* | hpd_tcpd_data_f) (hpd_tcpd_t *instance, hpd_tcpd_conn_t *conn, void *ws_ctx, void **conn_ctx, const char *buf, size_t len) |
typedef hpd_tcpd_return_t(* | hpd_tcpd_nodata_f) (hpd_tcpd_t *instance, hpd_tcpd_conn_t *conn, void *ws_ctx, void **conn_ctx) |
typedef enum hpd_tcpd_return | hpd_tcpd_return_t |
typedef struct hpd_tcpd_settings | hpd_tcpd_settings_t |
typedef struct hpd_tcpd | hpd_tcpd_t |
Enumerations | |
enum | hpd_tcpd_return { HPD_TCPD_R_CONTINUE = 0, HPD_TCPD_R_STOP = 1 } |
Functions | |
hpd_error_t | hpd_tcpd_conn_close (hpd_tcpd_conn_t *conn) |
Close a connection, after the remaining data has been sent. More... | |
hpd_error_t | hpd_tcpd_conn_get_ip (hpd_tcpd_conn_t *conn, const char **ip) |
Get the IP address of the client. More... | |
hpd_error_t | hpd_tcpd_conn_keep_open (hpd_tcpd_conn_t *conn) |
Disable timeout on connection. More... | |
hpd_error_t | hpd_tcpd_conn_kill (hpd_tcpd_conn_t *conn) |
Kill and clean up after a connection. More... | |
hpd_error_t | hpd_tcpd_conn_sendf (hpd_tcpd_conn_t *conn, const char *fmt,...) |
Send message on connection. More... | |
hpd_error_t | hpd_tcpd_conn_vsendf (hpd_tcpd_conn_t *conn, const char *fmt, va_list vp) |
Send message on connection. More... | |
hpd_error_t | hpd_tcpd_create (hpd_tcpd_t **tcpd, hpd_tcpd_settings_t *settings, const hpd_module_t *context, hpd_ev_loop_t *loop) |
Create new tcpd instance. More... | |
hpd_error_t | hpd_tcpd_destroy (hpd_tcpd_t *tcpd) |
Destroy tcpd and free used memory. More... | |
hpd_error_t | hpd_tcpd_start (hpd_tcpd_t *tcpd) |
Start the tcpd. More... | |
hpd_error_t | hpd_tcpd_stop (hpd_tcpd_t *tcpd) |
Stop an already running tcpd. More... | |
struct hpd_tcpd_settings |
Settings struct for tcpd.
Please initialise this struct as following, to ensure that all settings have acceptable default values:
The settings hold a series of callbacks of type either data_cb or nodata_cb. Do not expect the string parameter in data callbacks to be null terminated. All data callbacks are called on chunks and therefore may be called multiple times. It is up to the implementer of these callbacks to concatenate the results if needed.
The callbacks are called in the following order:
Notes on the return values of callbacks:
Definition at line 94 of file hpd_tcpd.h.
Data Fields | ||
---|---|---|
size_t | max_data_size | |
hpd_tcpd_nodata_f | on_connect | |
hpd_tcpd_nodata_f | on_disconnect | |
hpd_tcpd_data_f | on_receive | |
hpd_tcpd_port_t | port | Port number. |
int | retry_delay | |
void * | tcpd_ctx | |
int | timeout |
#define HPD_TCPD_SETTINGS_DEFAULT |
Default settings for tcpd.
Use this as:
Definition at line 113 of file hpd_tcpd.h.
typedef struct hpd_tcpd_conn hpd_tcpd_conn_t |
Definition at line 43 of file hpd_tcpd.h.
typedef hpd_tcpd_return_t(* hpd_tcpd_data_f) (hpd_tcpd_t *instance, hpd_tcpd_conn_t *conn, void *ws_ctx, void **conn_ctx, const char *buf, size_t len) |
Definition at line 56 of file hpd_tcpd.h.
typedef hpd_tcpd_return_t(* hpd_tcpd_nodata_f) (hpd_tcpd_t *instance, hpd_tcpd_conn_t *conn, void *ws_ctx, void **conn_ctx) |
Definition at line 54 of file hpd_tcpd.h.
typedef enum hpd_tcpd_return hpd_tcpd_return_t |
typedef struct hpd_tcpd_settings hpd_tcpd_settings_t |
Definition at line 42 of file hpd_tcpd.h.
typedef struct hpd_tcpd hpd_tcpd_t |
Definition at line 41 of file hpd_tcpd.h.
enum hpd_tcpd_return |
Enumerator | |
---|---|
HPD_TCPD_R_CONTINUE | |
HPD_TCPD_R_STOP |
Definition at line 45 of file hpd_tcpd.h.
hpd_error_t hpd_tcpd_conn_close | ( | hpd_tcpd_conn_t * | conn | ) |
Close a connection, after the remaining data has been sent.
This sets the close flag on a connection. The connection will be closed after the remaining messages has been sent. If there is no waiting messages the connection will be closed instantly.
conn | The connection to close |
Definition at line 581 of file tcpd.c.
hpd_error_t hpd_tcpd_conn_get_ip | ( | hpd_tcpd_conn_t * | conn, |
const char ** | ip | ||
) |
hpd_error_t hpd_tcpd_conn_keep_open | ( | hpd_tcpd_conn_t * | conn | ) |
Disable timeout on connection.
Every connection have per default a timeout value, which is set in hpd_tcpd_settings_t. If there is no activity on the connection before the timeout run out the connection is killed. This function disables the timeout, so connections will stay open. A connection will still be killed when the client closes the connection, or kill/close is called.
conn | The connection to keep open |
Definition at line 479 of file tcpd.c.
hpd_error_t hpd_tcpd_conn_kill | ( | hpd_tcpd_conn_t * | conn | ) |
Kill and clean up after a connection.
This function stops the LibEV watchers, closes the socket, and frees the data structures used by a connection.
Note that you should use hpd_tcpd_conn_close for a graceful closure of the connection, where the remaining data is sent.
conn | The connection to kill. |
Definition at line 608 of file tcpd.c.
hpd_error_t hpd_tcpd_conn_sendf | ( | hpd_tcpd_conn_t * | conn, |
const char * | fmt, | ||
... | |||
) |
Send message on connection.
This function is used similary to the standard printf function, with a format string and variable arguments. It calls hpd_tcpd_conn_vsendf() to handle the actually sending, see this for more information.
Connection is kept open for further communication, use hpd_tcpd_conn_close to close it.
conn | Connection to send on |
fmt | Format string |
Definition at line 503 of file tcpd.c.
hpd_error_t hpd_tcpd_conn_vsendf | ( | hpd_tcpd_conn_t * | conn, |
const char * | fmt, | ||
va_list | vp | ||
) |
Send message on connection.
This function is simiar to the standard vprintf function, with a format string and a list of variable arguments.
Note that this function only schedules the message to be send. A send watcher on the event loop will trigger the actual sending, when the connection is ready for it.
Connection is kept open for further communication, use hpd_tcpd_conn_close to close it.
conn | Connection to send on |
fmt | Format string |
arg | List of arguments |
Definition at line 534 of file tcpd.c.
hpd_error_t hpd_tcpd_create | ( | hpd_tcpd_t ** | tcpd, |
hpd_tcpd_settings_t * | settings, | ||
const hpd_module_t * | context, | ||
hpd_ev_loop_t * | loop | ||
) |
Create new tcpd instance.
This creates a new tcpd instances, that can be started with hpd_tcpd_start() and stopped with hpd_tcpd_stop(). The instance should be destroyed with hpd_tcpd_destroy when not longer needed.
settings | The settings for the tcpd. |
loop | The event loop to run tcpd on. |
Definition at line 269 of file tcpd.c.
hpd_error_t hpd_tcpd_destroy | ( | hpd_tcpd_t * | tcpd | ) |
Destroy tcpd and free used memory.
This function destroys and frees all connections are instances. The tcpd should be stopped before destroy to properly close all connections and sockets first.
instance | The tcpd instance to destroy |
Definition at line 297 of file tcpd.c.
hpd_error_t hpd_tcpd_start | ( | hpd_tcpd_t * | tcpd | ) |
Start the tcpd.
The libev-based tcpd is added to an event loop by a call to this function. It is the caller's resposibility to start the event loop.
To stop the tcpd again, one may call hpd_tcpd_stop().
instance | The tcpd instance to start. Created with hpd_tcpd_create(); |
Definition at line 318 of file tcpd.c.
hpd_error_t hpd_tcpd_stop | ( | hpd_tcpd_t * | tcpd | ) |
Stop an already running tcpd.
The tcpd, started with hpd_tcpd_start(), may be stopped by calling this function. It will take the tcpd off the event loop and clean up after it.
This includes killing all connections without waiting for remaining data to be sent.
instance | The tcpd instance to stop. |
Definition at line 428 of file tcpd.c.