Commit 940b65e4 authored by Sergey Lyubka's avatar Sergey Lyubka

Merge pull request #320 from xant/upstream

added a new handler callback to be used when the http connection is being closed
parents eaa0e26a b22f7d3a
...@@ -297,6 +297,7 @@ struct mg_server { ...@@ -297,6 +297,7 @@ struct mg_server {
union socket_address lsa; // Listening socket address union socket_address lsa; // Listening socket address
struct ll active_connections; struct ll active_connections;
mg_handler_t request_handler; mg_handler_t request_handler;
mg_handler_t http_close_handler;
mg_handler_t error_handler; mg_handler_t error_handler;
mg_handler_t auth_handler; mg_handler_t auth_handler;
char *config_options[NUM_OPTIONS]; char *config_options[NUM_OPTIONS];
...@@ -1391,6 +1392,10 @@ static void close_conn(struct connection *conn) { ...@@ -1391,6 +1392,10 @@ static void close_conn(struct connection *conn) {
LINKED_LIST_REMOVE(&conn->link); LINKED_LIST_REMOVE(&conn->link);
closesocket(conn->client_sock); closesocket(conn->client_sock);
close_local_endpoint(conn); 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)); DBG(("%p %d %d", conn, conn->flags, conn->endpoint_type));
free(conn->request); // It's OK to free(NULL), ditto below free(conn->request); // It's OK to free(NULL), ditto below
free(conn->path_info); free(conn->path_info);
...@@ -4175,6 +4180,10 @@ void mg_set_request_handler(struct mg_server *server, mg_handler_t handler) { ...@@ -4175,6 +4180,10 @@ void mg_set_request_handler(struct mg_server *server, mg_handler_t handler) {
server->request_handler = 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) { void mg_set_http_error_handler(struct mg_server *server, mg_handler_t handler) {
server->error_handler = handler; server->error_handler = handler;
} }
......
...@@ -67,6 +67,7 @@ void mg_destroy_server(struct mg_server **); ...@@ -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); const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
unsigned int mg_poll_server(struct mg_server *, int milliseconds); unsigned int mg_poll_server(struct mg_server *, int milliseconds);
void mg_set_request_handler(struct mg_server *, mg_handler_t); 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_http_error_handler(struct mg_server *, mg_handler_t);
void mg_set_auth_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); 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