#BUGFIX by stefan
authorStefan Vogel <sv@exept.de>
Wed, 15 Apr 2020 20:22:06 +0200
changeset 25359 46719ab5a7fc
parent 25358 e6c73d87afb9
child 25360 1d8244a0d9be
#BUGFIX by stefan class: UnixOperatingSystem class changed: #copyFromFd:toFd:startIndex:count: Fix if sendfile did not copy all the data
UnixOperatingSystem.st
--- a/UnixOperatingSystem.st	Wed Apr 15 20:20:12 2020 +0200
+++ b/UnixOperatingSystem.st	Wed Apr 15 20:22:06 2020 +0200
@@ -3808,18 +3808,30 @@
       && __isSmallInteger(outFd)
       && __isSmallInteger(startIdx)
       && __isSmallInteger(count)) {
-	off_t startOffset = __intVal(startIdx);
-	ssize_t nWritten;
-
-	nWritten = sendfile(__intVal(outFd), __intVal(inFd), &startOffset, __intVal(count));
-	if (nWritten < 0) {
-	    @global(LastErrorNumber) = __mkSmallInteger(errno);
-	}
-	RETURN (__mkSmallInteger(nWritten));
+        off_t startOffset = __intVal(startIdx);
+        ssize_t __count = __intVal(count);
+        ssize_t totalCount = 0;
+        
+        // sendfile may copy partial data, so do it in a loop.
+        // caller has to check that all data has been written and take measure if not.
+        do {
+            ssize_t writeCount = sendfile(__intVal(outFd), __intVal(inFd), &startOffset, __count);
+            if (writeCount < 0) {
+                @global(LastErrorNumber) = __mkSmallInteger(errno);
+                __count = 0;
+            } else {
+                totalCount += writeCount;
+                startOffset += writeCount;    // in case we have to loop
+                __count -= writeCount;
+            }    
+        } while (__count > 0);   
+        RETURN (__mkSmallInteger(totalCount));
      }
 #endif
 %}.
     ^ 0 "/ not supported
+
+    "Modified: / 15-04-2020 / 16:36:03 / Stefan Vogel"
 !
 
 createDirectory:aPathName