Skip to content

Commit 7883586

Browse files
committed
retry write() if it fails with EINTR or EAGAIN
1 parent 809a355 commit 7883586

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/common.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,16 @@ ssize_t dis_read(int fd, void* buf, size_t count)
215215
ssize_t dis_write(int fd, void* buf, size_t count)
216216
{
217217
ssize_t res = -1;
218-
218+
errno = 0;
219219
dis_printf(L_DEBUG, "Writing %#" F_SIZE_T " bytes to #%d from %p\n", count, fd, buf);
220-
221-
if((res = write(fd, buf, count)) < 0)
222-
{
223-
dis_errno = errno;
224-
dis_printf(L_ERROR, DIS_XWRITE_FAIL_STR " #%d: %s\n", fd, strerror(errno));
225-
}
220+
do {
221+
if((res = write(fd, buf, count)) < 0)
222+
{
223+
dis_errno = errno;
224+
dis_printf(L_ERROR, DIS_XWRITE_FAIL_STR
225+
" #%d: %s\n", fd, strerror(errno));
226+
}
227+
} while (res == -1 && (errno == EINTR || errno == EAGAIN));
226228

227229
return res;
228230
}

0 commit comments

Comments
 (0)