1
0
forked from bip/bip

Damn old backlog bug finally fixed. Happiness. Joy.

This commit is contained in:
nohar 2005-05-23 06:27:26 +00:00
parent 152e5324d5
commit abd979fb01

View File

@ -216,21 +216,29 @@ static int _write_socket(connection_t *cn, char* message)
ssize_t count; ssize_t count;
size = strlen(message); size = strlen(message);
while ((count = write(cn->handle, ((const char*)message) + tcount, do {
while ((count = write(cn->handle,
((const char *)message) + tcount,
size - tcount)) > 0) { size - tcount)) > 0) {
tcount += count; tcount += count;
if (tcount == size) if (tcount == size)
break; break;
} }
} while (count < 0 &&
(errno == EAGAIN || errno == EINTR || errno == EINPROGRESS));
if (count <= 0 && tcount > 0) if (count <= 0 && tcount > 0)
fatal("shit happens\n"); fatal("shit happens errno:%d count:%d tcount:%d (%s)\n", errno,
count, tcount, message);
if (count <= 0) { if (count <= 0) {
/* /*
* if no fatal error, return WRITE_KEEP, which makes caller * if no fatal error, return WRITE_KEEP, which makes caller
* keep line in its FIFO * keep line in its FIFO
*/ *
* Cannot do: we might have written a partial line
*
if (errno == EAGAIN || errno == EINTR || errno == EINPROGRESS) if (errno == EAGAIN || errno == EINTR || errno == EINPROGRESS)
return WRITE_KEEP; return WRITE_KEEP;
*/
if (cn_is_connected(cn)) { if (cn_is_connected(cn)) {
mylog(LOG_DEBUG, "write(fd %d) : %s", cn->handle, mylog(LOG_DEBUG, "write(fd %d) : %s", cn->handle,