common: call recv/send before can_recv/can_send

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

@ -442,13 +442,24 @@ 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); rcvd = self->trans_recv(self, in_s->end, size);
if (rcvd == -1) if (rcvd == -1)
{ {
if (g_tcp_last_error_would_block(self->sck)) if (g_tcp_last_error_would_block(self->sck))
{ {
if (!self->trans_can_recv(self, self->sck, 100))
{
/* check for term here */
if (self->is_term != 0)
{
if (self->is_term())
{
/* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
}
} }
else else
{ {
@ -469,20 +480,6 @@ trans_force_read_s(struct trans *self, struct stream *in_s, int size)
size -= rcvd; size -= rcvd;
} }
} }
else
{
/* check for term here */
if (self->is_term != 0)
{
if (self->is_term())
{
/* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
}
}
return 0; return 0;
} }
@ -513,14 +510,25 @@ trans_force_write_s(struct trans *self, struct stream *out_s)
return 1; return 1;
} }
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); sent = self->trans_send(self, out_s->data + total, size - total);
if (sent == -1) if (sent == -1)
{ {
if (g_tcp_last_error_would_block(self->sck)) if (g_tcp_last_error_would_block(self->sck))
{ {
if (!g_tcp_can_send(self->sck, 100))
{
/* check for term here */
if (self->is_term != 0)
{
if (self->is_term())
{
/* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
}
} }
else else
{ {
@ -540,20 +548,6 @@ trans_force_write_s(struct trans *self, struct stream *out_s)
total = total + sent; total = total + sent;
} }
} }
else
{
/* check for term here */
if (self->is_term != 0)
{
if (self->is_term())
{
/* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
}
}
return 0; return 0;
} }

Loading…
Cancel
Save