Removed while(1) loop in dcc_read_chat function

This commit is contained in:
Spencer Berger 2018-03-02 23:37:54 -08:00
parent ef909a3cc5
commit c4f0cf8e74

View File

@ -577,59 +577,56 @@ dcc_read_chat (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
char portbuf[32]; char portbuf[32];
char lbuf[2050]; char lbuf[2050];
while (1) if (dcc->throttled)
{ {
if (dcc->throttled) 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_chat, dcc);
len = recv (dcc->sok, lbuf, sizeof (lbuf) - 2, 0);
if (len < 1)
{
if (len < 0)
{ {
fe_input_remove (dcc->iotag); if (would_block ())
dcc->iotag = 0; return TRUE;
return FALSE;
} }
sprintf (portbuf, "%d", dcc->port);
if (!dcc->iotag) EMIT_SIGNAL (XP_TE_DCCCHATF, dcc->serv->front_session, dcc->nick,
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc); net_ip (dcc->addr), portbuf,
errorstring ((len < 0) ? sock_error () : 0), 0);
len = recv (dcc->sok, lbuf, sizeof (lbuf) - 2, 0); dcc_close (dcc, STAT_FAILED, FALSE);
if (len < 1) return TRUE;
}
i = 0;
lbuf[len] = 0;
while (i < len)
{
switch (lbuf[i])
{ {
if (len < 0) case '\r':
{ break;
if (would_block ()) case '\n':
return TRUE; dcc->dccchat->linebuf[dcc->dccchat->pos] = 0;
} dead = dcc_chat_line (dcc, dcc->dccchat->linebuf);
sprintf (portbuf, "%d", dcc->port);
EMIT_SIGNAL (XP_TE_DCCCHATF, dcc->serv->front_session, dcc->nick,
net_ip (dcc->addr), portbuf,
errorstring ((len < 0) ? sock_error () : 0), 0);
dcc_close (dcc, STAT_FAILED, FALSE);
return TRUE;
}
i = 0;
lbuf[len] = 0;
while (i < len)
{
switch (lbuf[i])
{
case '\r':
break;
case '\n':
dcc->dccchat->linebuf[dcc->dccchat->pos] = 0;
dead = dcc_chat_line (dcc, dcc->dccchat->linebuf);
if (dead || !dcc->dccchat) /* the dcc has been closed, don't use (DCC *)! */ if (dead || !dcc->dccchat) /* the dcc has been closed, don't use (DCC *)! */
return TRUE; return TRUE;
dcc->pos += dcc->dccchat->pos; dcc->pos += dcc->dccchat->pos;
dcc->dccchat->pos = 0; dcc->dccchat->pos = 0;
fe_dcc_update (dcc); fe_dcc_update (dcc);
break; break;
default: default:
dcc->dccchat->linebuf[dcc->dccchat->pos] = lbuf[i]; dcc->dccchat->linebuf[dcc->dccchat->pos] = lbuf[i];
if (dcc->dccchat->pos < (sizeof (dcc->dccchat->linebuf) - 1)) if (dcc->dccchat->pos < (sizeof (dcc->dccchat->linebuf) - 1))
dcc->dccchat->pos++; dcc->dccchat->pos++;
}
i++;
} }
i++;
} }
} }