One less dynamic http allocation. Also one less crash.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4689 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
9e7c860414
commit
86046e52f0
13
src/http.c
13
src/http.c
@ -19,6 +19,7 @@ typedef struct _tf_http_connection_t
|
||||
{
|
||||
tf_http_t* http;
|
||||
uv_tcp_t tcp;
|
||||
uv_shutdown_t shutdown;
|
||||
|
||||
const char* method;
|
||||
const char* path;
|
||||
@ -295,7 +296,7 @@ static void _http_on_connection(uv_stream_t* stream, int status)
|
||||
return;
|
||||
}
|
||||
|
||||
http->connections = tf_realloc(http->connections, http->connections_count + 1);
|
||||
http->connections = tf_realloc(http->connections, sizeof(tf_http_connection_t*) * (http->connections_count + 1));
|
||||
http->connections[http->connections_count++] = connection;
|
||||
}
|
||||
|
||||
@ -403,7 +404,7 @@ static const char* _http_status_text(int status)
|
||||
|
||||
static void _http_on_shutdown(uv_shutdown_t* request, int status)
|
||||
{
|
||||
tf_free(request);
|
||||
request->data = NULL;
|
||||
}
|
||||
|
||||
void tf_http_respond(tf_http_request_t* request, int status, const char** headers, int headers_count, const void* body, size_t content_length)
|
||||
@ -457,11 +458,11 @@ void tf_http_respond(tf_http_request_t* request, int status, const char** header
|
||||
tf_printf("uv_write: %s\n", uv_strerror(r));
|
||||
}
|
||||
|
||||
if (request->connection->connection_close)
|
||||
if (request->connection->connection_close &&
|
||||
!request->connection->shutdown.data)
|
||||
{
|
||||
uv_shutdown_t* shutdown_request = tf_malloc(sizeof(uv_shutdown_t));
|
||||
*shutdown_request = (uv_shutdown_t) { .data = request };
|
||||
uv_shutdown(shutdown_request, (uv_stream_t*)&request->connection->tcp, _http_on_shutdown);
|
||||
request->connection->shutdown.data = request->connection;
|
||||
uv_shutdown(&request->connection->shutdown, (uv_stream_t*)&request->connection->tcp, _http_on_shutdown);
|
||||
}
|
||||
tf_free(request);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user