Removed while(1) loop in dcc_read function

This commit is contained in:
Spencer Berger 2018-03-02 23:29:36 -08:00
parent 8aa3b03261
commit ef909a3cc5

View File

@ -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;
}
}