#BUGFIX by stefan
class: UnixOperatingSystem class
changed: #copyFromFd:toFd:startIndex:count:
Linux: sendfile() fix.
--- a/UnixOperatingSystem.st Tue Apr 28 11:49:45 2020 +0200
+++ b/UnixOperatingSystem.st Tue Apr 28 11:50:16 2020 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1988 by Claus Gittinger
All Rights Reserved
@@ -3801,9 +3803,11 @@
"
!
-copyFromFd:inFd toFd:outFd startIndex:startIdx count:count
+copyFromFd:inFd toFd:outFd startIndex:startIdxOrNil count:count
"directly copy data from inFd to outFd (if supported by the OS).
- Start the copy at the 0-based index startIdx of inFd and copy count bytes.
+ If startIdxOrNil is nil start at the current search position of inFd.
+ Otherwise start the copy at the 0-based index startIdxOrNil of inFd.
+ Copy count bytes.
Answer the number of bytes copied."
|error|
@@ -3813,22 +3817,30 @@
if (__isSmallInteger(inFd)
&& __isSmallInteger(outFd)
- && __isSmallInteger(startIdx)
&& __isSmallInteger(count)) {
- off_t startOffset = __intVal(startIdx);
ssize_t __count = __intVal(count);
ssize_t totalCount = 0;
+ off_t startOffset, *startOffsetP;
+
+ if (__isSmallInteger(startIdxOrNil)) {
+ startOffset = __intVal(startIdxOrNil);
+ startOffsetP = &startOffset;
+ } else if (startIdxOrNil == nil) {
+ startOffsetP = NULL;
+ } else {
+ goto out;
+ }
// 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) {
+ ssize_t writeCount = sendfile(__intVal(outFd), __intVal(inFd), startOffsetP, __count);
+ if (writeCount < 0 && errno != EINTR) {
error = __mkSmallInteger(errno);
__count = -1;
} else {
+ // startOffset ist incremented by the system call!
totalCount += writeCount;
- startOffset += writeCount; // in case we have to loop
__count -= writeCount;
}
} while (__count > 0);
@@ -3837,6 +3849,7 @@
}
}
#endif
+out:;
%}.
error notNil ifTrue:[
@@ -3854,7 +3867,7 @@
self copyFromFd:500 toFd:200 startIndex:1 count:20
"
- "Modified (comment): / 20-04-2020 / 11:41:51 / Stefan Vogel"
+ "Modified: / 28-04-2020 / 11:06:28 / Stefan Vogel"
!
createDirectory:aPathName
@@ -9830,7 +9843,7 @@
Codeset := #'utf8-mac'.
CodesetEncoder := nil.
OperatingSystem getCodesetEncoder
- OperatingSystem encodePath:'äöü'
+ OperatingSystem encodePath:'äöü'
"
"Modified: / 23-01-2013 / 10:00:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -13693,9 +13706,9 @@
domain:#'AF_UNSPEC' type:nil protocol:nil flags:nil
self getAddressInfo:'www.exept.de' serviceName:nil
domain:#'AF_INET6' type:nil protocol:nil flags:nil
- self getAddressInfo:'www.baden-württemberg.de' serviceName:nil
+ self getAddressInfo:'www.baden-württemberg.de' serviceName:nil
domain:#'AF_INET' type:#stream protocol:nil flags:nil
- self getAddressInfo:'www.baden-württemberg.de' serviceName:nil
+ self getAddressInfo:'www.baden-württemberg.de' serviceName:nil
domain:#'AF_INET6' type:#stream protocol:nil flags:nil
"