forked from cory/tildefriends
Stop leaking the TLS context.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4802 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
22
src/http.c
22
src/http.c
@ -77,6 +77,8 @@ typedef struct _tf_http_listener_t
|
||||
tf_http_t* http;
|
||||
tf_tls_context_t* tls;
|
||||
uv_tcp_t tcp;
|
||||
tf_http_cleanup_t* cleanup;
|
||||
void* user_data;
|
||||
} tf_http_listener_t;
|
||||
|
||||
typedef struct _tf_http_t
|
||||
@ -606,10 +608,17 @@ static void _http_on_connection(uv_stream_t* stream, int status)
|
||||
http->connections[http->connections_count++] = connection;
|
||||
}
|
||||
|
||||
int tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls)
|
||||
int tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls, tf_http_cleanup_t* cleanup, void* user_data)
|
||||
{
|
||||
tf_http_listener_t* listener = tf_malloc(sizeof(tf_http_listener_t));
|
||||
*listener = (tf_http_listener_t) { .http = http, .tls = tls, .tcp = { .data = listener } };
|
||||
*listener = (tf_http_listener_t)
|
||||
{
|
||||
.http = http,
|
||||
.tls = tls,
|
||||
.tcp = { .data = listener },
|
||||
.cleanup = cleanup,
|
||||
.user_data = user_data,
|
||||
};
|
||||
int r = uv_tcp_init(http->loop, &listener->tcp);
|
||||
if (r)
|
||||
{
|
||||
@ -651,7 +660,7 @@ int tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls)
|
||||
|
||||
if (r == 0)
|
||||
{
|
||||
http->listeners = tf_realloc(http->listeners, sizeof(tf_http_listener_t*) * (http->listeners_count + 1));
|
||||
http->listeners = tf_resize_vec(http->listeners, sizeof(tf_http_listener_t*) * (http->listeners_count + 1));
|
||||
http->listeners[http->listeners_count++] = listener;
|
||||
}
|
||||
return assigned_port;
|
||||
@ -680,7 +689,12 @@ void tf_http_destroy(tf_http_t* http)
|
||||
{
|
||||
for (int i = 0; i < http->listeners_count; i++)
|
||||
{
|
||||
uv_close((uv_handle_t*)&http->listeners[i]->tcp, _http_free_listener_on_close);
|
||||
tf_http_listener_t* listener = http->listeners[i];
|
||||
if (listener->cleanup)
|
||||
{
|
||||
listener->cleanup(listener->user_data);
|
||||
}
|
||||
uv_close((uv_handle_t*)&listener->tcp, _http_free_listener_on_close);
|
||||
}
|
||||
tf_free(http->listeners);
|
||||
http->listeners = NULL;
|
||||
|
Reference in New Issue
Block a user