56 |
|
|
57 |
while (total < length) |
while (total < length) |
58 |
{ |
{ |
59 |
sent = write(sock, s->data + total, length - total); |
sent = send(sock, s->data + total, length - total, 0); |
|
|
|
60 |
if (sent <= 0) |
if (sent <= 0) |
61 |
{ |
{ |
62 |
error("write: %s\n", strerror(errno)); |
error("send: %s\n", strerror(errno)); |
63 |
return; |
return; |
64 |
} |
} |
65 |
|
|
71 |
STREAM |
STREAM |
72 |
tcp_recv(int length) |
tcp_recv(int length) |
73 |
{ |
{ |
74 |
int ret, rcvd = 0; |
int rcvd = 0; |
|
struct timeval tv; |
|
|
fd_set rfds; |
|
75 |
|
|
76 |
if (length > in.size) |
if (length > in.size) |
77 |
{ |
{ |
83 |
|
|
84 |
while (length > 0) |
while (length > 0) |
85 |
{ |
{ |
86 |
ui_process_events(); |
ui_select(sock); |
|
|
|
|
FD_ZERO(&rfds); |
|
|
FD_SET(sock, &rfds); |
|
|
tv.tv_sec = 0; |
|
|
tv.tv_usec = 100; |
|
|
|
|
|
ret = select(sock + 1, &rfds, NULL, NULL, &tv); |
|
87 |
|
|
88 |
if (ret) |
rcvd = recv(sock, in.end, length, 0); |
89 |
|
if (rcvd == -1) |
90 |
{ |
{ |
91 |
rcvd = read(sock, in.end, length); |
error("recv: %s\n", strerror(errno)); |
92 |
|
return NULL; |
|
if (rcvd <= 0) |
|
|
{ |
|
|
error("read: %s\n", strerror(errno)); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
in.end += rcvd; |
|
|
length -= rcvd; |
|
93 |
} |
} |
94 |
|
|
95 |
|
in.end += rcvd; |
96 |
|
length -= rcvd; |
97 |
} |
} |
98 |
|
|
99 |
return ∈ |
return ∈ |