From e4a3a726435c280eacd04af930a452e068d86657 Mon Sep 17 00:00:00 2001 From: Lammert Bies Date: Sat, 10 Dec 2016 11:53:41 +0100 Subject: [PATCH] Moved close_all_listening_sockets to own file --- Makefile | 1 + src/libhttp-private.h | 1 + src/libhttp.c | 29 +++++------------------------ 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 76eb9768..cffa080b 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ LIB_SOURCES = src/libhttp.c \ src/httplib_accept_new_connection.c \ src/httplib_check_acl.c \ src/httplib_check_feature.c \ + src/httplib_close_all_listening_sockets.c \ src/httplib_close_connection.c \ src/httplib_close_socket_gracefully.c \ src/httplib_connect_client.c \ diff --git a/src/libhttp-private.h b/src/libhttp-private.h index 9ef2ef60..0ccfe14d 100644 --- a/src/libhttp-private.h +++ b/src/libhttp-private.h @@ -850,6 +850,7 @@ const char * XX_httplib_get_rel_url_at_current_server( const char *uri, const s void XX_httplib_get_system_name( char **sysName ); int XX_httplib_get_uri_type( const char *uri ); int XX_httplib_getreq( struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err ); +void XX_httplib_handle_file_based_request( struct mg_connection *conn, const char *path, struct file *filep ); void XX_httplib_handle_request( struct mg_connection *conn ); int XX_httplib_initialize_ssl( struct mg_context *ctx ); int XX_httplib_is_valid_port( unsigned long port ); diff --git a/src/libhttp.c b/src/libhttp.c index b4b4a702..ac6c4a97 100644 --- a/src/libhttp.c +++ b/src/libhttp.c @@ -1533,8 +1533,6 @@ static int send_static_cache_header(struct mg_connection *conn) { } -static void handle_file_based_request(struct mg_connection *conn, const char *path, struct file *filep); - void XX_httplib_send_http_error( struct mg_connection *conn, int status, const char *fmt, ... ) { char buf[MG_BUF_LEN]; @@ -1603,7 +1601,7 @@ void XX_httplib_send_http_error( struct mg_connection *conn, int status, const c if (page_handler_found) { conn->in_error_handler = 1; - handle_file_based_request(conn, buf, &error_page_file); + XX_httplib_handle_file_based_request(conn, buf, &error_page_file); conn->in_error_handler = 0; return; } @@ -7789,7 +7787,7 @@ void XX_httplib_handle_request( struct mg_connection *conn ) { /* 10. File is handled by a script. */ if (is_script_resource) { - handle_file_based_request(conn, path, &file); + XX_httplib_handle_file_based_request(conn, path, &file); return; } @@ -7878,7 +7876,7 @@ void XX_httplib_handle_request( struct mg_connection *conn ) { } } - handle_file_based_request(conn, path, &file); + XX_httplib_handle_file_based_request(conn, path, &file); #endif /* !defined(NO_FILES) */ #if 0 @@ -7893,7 +7891,7 @@ void XX_httplib_handle_request( struct mg_connection *conn ) { } /* XX_httplib_handle_request */ -static void handle_file_based_request(struct mg_connection *conn, const char *path, struct file *file) { +void XX_httplib_handle_file_based_request( struct mg_connection *conn, const char *path, struct file *file ) { if ( conn == NULL || conn->ctx == NULL ) return; @@ -7911,22 +7909,5 @@ static void handle_file_based_request(struct mg_connection *conn, const char *pa handle_not_modified_static_file_request(conn, file); #endif /* !NO_CACHING */ } else handle_static_file_request(conn, path, file, NULL, NULL); -} - -void XX_httplib_close_all_listening_sockets( struct mg_context *ctx ) { - - unsigned int i; - - if ( ctx == NULL ) return; - - for (i = 0; i < ctx->num_listening_sockets; i++) { - closesocket(ctx->listening_sockets[i].sock); - ctx->listening_sockets[i].sock = INVALID_SOCKET; - } - XX_httplib_free(ctx->listening_sockets); - ctx->listening_sockets = NULL; - XX_httplib_free(ctx->listening_socket_fds); - ctx->listening_socket_fds = NULL; - -} /* XX_close_all_listening_sockets */ +} /* XX_httplib_handle_file_based_request */