]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
utils: tvh_write - add special socket error check
authorJaroslav Kysela <perex@perex.cz>
Tue, 2 Jun 2015 15:56:14 +0000 (17:56 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 2 Jun 2015 18:43:09 +0000 (20:43 +0200)
src/wrappers.c

index 9d8fa6a61c19147b799fc4c451805793c30c5b3d..66a9ee1599157d40667b9c44abd8e8dda90b490a 100644 (file)
@@ -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>
@@ -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;
       }