Commit 0edece32 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Use select() + send().

parent ed5f17c9
Pipeline #2967 passed with stages
in 1 minute and 41 seconds
......@@ -113,15 +113,39 @@ static inline ssize_t _send(socket_t conn, const char *buf, size_t size)
int written = 0;
ssize_t n = 0;
while (written < size) {
n = send(conn, buf, size - written, 0);
if (n < 0) {
_time();
printf("WRITE FAILED: %ld, errno: %d\n", n, errno);
printf("%s\n", buf - written);
return written;
fd_set wfds;
struct timeval tv;
int retval;
FD_ZERO(&wfds);
FD_SET(conn, &wfds);
tv.tv_sec = 1;
tv.tv_usec = 0;
retval = select(conn + 1, NULL, &wfds, NULL, &tv);
if (!FD_ISSET(conn, &wfds)) {
continue;
}
if (retval == -1) {
printf("Select failed: %d.\n", errno);
return -1;
} else if (retval > 0) {
n = send(conn, buf, size - written, 0);
if (n < 0) {
_time();
printf("RECEIVE FAILED: %ld, errno: %d\n, written %ld / %ld", n, errno, written, size);
printf("%s\n", buf - written);
return written;
}
if (n == 0) {
break;
}
written += n;
buf += n;
} else {
continue;
}
written += n;
buf += n;
}
return written;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment