forked from cory/tildefriends
Delete httpd.js.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4709 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
12
src/http.c
12
src/http.c
@ -544,7 +544,7 @@ static void _http_on_connection(uv_stream_t* stream, int status)
|
||||
http->connections[http->connections_count++] = connection;
|
||||
}
|
||||
|
||||
void 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_listener_t* listener = tf_malloc(sizeof(tf_http_listener_t));
|
||||
*listener = (tf_http_listener_t) { .http = http, .tls = tls, .tcp = { .data = listener } };
|
||||
@ -569,6 +569,15 @@ void tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls)
|
||||
}
|
||||
}
|
||||
|
||||
int assigned_port = 0;
|
||||
if (r == 0)
|
||||
{
|
||||
struct sockaddr_storage name = { 0 };
|
||||
int size = (int)sizeof(name);
|
||||
r = uv_tcp_getsockname(&listener->tcp, (struct sockaddr*)&name, &size);
|
||||
assigned_port = ntohs(((struct sockaddr_in*)&name)->sin_port);
|
||||
}
|
||||
|
||||
if (r == 0)
|
||||
{
|
||||
r = uv_listen((uv_stream_t*)&listener->tcp, 16, _http_on_connection);
|
||||
@ -583,6 +592,7 @@ void tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls)
|
||||
http->listeners = tf_realloc(http->listeners, sizeof(tf_http_listener_t*) * (http->listeners_count + 1));
|
||||
http->listeners[http->listeners_count++] = listener;
|
||||
}
|
||||
return assigned_port;
|
||||
}
|
||||
|
||||
void tf_http_add_handler(tf_http_t* http, const char* pattern, tf_http_callback_t* callback, void* user_data)
|
||||
|
Reference in New Issue
Block a user