forked from cory/tildefriends
Bugs galore, but this is sending and receiving some websocket messages.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4697 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
13
src/http.c
13
src/http.c
@ -41,6 +41,7 @@ typedef struct _tf_http_connection_t
|
||||
|
||||
int flags;
|
||||
tf_http_callback_t* callback;
|
||||
tf_http_request_t* request;
|
||||
void* user_data;
|
||||
|
||||
bool is_websocket;
|
||||
@ -133,6 +134,7 @@ static void _http_connection_destroy(tf_http_connection_t* connection)
|
||||
{
|
||||
if (connection->tcp.data)
|
||||
{
|
||||
tf_printf("CLOSE %p\n", connection);
|
||||
uv_close((uv_handle_t*)&connection->tcp, _http_connection_on_close);
|
||||
}
|
||||
else if (connection->ref_count == 0)
|
||||
@ -233,7 +235,14 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
|
||||
}
|
||||
if (fin)
|
||||
{
|
||||
tf_printf("MESSAGE %d [%.*s]\n", opcode, (int)length, p + mask_start + 4);
|
||||
if (connection->request->on_message)
|
||||
{
|
||||
connection->request->on_message(connection->request, p + mask_start + 4, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
tf_printf("MESSAGE %d [%.*s]\n", opcode, (int)length, p + mask_start + 4);
|
||||
}
|
||||
}
|
||||
size_t total_length = end;
|
||||
memmove(connection->body, (char*)connection->body + total_length, connection->body_length - total_length);
|
||||
@ -271,6 +280,7 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
|
||||
.headers_count = connection->headers_length,
|
||||
.user_data = connection->user_data,
|
||||
};
|
||||
connection->request = request;
|
||||
|
||||
tf_http_request_ref(request);
|
||||
connection->callback(request);
|
||||
@ -523,6 +533,7 @@ static void _http_on_shutdown(uv_shutdown_t* request, int status)
|
||||
|
||||
static void _http_write(tf_http_connection_t* connection, const void* data, size_t size)
|
||||
{
|
||||
tf_printf("WRITE connection=%p\n", connection);
|
||||
uv_write_t* write = tf_malloc(sizeof(uv_write_t) + size);
|
||||
*write = (uv_write_t) { .data = connection };
|
||||
memcpy(write + 1, data, size);
|
||||
|
Reference in New Issue
Block a user