common: call recv/send before can_recv/can_send

ulab-next-nosound
Jay Sorg 9 years ago
parent bd6c38af4d
commit 0655272b9c

@ -442,45 +442,42 @@ trans_force_read_s(struct trans *self, struct stream *in_s, int size)
{ {
return 1; return 1;
} }
if (self->trans_can_recv(self, self->sck, 100)) rcvd = self->trans_recv(self, in_s->end, size);
if (rcvd == -1)
{ {
rcvd = self->trans_recv(self, in_s->end, size); if (g_tcp_last_error_would_block(self->sck))
if (rcvd == -1)
{ {
if (g_tcp_last_error_would_block(self->sck)) if (!self->trans_can_recv(self, self->sck, 100))
{
}
else
{ {
/* error */ /* check for term here */
self->status = TRANS_STATUS_DOWN; if (self->is_term != 0)
return 1; {
if (self->is_term())
{
/* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
} }
} }
else if (rcvd == 0) else
{ {
/* error */ /* error */
self->status = TRANS_STATUS_DOWN; self->status = TRANS_STATUS_DOWN;
return 1; return 1;
} }
else }
{ else if (rcvd == 0)
in_s->end += rcvd; {
size -= rcvd; /* error */
} self->status = TRANS_STATUS_DOWN;
return 1;
} }
else else
{ {
/* check for term here */ in_s->end += rcvd;
if (self->is_term != 0) size -= rcvd;
{
if (self->is_term())
{
/* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
} }
} }
return 0; return 0;
@ -514,44 +511,41 @@ trans_force_write_s(struct trans *self, struct stream *out_s)
} }
while (total < size) while (total < size)
{ {
if (g_tcp_can_send(self->sck, 100)) sent = self->trans_send(self, out_s->data + total, size - total);
if (sent == -1)
{ {
sent = self->trans_send(self, out_s->data + total, size - total); if (g_tcp_last_error_would_block(self->sck))
if (sent == -1)
{ {
if (g_tcp_last_error_would_block(self->sck)) if (!g_tcp_can_send(self->sck, 100))
{ {
} /* check for term here */
else if (self->is_term != 0)
{ {
/* error */ if (self->is_term())
self->status = TRANS_STATUS_DOWN; {
return 1; /* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
} }
} }
else if (sent == 0) else
{ {
/* error */ /* error */
self->status = TRANS_STATUS_DOWN; self->status = TRANS_STATUS_DOWN;
return 1; return 1;
} }
else }
{ else if (sent == 0)
total = total + sent; {
} /* error */
self->status = TRANS_STATUS_DOWN;
return 1;
} }
else else
{ {
/* check for term here */ total = total + sent;
if (self->is_term != 0)
{
if (self->is_term())
{
/* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
} }
} }
return 0; return 0;

Loading…
Cancel
Save