ExtSTream>>next: did not work correct if interrupted.
authorStefan Vogel <sv@exept.de>
Thu, 29 Feb 1996 11:18:33 +0100
changeset 1044 c2fb3818e097
parent 1043 252a034cc582
child 1045 c7a38395a1d4
ExtSTream>>next: did not work correct if interrupted.
ExtStream.st
ExternalStream.st
--- a/ExtStream.st	Thu Feb 29 03:25:30 1996 +0100
+++ b/ExtStream.st	Thu Feb 29 11:18:33 1996 +0100
@@ -10,16 +10,16 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:2.10.8 on 29-dec-1995 at 00:15:30'                   !
+'From Smalltalk/X, Version:2.10.9 on 28-feb-1996 at 22:05:50'                   !
 
 ReadWriteStream subclass:#ExternalStream
-	 instanceVariableNames:'filePointer mode buffered binary useCRLF hitEOF didWrite
+	instanceVariableNames:'filePointer mode buffered binary useCRLF hitEOF didWrite
 		lastErrorNumber'
-	 classVariableNames:'Lobby LastErrorNumber 
-		InvalidReadSignal InvalidWriteSignal InvalidModeSignal
-		OpenErrorSignal StreamNotOpenSignal InvalidOperationSignal'
-	 poolDictionaries:''
-	 category:'Streams-External'
+	classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
+		InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
+		InvalidOperationSignal'
+	poolDictionaries:''
+	category:'Streams-External'
 !
 
 !ExternalStream primitiveDefinitions!
@@ -1216,6 +1216,12 @@
     self position:"0" 1
 !
 
+setToEnd
+    "redefined since it must be implemented differently"
+
+    ^ self subclassResponsibility
+!
+
 truncateTo:newSize
     "truncate the underlying OS file to newSize.
      Warning: this may not be implemented on all platforms."
@@ -1254,12 +1260,6 @@
 
      ('test' asFilename fileSize) printNL
     "
-!
-
-setToEnd
-    "redefined since it must be implemented differently"
-
-    ^ self subclassResponsibility
 ! !
 
 !ExternalStream methodsFor:'non homogenous reading'!
@@ -1363,71 +1363,81 @@
     _INST(lastErrorNumber) = nil;
     if (((fp = _INST(filePointer)) != nil)
      && (_INST(mode) != @symbol(writeonly))) {
-	if (__bothSmallInteger(count, start)) {
-	    f = __FILEVal(fp);
-
-	    oClass = __Class(anObject);
-	    switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
-		case BYTEARRAY:
-		case WORDARRAY:
-		case LONGARRAY:
-		case FLOATARRAY:
-		case DOUBLEARRAY:
-		    break;
-		default:
-		    goto bad;
-	    }
-	    cnt = __intVal(count);
-	    offs = __intVal(start) - 1;
-	    nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-	    nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
-	    objSize = __Size(anObject) - nInstBytes;
-	    if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
-		/* 
-		 * mhmh - since we are interruptable, anObject may move.
-		 * therefore, fetch the cp-pointer within the loop
-		 */
-		if (_INST(buffered) == true) {
-		    __READING__(f)
-		}
-
-		__BEGIN_INTERRUPTABLE__
-		do {
-		    errno = 0;
-		    /*
-		     * because we are interruptable, refetch pointer
-		     */
-		    cp = (char *)__InstPtr(anObject) + nInstBytes + offs;
-		    if (_INST(buffered) == false) {
-			ret = read(fileno(f), cp, cnt);
-		    } else {
-			if (feof(f)) {
-			    ret = 0;
-			    break;
-			}
-			ret = fread(cp, 1, cnt, f);
-		    }
-		} while ((ret < 0) && (errno == EINTR));
-
-		__END_INTERRUPTABLE__
-		cnt = ret;
-
-		if (cnt > 0) {
-		    pos = _INST(position);
-		    if (pos != nil) {
-			_INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
-		    }
-		    RETURN (__MKSMALLINT(cnt));
-		}
-		if (cnt == 0) { 
-		    _INST(hitEOF) = true;
-		    RETURN (__MKSMALLINT(cnt));
-		}
-
-		_INST(position) = nil;
-		_INST(lastErrorNumber) = __MKSMALLINT(errno);
-	    }
-	}
+        if (__bothSmallInteger(count, start)) {
+            f = __FILEVal(fp);
+
+            oClass = __Class(anObject);
+            switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+                case BYTEARRAY:
+                case WORDARRAY:
+                case LONGARRAY:
+                case FLOATARRAY:
+                case DOUBLEARRAY:
+                    break;
+                default:
+                    goto bad;
+            }
+            cnt = __intVal(count);
+            offs = __intVal(start) - 1;
+            nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+            nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+            objSize = __Size(anObject) - nInstBytes;
+            if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
+                /* 
+                 * mhmh - since we are interruptable, anObject may move.
+                 * therefore, fetch the cp-pointer within the loop
+                 */
+                if (_INST(buffered) == true) {
+                    __READING__(f)
+                }
+
+                __BEGIN_INTERRUPTABLE__
+                for (;;) {
+                    errno = 0;
+                    /*
+                     * because we are interruptable, refetch pointer
+                     */
+                    cp = (char *)__InstPtr(anObject) + nInstBytes + offs;
+                    if (_INST(buffered) == false) {
+                        ret = read(fileno(f), cp, cnt);
+                    } else {
+                        if (feof(f)) {
+                            ret = 0;
+                            break;
+                        }
+                        ret = fread(cp, 1, cnt, f);
+                    }
+                    if (ret < 0) {
+                        if (errno == EINTR) 
+                            continue;
+                        else
+                            break;
+                    }   
+                    cnt -= ret;
+                    if (cnt == 0 || ret == 0)
+                        break;
+                    offs += ret;
+                } 
+
+                __END_INTERRUPTABLE__
+                cnt = __intVal(count) - cnt;
+
+                if (cnt > 0) {
+                    pos = _INST(position);
+                    if (pos != nil) {
+                        _INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
+                    }
+                    RETURN (__MKSMALLINT(cnt));
+                }
+                if (cnt == 0) { 
+                    _INST(hitEOF) = true;
+                    RETURN (__MKSMALLINT(cnt));
+                }
+
+                _INST(position) = nil;
+                _INST(lastErrorNumber) = __MKSMALLINT(errno);
+            }
+        }
     }
 bad: ;
 %}.
