sockets: Simplify write function

libvncclient-integration
Andri Yngvason 2022-06-29 11:48:50 +00:00
parent bd4c3a7286
commit 8bc25aa700
1 changed files with 21 additions and 20 deletions

View File

@ -133,28 +133,29 @@ WriteToRFBServer(rfbClient* client, const char *buf, unsigned int n)
// TODO: Dispatch events while waiting
while (i < n) {
j = write(client->sock, obuf + i, (n - i));
if (j <= 0) {
if (j < 0) {
if (errno == EWOULDBLOCK || errno == EAGAIN) {
fds.fd = client->sock;
fds.events = POLLIN;
if (poll(&fds, 1, -1) <= 0) {
rfbClientErr("select\n");
return FALSE;
}
j = 0;
} else {
rfbClientErr("write\n");
return FALSE;
}
} else {
rfbClientLog("write failed\n");
return FALSE;
}
if (j > 0) {
i += j;
continue;
}
if (j == 0) {
rfbClientLog("write failed\n");
return FALSE;
}
if (errno != EWOULDBLOCK && errno != EAGAIN) {
rfbClientErr("write\n");
return FALSE;
}
fds.fd = client->sock;
fds.events = POLLOUT;
if (poll(&fds, 1, -1) <= 0) {
rfbClientErr("poll\n");
return FALSE;
}
i += j;
}
return TRUE;
}