tsocket: allow empty vectors at the end for tstream_writev()/readv()
[ira/wip.git] / lib / tsocket / tsocket_bsd.c
index 8f5f009d4c136332bc75fc3b8b701943bdd677fd..a4cbda8b8378d8b28434c98e13a265a9b8a75df8 100644 (file)
@@ -1538,6 +1538,19 @@ static void tstream_bsd_readv_handler(void *private_data)
                state->count -= 1;
        }
 
+       /*
+        * there're maybe some empty vectors at the end
+        * which we need to skip, otherwise we would get
+        * ret == 0 from the readv() call and return EPIPE
+        */
+       while (state->count > 0) {
+               if (state->vector[0].iov_len > 0) {
+                       break;
+               }
+               state->vector += 1;
+               state->count -= 1;
+       }
+
        if (state->count > 0) {
                /* we have more to read */
                return;
@@ -1685,6 +1698,19 @@ static void tstream_bsd_writev_handler(void *private_data)
                state->count -= 1;
        }
 
+       /*
+        * there're maybe some empty vectors at the end
+        * which we need to skip, otherwise we would get
+        * ret == 0 from the writev() call and return EPIPE
+        */
+       while (state->count > 0) {
+               if (state->vector[0].iov_len > 0) {
+                       break;
+               }
+               state->vector += 1;
+               state->count -= 1;
+       }
+
        if (state->count > 0) {
                /* we have more to read */
                return;