Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
utils: tvh_write - add special socket error check
  • Loading branch information
perexg committed Jun 2, 2015
1 parent 2fdfe48 commit 2b31be5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/wrappers.c
Expand Up @@ -3,6 +3,7 @@
#include <fcntl.h>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
Expand Down Expand Up @@ -72,11 +73,19 @@ int
tvh_write(int fd, const void *buf, size_t len)
{
ssize_t c;
struct stat st;
int err;
socklen_t errlen;

while (len) {
c = write(fd, buf, len);
if (c < 0) {
if (ERRNO_AGAIN(errno)) {
fstat(fd, &st);
errlen = sizeof(err);
if (S_ISSOCK(st.st_mode) &&
(getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&err, &errlen) || err))
break;
usleep(100);
continue;
}
Expand Down

0 comments on commit 2b31be5

Please sign in to comment.