@@ -3545,6 +3555,6 @@
 !ExternalStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.87 1996-02-20 16:32:47 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.88 1996-02-29 10:18:33 stefan Exp $'
 ! !
 ExternalStream initialize!
--- a/ExternalStream.st	Thu Feb 29 03:25:30 1996 +0100
+++ b/ExternalStream.st	Thu Feb 29 11:18:33 1996 +0100
@@ -10,16 +10,16 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:2.10.8 on 29-dec-1995 at 00:15:30'                   !
+'From Smalltalk/X, Version:2.10.9 on 28-feb-1996 at 22:05:50'                   !
 
 ReadWriteStream subclass:#ExternalStream
-	 instanceVariableNames:'filePointer mode buffered binary useCRLF hitEOF didWrite
+	instanceVariableNames:'filePointer mode buffered binary useCRLF hitEOF didWrite
 		lastErrorNumber'
-	 classVariableNames:'Lobby LastErrorNumber 
-		InvalidReadSignal InvalidWriteSignal InvalidModeSignal
-		OpenErrorSignal StreamNotOpenSignal InvalidOperationSignal'
-	 poolDictionaries:''
-	 category:'Streams-External'
+	classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
+		InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
+		InvalidOperationSignal'
+	poolDictionaries:''
+	category:'Streams-External'
 !
 
 !ExternalStream primitiveDefinitions!
@@ -1216,6 +1216,12 @@
     self position:"0" 1
 !
 
+setToEnd
+    "redefined since it must be implemented differently"
+
+    ^ self subclassResponsibility
+!
+
 truncateTo:newSize
     "truncate the underlying OS file to newSize.
      Warning: this may not be implemented on all platforms."
@@ -1254,12 +1260,6 @@
 
      ('test' asFilename fileSize) printNL
     "
-!
-
-setToEnd
-    "redefined since it must be implemented differently"
-
-    ^ self subclassResponsibility
 ! !
 
 !ExternalStream methodsFor:'non homogenous reading'!
