Data Fields
vtm_http_srv_cbs Struct Reference

Data Fields

void(* server_ready )(vtm_http_srv *srv, struct vtm_http_srv_opts *opts)
 
void(* worker_init )(struct vtm_http_ctx *ctx)
 
void(* worker_end )(struct vtm_http_ctx *ctx)
 
void(* http_request )(struct vtm_http_ctx *ctx, struct vtm_http_req *req, vtm_http_res *res)
 
void(* ws_connect )(struct vtm_http_ctx *ctx, vtm_ws_con *con)
 
void(* ws_message )(struct vtm_http_ctx *ctx, struct vtm_ws_msg *msg)
 
void(* ws_close )(struct vtm_http_ctx *ctx, vtm_ws_con *con)
 

Detailed Description

Holds the user defined callbacks for an HTTP server.

When a specific callback is not needed, then is MUST be set to NULL.

Unless otherwise stated each callback function is called from a worker-thread. When the server runs in single-threaded mode, the functions are called from the main thread that started the server.

Field Documentation

void(* vtm_http_srv_cbs::server_ready)(vtm_http_srv *srv, struct vtm_http_srv_opts *opts)

This function is called when the HTTP server was successfully created and is ready to accept incoming connections.

The function is called in the same thread that called vtm_http_srv_run()

Parameters
srvthe server that is ready
optsthe options with which the server was startet
void(* vtm_http_srv_cbs::worker_init)(struct vtm_http_ctx *ctx)

This function is is called during startup phase of the HTTP server for each worker thread.

Parameters
srvthe server
ctxthe context with the global HTTP memory object and the per-thread dataset
void(* vtm_http_srv_cbs::worker_end)(struct vtm_http_ctx *ctx)

This function is called during shutdown phase of the HTTP server for each worker thread.

Parameters
srvthe server
ctxthe context with the global HTTP memory object and the per-thread dataset
void(* vtm_http_srv_cbs::http_request)(struct vtm_http_ctx *ctx, struct vtm_http_req *req, vtm_http_res *res)

Called for each HTTP request.

Parameters
ctxthe context
reqthe request details
resresponse handle for sending back the HTTP response
void(* vtm_http_srv_cbs::ws_connect)(struct vtm_http_ctx *ctx, vtm_ws_con *con)

Called for each new WebSocket connection.

Parameters
ctxthe context
conthe client connection object
void(* vtm_http_srv_cbs::ws_message)(struct vtm_http_ctx *ctx, struct vtm_ws_msg *msg)

Called when a new WebSocket message was received.

Parameters
ctxthe context
msgthe received message
void(* vtm_http_srv_cbs::ws_close)(struct vtm_http_ctx *ctx, vtm_ws_con *con)

Called when a WebSocket connection was closed.

Parameters
ctxthe context
conthe connection that was closed