From 2790a3b0b5ba14985b67e334c7069dcb28e687b6 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 19 Feb 2001 02:12:06 +0000 Subject: [PATCH] When reading data from socket, read max. 5kB at a time so we won't get stuck if socket just keeps sending more and more data. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1243 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/net-disconnect.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/core/net-disconnect.c b/src/core/net-disconnect.c index 3120558f..9f477fb5 100644 --- a/src/core/net-disconnect.c +++ b/src/core/net-disconnect.c @@ -47,16 +47,20 @@ static void net_disconnect_remove(NET_DISCONNECT_REC *rec) static void sig_disconnect(NET_DISCONNECT_REC *rec) { - char buf[128]; - int ret; + char buf[512]; + int count, ret; - /* check if there's any data waiting in socket */ - while ((ret = net_receive(rec->handle, buf, sizeof(buf))) > 0) ; - - if (ret == -1) { - /* socket was closed */ - net_disconnect_remove(rec); - } + /* check if there's any data waiting in socket. read max. 5kB so + if server just keeps sending us stuff we won't get stuck */ + count = 0; + do { + ret = net_receive(rec->handle, buf, sizeof(buf)); + if (ret == -1) { + /* socket was closed */ + net_disconnect_remove(rec); + } + count++; + } while (ret == sizeof(buf) && count < 10); } static int sig_timeout_disconnect(void)