@@ -1363,71 +1363,81 @@
     _INST(lastErrorNumber) = nil;
     if (((fp = _INST(filePointer)) != nil)
      && (_INST(mode) != @symbol(writeonly))) {
-	if (__bothSmallInteger(count, start)) {
-	    f = __FILEVal(fp);
-
-	    oClass = __Class(anObject);
-	    switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
-		case BYTEARRAY:
-		case WORDARRAY:
-		case LONGARRAY:
-		case FLOATARRAY:
-		case DOUBLEARRAY:
-		    break;
-		default:
-		    goto bad;
-	    }
-	    cnt = __intVal(count);
-	    offs = __intVal(start) - 1;
-	    nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-	    nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
-	    objSize = __Size(anObject) - nInstBytes;
-	    if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
-		/* 
-		 * mhmh - since we are interruptable, anObject may move.
-		 * therefore, fetch the cp-pointer within the loop
-		 */
-		if (_INST(buffered) == true) {
-		    __READING__(f)
-		}
-
-		__BEGIN_INTERRUPTABLE__
-		do {
-		    errno = 0;
-		    /*
-		     * because we are interruptable, refetch pointer
-		     */
-		    cp = (char *)__InstPtr(anObject) + nInstBytes + offs;
-		    if (_INST(buffered) == false) {
-			ret = read(fileno(f), cp, cnt);
-		    } else {
-			if (feof(f)) {
-			    ret = 0;
-			    break;
-			}
-			ret = fread(cp, 1, cnt, f);
-		    }
-		} while ((ret < 0) && (errno == EINTR));
-
-		__END_INTERRUPTABLE__
-		cnt = ret;
-
-		if (cnt > 0) {
-		    pos = _INST(position);
-		    if (pos != nil) {
-			_INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
-		    }
-		    RETURN (__MKSMALLINT(cnt));
-		}
-		if (cnt == 0) { 
-		    _INST(hitEOF) = true;
-		    RETURN (__MKSMALLINT(cnt));
-		}
-
-		_INST(position) = nil;
-		_INST(lastErrorNumber) = __MKSMALLINT(errno);
-	    }
-	}
+        if (__bothSmallInteger(count, start)) {
+            f = __FILEVal(fp);
+
+            oClass = __Class(anObject);
+            switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+                case BYTEARRAY:
+                case WORDARRAY:
+                case LONGARRAY:
+                case FLOATARRAY:
+                case DOUBLEARRAY:
+                    break;
+                default:
+                    goto bad;
+            }
+            cnt = __intVal(count);
+            offs = __intVal(start) - 1;
+            nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+            nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+            objSize = __Size(anObject) - nInstBytes;
+            if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
+                /* 
+                 * mhmh - since we are interruptable, anObject may move.
+                 * therefore, fetch the cp-pointer within the loop
+                 */
+                if (_INST(buffered) == true) {
+                    __READING__(f)
+                }
+
+                __BEGIN_INTERRUPTABLE__
+                for (;;) {
+                    errno = 0;
+                    /*
+                     * because we are interruptable, refetch pointer
+                     */
+                    cp = (char *)__InstPtr(anObject) + nInstBytes + offs;
+                    if (_INST(buffered) == false) {
+                        ret = read(fileno(f), cp, cnt);
+                    } else {
+                        if (feof(f)) {
+                            ret = 0;
+                            break;
+                        }
+                        ret = fread(cp, 1, cnt, f);
+                    }
+                    if (ret < 0) {
+                        if (errno == EINTR) 
+                            continue;
+                        else
+                            break;
+                    }   
+                    cnt -= ret;
+                    if (cnt == 0 || ret == 0)
+                        break;
+                    offs += ret;
+                } 
+
+                __END_INTERRUPTABLE__
+                cnt = __intVal(count) - cnt;
+
+                if (cnt > 0) {
+                    pos = _INST(position);
+                    if (pos != nil) {
+                        _INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
+                    }
+                    RETURN (__MKSMALLINT(cnt));
+                }
+                if (cnt == 0) { 
+                    _INST(hitEOF) = true;
+                    RETURN (__MKSMALLINT(cnt));
+                }
+
+                _INST(position) = nil;
+                _INST(lastErrorNumber) = __MKSMALLINT(errno);
+            }
+        }
     }
 bad: ;
 %}.
@@ -3545,6 +3555,6 @@
 !ExternalStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.87 1996-02-20 16:32:47 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.88 1996-02-29 10:18:33 stefan Exp $'
 ! !
 ExternalStream initialize!