# HG changeset patch # User Stefan Vogel # Date 1480426529 -3600 # Node ID b7050f50aa94d56b18cb9d9baf305a9e9d77dffb # Parent d4735595a00216b0aa26b74a1877f47b6b84b677 #BUGFIX by stefan class: ExternalStream class definition comment/format in: #nextAvailableBytes:into:startingAt: changed: #atEnd librun has been fixed to return real error codes - now fix handling of ERROR_BROKEN_PIPE diff -r d4735595a002 -r b7050f50aa94 ExternalStream.st --- a/ExternalStream.st Tue Nov 29 14:32:54 2016 +0100 +++ b/ExternalStream.st Tue Nov 29 14:35:29 2016 +0100 @@ -224,8 +224,6 @@ #endif #ifdef __win32__ -// Win returns from ReadFile() with false and _threadErrno == 0 on end of pipe. -// We don't know why # define READ(ret, f, cp, n, handleType) { \ if (handleType == @symbol(socketHandle)) { \ (ret) = __STX_WSA_NOINT_CALL4("recv", recv, (f), (cp), (n), 0); \ @@ -236,7 +234,7 @@ } else { \ int __res; \ (ret) = __STX_API_NOINT_CALL5("ReadFile", ReadFile, h, (cp), (n), &__res, 0);\ - (ret) = (ret) ? __res : ((__threadErrno == EPIPE || __threadErrno == 0) ? 0 : -1); \ + (ret) = (ret) > 0 ? __res : (__threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1); \ } \ } \ } @@ -409,7 +407,11 @@ if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ || (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ || (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ - if (!ok) { (ret) = -1; break; } \ + if (!ok) { \ + __threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ + (ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ + break; \ + } \ if (res > 0) { \ if (res > ((cnt)-__offs)) \ res = (cnt)-__offs; \ @@ -456,7 +458,7 @@ if (__threadErrno == EINTR) { \ clearerr(f); \ /* refetch */ \ - buf = (char *)(obj); \ + buf = (char *)(obj); \ continue; \ } \ } else { \ @@ -554,7 +556,11 @@ if ((handleType == @symbol(socketFilePointer) && ((ok = ioctlsocket(sock = (SOCKET)_get_osfhandle(fileno(f)),FIONREAD,&res) == 0), 1)) \ || (handleType == @symbol(socketHandle) && ((ok = ioctlsocket(sock = (SOCKET)(f), FIONREAD, &res) == 0), 1)) \ || (handleType == @symbol(pipeFilePointer) && ((ok = PeekNamedPipe((HANDLE)_get_osfhandle(fileno(f)),0, 0,0,&res,0)), 1))) { \ - if (!ok) { (ret) = -1; break; } \ + if (!ok) { \ + __threadErrno = sock ? WSAGetLastError() : __WIN32_ERR(GetLastError()); \ + (ret) = __threadErrno == __WIN32_ERR(ERROR_BROKEN_PIPE) ? 0 : -1; \ + break; \ + } \ if (res > 0) { \ if (res > l) res = l; \ READ((ret), f, __buf, res, handleType); \ @@ -566,7 +572,7 @@ } \ break; \ } \ - } else { \ + } else { \ READ((ret), f, __buf, l, handleType); \ } \ if ((ret) <= 0) { \ @@ -640,7 +646,7 @@ while (__offs < (cnt)) { \ CLEAR_ERRNO; \ WRITE((ret),f, (buf)+__offs, (cnt)-__offs, handleType); \ - if ((ret) <= 0) { \ + if ((ret) <= 0) { \ if ((ret) < 0 && __threadErrno == EINTR) { \ continue; \ } \ @@ -5625,21 +5631,13 @@ */ do { #ifdef __win32__ -# if 1 __READBYTE__(ret, f, &c, _buffered, __INST(handleType)); - -# else - __BEGIN_INTERRUPTABLE__ - __READBYTE__(ret, f, &c, _buffered, __INST(handleType)); - __END_INTERRUPTABLE__ -# endif #else /* not __win32__ */ __BEGIN_INTERRUPTABLE__ __READBYTE__(ret, f, &c, _buffered, __INST(handleType)); __END_INTERRUPTABLE__ #endif } while ((ret < 0) && (__threadErrno == EINTR)); - if (ret > 0) { __UNGETC__(c&0xff, f, _buffered); RETURN (false);