http: I caught an http listener lingering on shutdown. Clean them up more correctly. Possible progress on #108.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 30m38s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 30m38s
This commit is contained in:
parent
0e4fda54e9
commit
40cf519492
32
src/http.c
32
src/http.c
@ -785,8 +785,25 @@ void tf_http_add_handler(tf_http_t* http, const char* pattern, tf_http_callback_
|
|||||||
static void _http_free_listener_on_close(uv_handle_t* handle)
|
static void _http_free_listener_on_close(uv_handle_t* handle)
|
||||||
{
|
{
|
||||||
tf_http_listener_t* listener = handle->data;
|
tf_http_listener_t* listener = handle->data;
|
||||||
|
tf_http_t* http = listener->http;
|
||||||
|
for (int i = 0; i < http->listeners_count; i++)
|
||||||
|
{
|
||||||
|
if (http->listeners[i] == listener)
|
||||||
|
{
|
||||||
|
http->listeners[i] = http->listeners[http->listeners_count - 1];
|
||||||
|
http->listeners_count--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
handle->data = NULL;
|
handle->data = NULL;
|
||||||
tf_free(listener);
|
tf_free(listener);
|
||||||
|
|
||||||
|
if (!http->listeners_count)
|
||||||
|
{
|
||||||
|
tf_free(http->listeners);
|
||||||
|
http->listeners = NULL;
|
||||||
|
tf_http_destroy(http);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tf_http_destroy(tf_http_t* http)
|
void tf_http_destroy(tf_http_t* http)
|
||||||
@ -812,6 +829,10 @@ void tf_http_destroy(tf_http_t* http)
|
|||||||
listener->cleanup(listener->user_data);
|
listener->cleanup(listener->user_data);
|
||||||
listener->cleanup = NULL;
|
listener->cleanup = NULL;
|
||||||
}
|
}
|
||||||
|
if (listener->tcp.data && !uv_is_closing((uv_handle_t*)&listener->tcp))
|
||||||
|
{
|
||||||
|
uv_close((uv_handle_t*)&listener->tcp, _http_free_listener_on_close);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < http->handlers_count; i++)
|
for (int i = 0; i < http->handlers_count; i++)
|
||||||
@ -829,20 +850,11 @@ void tf_http_destroy(tf_http_t* http)
|
|||||||
http->user_data = NULL;
|
http->user_data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (http->connections_count == 0)
|
if (http->connections_count == 0 && http->listeners_count == 0)
|
||||||
{
|
{
|
||||||
tf_free(http->connections);
|
tf_free(http->connections);
|
||||||
http->connections = NULL;
|
http->connections = NULL;
|
||||||
|
|
||||||
for (int i = 0; i < http->listeners_count; i++)
|
|
||||||
{
|
|
||||||
tf_http_listener_t* listener = http->listeners[i];
|
|
||||||
uv_close((uv_handle_t*)&listener->tcp, _http_free_listener_on_close);
|
|
||||||
}
|
|
||||||
tf_free(http->listeners);
|
|
||||||
http->listeners = NULL;
|
|
||||||
http->listeners_count = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < http->handlers_count; i++)
|
for (int i = 0; i < http->handlers_count; i++)
|
||||||
{
|
{
|
||||||
if (http->handlers[i].pattern)
|
if (http->handlers[i].pattern)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user