Fix a buffer size / disconnect issue.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3786 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-01-22 21:20:43 +00:00
parent bd81b2acf5
commit 5623cba7c3

View File

@ -1332,6 +1332,11 @@ static void _tf_ssb_connection_on_tcp_recv(uv_stream_t* stream, ssize_t nread, c
break; break;
} }
} }
else if (nread == UV_ENOBUFS)
{
/* Our read buffer is full. Try harder to process messages. */
uv_async_send(&connection->async);
}
else else
{ {
uv_close((uv_handle_t*)stream, _tf_ssb_connection_on_close); uv_close((uv_handle_t*)stream, _tf_ssb_connection_on_close);
@ -1982,13 +1987,14 @@ static void _tf_ssb_on_connection(uv_stream_t* stream, int status)
if (uv_tcp_init(ssb->loop, &connection->tcp) != 0) if (uv_tcp_init(ssb->loop, &connection->tcp) != 0)
{ {
printf("uv_tcp_init failed\n"); printf("uv_tcp_init failed\n");
JS_FreeValue(ssb->context, connection->object); tf_ssb_connection_destroy(connection);
return; return;
} }
if (uv_accept(stream, (uv_stream_t*)&connection->tcp) != 0) if (uv_accept(stream, (uv_stream_t*)&connection->tcp) != 0)
{ {
printf("uv_accept failed\n"); printf("uv_accept failed\n");
tf_ssb_connection_destroy(connection);
return; return;
} }
@ -2149,8 +2155,10 @@ void tf_ssb_connect_str(tf_ssb_t* ssb, const char* address)
static void _tf_ssb_on_broadcast_listener_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) static void _tf_ssb_on_broadcast_listener_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf)
{ {
buf->base = malloc(suggested_size + 1); tf_ssb_connection_t* connection = handle->data;
buf->len = suggested_size; size_t malloc_size = sizeof(connection->recv_buffer) - connection->recv_size;
buf->base = malloc(malloc_size);
buf->len = malloc_size;
} }
static void _tf_ssb_notify_broadcasts_changed(tf_ssb_t* ssb) static void _tf_ssb_notify_broadcasts_changed(tf_ssb_t* ssb)