From 5623cba7c3d2cdf4917c53edcb1ca9eb63959710 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 22 Jan 2022 21:20:43 +0000 Subject: [PATCH] Fix a buffer size / disconnect issue. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3786 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ssb.c b/src/ssb.c index 3a05efb1..a00cafb5 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -1332,6 +1332,11 @@ static void _tf_ssb_connection_on_tcp_recv(uv_stream_t* stream, ssize_t nread, c break; } } + else if (nread == UV_ENOBUFS) + { + /* Our read buffer is full. Try harder to process messages. */ + uv_async_send(&connection->async); + } else { 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) { printf("uv_tcp_init failed\n"); - JS_FreeValue(ssb->context, connection->object); + tf_ssb_connection_destroy(connection); return; } if (uv_accept(stream, (uv_stream_t*)&connection->tcp) != 0) { printf("uv_accept failed\n"); + tf_ssb_connection_destroy(connection); 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) { - buf->base = malloc(suggested_size + 1); - buf->len = suggested_size; + tf_ssb_connection_t* connection = handle->data; + 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)