You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.4 KiB

#error Please include <lighttpd/base.h> instead of this file
typedef enum {
/** unused */
/** closed (or "closing") */
/** waiting for new input after first request */
/** after the connect, the request is initialized */
/** loop in the read-request-header until the full header is received */
/** handle in main virtual request */
/** write remaining bytes from raw_out, mainvr finished (or not started) */
} liConnectionState;
typedef struct liConnectionSocketCallbacks liConnectionSocketCallbacks;
typedef struct liConnectionSocket liConnectionSocket;
struct liConnectionSocketCallbacks {
void (*finish)(liConnection *con, gboolean aborted);
struct liConnectionSocket {
gpointer data; /** private data (simple tcp, ssl, ...) */
const liConnectionSocketCallbacks *callbacks;
liStream *raw_in, *raw_out;
struct liConnection {
guint idx; /** index in connection table, -1 if not active */
liServer *srv;
liWorker *wrk;
liServerSocket *srv_sock;
liConnectionSocket con_sock;
liConInfo info;
liConnectionState state;
gboolean response_headers_sent, expect_100_cont, out_has_all_data;
liStream in, out;
liVRequest *mainvr;
liHttpRequestCtx req_parser_ctx;
ev_tstamp ts_started; /* when connection was started, not a (v)request */
/* Keep alive timeout data */
struct {
GList *link;
ev_tstamp timeout;
guint max_idle;
liEventTimer watcher;
} keep_alive_data;
guint keep_alive_requests;
/* I/O read timeout data */
liWaitQueueElem io_timeout_elem;
liJob job_reset;
/* Internal functions */
LI_API liConnection* li_connection_new(liWorker *wrk);
/** Free dead connections */
LI_API void li_connection_free(liConnection *con);
/* close connection (for worker keep-alive timeout) */
LI_API void li_connection_reset(liConnection *con);
/** aborts an active connection, calls all plugin cleanup handlers */
LI_API void li_connection_error(liConnection *con); /* used in worker.c */
LI_API void li_connection_start(liConnection *con, liSocketAddress remote_addr, int s, liServerSocket *srv_sock);
/* public function */
LI_API gchar *li_connection_state_str(liConnectionState state);
/* returns NULL if the vrequest doesn't belong to a liConnection* object */
LI_API liConnection* li_connection_from_vrequest(liVRequest *vr);
/* IO backend stuff (simple tcp, tls implementations) */
/* call after IO send operations if con->out_has_all_data and out queues are empty */
LI_API void li_connection_request_done(liConnection *con);
/* call after successful io
* li_connection_simple_tcp takes care of this for you.
LI_API void li_connection_update_io_timeout(liConnection *con);
/* handles IOStream events for a connection; updates transfered bytes and io timeouts;
* *pcon is needed to handle cases then the connections gets reset while handling io stuff
* NULL == *pcon is ok - it won't update transfered bytes and io timeouts then.
* closes outgoing stream on reading EOF
LI_API void li_connection_simple_tcp(liConnection **pcon, liIOStream *stream, gpointer *context, liIOStreamEvent event);