From ef909a3cc5b76ca2386461e81ec38d9e7f315e2f Mon Sep 17 00:00:00 2001 From: Spencer Berger Date: Fri, 2 Mar 2018 23:29:36 -0800 Subject: [PATCH] Removed while(1) loop in dcc_read function --- src/common/dcc.c | 115 +++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 59 deletions(-) diff --git a/src/common/dcc.c b/src/common/dcc.c index 954e6b91..ebb6405b 100644 --- a/src/common/dcc.c +++ b/src/common/dcc.c @@ -713,68 +713,65 @@ dcc_read (GIOChannel *source, GIOCondition condition, struct DCC *dcc) dcc_close (dcc, STAT_FAILED, FALSE); return TRUE; } - while (1) + if (dcc->throttled) { - if (dcc->throttled) - { - if (need_ack) - dcc_send_ack (dcc); - - fe_input_remove (dcc->iotag); - dcc->iotag = 0; - return FALSE; - } - - if (!dcc->iotag) - dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read, dcc); - - n = recv (dcc->sok, buf, sizeof (buf), 0); - if (n < 1) - { - if (n < 0) - { - if (would_block ()) - { - if (need_ack) - dcc_send_ack (dcc); - return TRUE; - } - } - EMIT_SIGNAL (XP_TE_DCCRECVERR, dcc->serv->front_session, dcc->file, - dcc->destfile, dcc->nick, - errorstring ((n < 0) ? sock_error () : 0), 0); - /* send ack here? but the socket is dead */ - /*if (need_ack) - dcc_send_ack (dcc);*/ - dcc_close (dcc, STAT_FAILED, FALSE); - return TRUE; - } - - if (write (dcc->fp, buf, n) == -1) /* could be out of hdd space */ - { - EMIT_SIGNAL (XP_TE_DCCRECVERR, dcc->serv->front_session, dcc->file, - dcc->destfile, dcc->nick, errorstring (errno), 0); - if (need_ack) - dcc_send_ack (dcc); - dcc_close (dcc, STAT_FAILED, FALSE); - return TRUE; - } - - dcc->lasttime = time (0); - dcc->pos += n; - need_ack = TRUE; /* send ack when we're done recv()ing */ - - if (dcc->pos >= dcc->size) - { + if (need_ack) dcc_send_ack (dcc); - dcc_close (dcc, STAT_DONE, FALSE); - dcc_calc_average_cps (dcc); /* this must be done _after_ dcc_close, or dcc_remove_from_sum will see the wrong value in dcc->cps */ - /* cppcheck-suppress deallocuse */ - sprintf (buf, "%" G_GINT64_FORMAT, dcc->cps); - EMIT_SIGNAL (XP_TE_DCCRECVCOMP, dcc->serv->front_session, - dcc->file, dcc->destfile, dcc->nick, buf, 0); - return TRUE; + + fe_input_remove (dcc->iotag); + dcc->iotag = 0; + return FALSE; + } + + if (!dcc->iotag) + dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read, dcc); + + n = recv (dcc->sok, buf, sizeof (buf), 0); + if (n < 1) + { + if (n < 0) + { + if (would_block ()) + { + if (need_ack) + dcc_send_ack (dcc); + return TRUE; + } } + EMIT_SIGNAL (XP_TE_DCCRECVERR, dcc->serv->front_session, dcc->file, + dcc->destfile, dcc->nick, + errorstring ((n < 0) ? sock_error () : 0), 0); + /* send ack here? but the socket is dead */ + /*if (need_ack) + dcc_send_ack (dcc);*/ + dcc_close (dcc, STAT_FAILED, FALSE); + return TRUE; + } + + if (write (dcc->fp, buf, n) == -1) /* could be out of hdd space */ + { + EMIT_SIGNAL (XP_TE_DCCRECVERR, dcc->serv->front_session, dcc->file, + dcc->destfile, dcc->nick, errorstring (errno), 0); + if (need_ack) + dcc_send_ack (dcc); + dcc_close (dcc, STAT_FAILED, FALSE); + return TRUE; + } + + dcc->lasttime = time (0); + dcc->pos += n; + need_ack = TRUE; /* send ack when we're done recv()ing */ + + if (dcc->pos >= dcc->size) + { + dcc_send_ack (dcc); + dcc_close (dcc, STAT_DONE, FALSE); + dcc_calc_average_cps (dcc); /* this must be done _after_ dcc_close, or dcc_remove_from_sum will see the wrong value in dcc->cps */ + /* cppcheck-suppress deallocuse */ + sprintf (buf, "%" G_GINT64_FORMAT, dcc->cps); + EMIT_SIGNAL (XP_TE_DCCRECVCOMP, dcc->serv->front_session, + dcc->file, dcc->destfile, dcc->nick, buf, 0); + return TRUE; } }