dtchat: fail cleanly on a zero-byte frame write
dc_frame_send now returns -1 instead of looping when write(2) returns 0 for the payload or the trailing newline.
This commit is contained in:
1 parent
e645e8160d
commit
ffb067372b
1 file changed
+9
-3
@@ -1261,11 +1261,17 @@ dc_frame_send(int fd, const char *line, size_t len)
|
||||
continue;
|
||||
return -1;
|
||||
}
|
||||
if (w == 0)
|
||||
return -1;
|
||||
off += (size_t)w;
|
||||
}
|
||||
while (write(fd, "\n", 1) < 0) {
|
||||
if (errno != EINTR)
|
||||
return -1;
|
||||
for (;;) {
|
||||
ssize_t n = write(fd, "\n", 1);
|
||||
if (n == 1)
|
||||
break;
|
||||
if (n < 0 && errno == EINTR)
|
||||
continue;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user