From dcffa98d4629ee1810900d0dde1234050e68d39e Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Wed, 23 Nov 2016 16:23:35 +0100 Subject: add a static buffer for dcc received data increased buffersize might make irssi freeze less / #159 --- src/irc/dcc/dcc-get.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/irc/dcc') diff --git a/src/irc/dcc/dcc-get.c b/src/irc/dcc/dcc-get.c index f7a95bb9..73c1b864 100644 --- a/src/irc/dcc/dcc-get.c +++ b/src/irc/dcc/dcc-get.c @@ -30,6 +30,8 @@ #include "dcc-get.h" #include "dcc-send.h" +static char *dcc_get_recv_buffer; + GET_DCC_REC *dcc_get_create(IRC_SERVER_REC *server, CHAT_DCC_REC *chat, const char *nick, const char *arg) { @@ -139,14 +141,20 @@ static void sig_dccget_send(GET_DCC_REC *dcc) dcc_get_send_received(dcc); } +#define DCC_GET_RECV_BUFFER_SIZE 32768 + /* input function: DCC GET received data */ static void sig_dccget_receive(GET_DCC_REC *dcc) { - char buffer[512]; int ret; + if (dcc_get_recv_buffer == NULL) { + dcc_get_recv_buffer = g_malloc(DCC_GET_RECV_BUFFER_SIZE); + } + for (;;) { - ret = net_receive(dcc->handle, buffer, sizeof(buffer)); + ret = net_receive(dcc->handle, dcc_get_recv_buffer, + DCC_GET_RECV_BUFFER_SIZE); if (ret == 0) break; if (ret < 0) { @@ -156,7 +164,7 @@ static void sig_dccget_receive(GET_DCC_REC *dcc) return; } - if (write(dcc->fhandle, buffer, ret) != ret) { + if (write(dcc->fhandle, dcc_get_recv_buffer, ret) != ret) { /* most probably out of disk space */ signal_emit("dcc error write", 2, dcc, g_strerror(errno)); @@ -596,4 +604,5 @@ void dcc_get_deinit(void) signal_remove("dcc destroyed", (SIGNAL_FUNC) sig_dcc_destroyed); signal_remove("ctcp msg dcc send", (SIGNAL_FUNC) ctcp_msg_dcc_send); command_unbind("dcc get", (SIGNAL_FUNC) cmd_dcc_get); + g_free_and_null(dcc_get_recv_buffer); } -- cgit v1.2.3