Commit b22f7d3a authored by Andrea Guzzo's avatar Andrea Guzzo Committed by xant

added a new handler callback to be used when the http connection is being closed

so that in case of connections closed prematurely, the user can clear resources
eventually bound to the connection using the 'connection_param' member of the
mg_connection structure
parent eaa0e26a
......@@ -297,6 +297,7 @@ struct mg_server {
union socket_address lsa; // Listening socket address
struct ll active_connections;
mg_handler_t request_handler;
mg_handler_t http_close_handler;
mg_handler_t error_handler;
mg_handler_t auth_handler;
char *config_options[NUM_OPTIONS];
......@@ -1391,6 +1392,10 @@ static void close_conn(struct connection *conn) {
LINKED_LIST_REMOVE(&conn->link);
closesocket(conn->client_sock);
close_local_endpoint(conn);
if (conn->server->http_close_handler)
conn->server->http_close_handler(&conn->mg_conn);
DBG(("%p %d %d", conn, conn->flags, conn->endpoint_type));
free(conn->request); // It's OK to free(NULL), ditto below
free(conn->path_info);
......@@ -4175,6 +4180,10 @@ void mg_set_request_handler(struct mg_server *server, mg_handler_t handler) {
server->request_handler = handler;
}
void mg_set_http_close_handler(struct mg_server *server, mg_handler_t handler) {
server->http_close_handler = handler;
}
void mg_set_http_error_handler(struct mg_server *server, mg_handler_t handler) {
server->error_handler = handler;
}
......
......@@ -67,6 +67,7 @@ void mg_destroy_server(struct mg_server **);
const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
unsigned int mg_poll_server(struct mg_server *, int milliseconds);
void mg_set_request_handler(struct mg_server *, mg_handler_t);
void mg_set_http_close_handler(struct mg_server *, mg_handler_t);
void mg_set_http_error_handler(struct mg_server *, mg_handler_t);
void mg_set_auth_handler(struct mg_server *, mg_handler_t);
const char **mg_get_valid_option_names(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment