changed:
authorStefan Vogel <sv@exept.de>
Mon, 01 Feb 2010 20:09:40 +0100
changeset 12678 662465401b77
parent 12677 aeab74b04f0b
child 12679 18c4eabbb673
changed: #closeFile #flush #flush: do fflush() in wrap call #clsoeFile: fflush() before fclose()
ExternalStream.st
--- a/ExternalStream.st	Mon Feb 01 19:20:44 2010 +0100
+++ b/ExternalStream.st	Mon Feb 01 20:09:40 2010 +0100
@@ -4225,7 +4225,9 @@
 
 clearEOF
     hitEOF := false
-!
+! !
+
+!ExternalStream protectedMethodsFor:'private'!
 
 closeFile
     "low level close - may be redefined in subclasses
@@ -4247,6 +4249,14 @@
                 fprintf(stderr, "fclose [ExternalStream] %x\n", f);
             }
 #ifdef WIN32
+            if (__INST(mode) != @symbol(readonly)) {
+                // do a fflush() first, so that fclose() doesn't block
+                // we suspect, that EINTR causes problems in fclose()
+                do {
+                    __threadErrno = 0;
+                    rslt = __STX_C_CALL1("fflush", fflush, f);
+                } while((rslt < 0) && (__threadErrno == EINTR));
+            }
             do {
                 __threadErrno = 0;
                 rslt = __STX_C_CALL1("fclose", fclose, f);
@@ -4279,7 +4289,9 @@
         handle := nil.
         self closeFile:fp
     ]
-!
+! !
+
+!ExternalStream methodsFor:'private'!
 
 closeFile:handle
     "for rel5 only"
@@ -5322,33 +5334,29 @@
      || (__INST(handleType) == @symbol(filePointer))
      || (__INST(handleType) == @symbol(socketFilePointer))
      || (__INST(handleType) == @symbol(pipeFilePointer))) {
-	if ((fp = __INST(handle)) != nil) {
-	    if (__INST(mode) != @symbol(readonly)) {
-		if (__INST(buffered) == true) {
-		    FILEPOINTER f = __FILEVal(fp);
-#ifdef WIN32
-		    if ((f == __win32_stdout()) || (f == __win32_stderr())) {
-			__win32_fflush(f);
-		    } else
-#endif
-		    {
+        if ((fp = __INST(handle)) != nil) {
+            if (__INST(mode) != @symbol(readonly)) {
+                if (__INST(buffered) == true) {
+                    FILEPOINTER f = __FILEVal(fp);
 #ifdef WIN32
-# if 1
-			FFLUSH(f);
-# else
-			__BEGIN_INTERRUPTABLE__
-			FFLUSH(f);
-			__END_INTERRUPTABLE__
-# endif
-#else
-			__BEGIN_INTERRUPTABLE__
-			FFLUSH(f);
-			__END_INTERRUPTABLE__
-#endif
-		    }
-		}
-	    }
-	}
+                    if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+                        __win32_fflush(f);
+                    } else {
+                        int rslt;
+
+                        do {
+                            __threadErrno = 0;
+                            rslt = __STX_C_CALL1("fflush", fflush, f);
+                        } while((rslt < 0) && (__threadErrno == EINTR));
+                    }
+#else /* ! WIN32 */
+                    __BEGIN_INTERRUPTABLE__
+                    FFLUSH(f);
+                    __END_INTERRUPTABLE__
+#endif /* ! WIN32 */
+                }
+            }
+        }
     }
 %}
 !
@@ -5631,11 +5639,11 @@
 !ExternalStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.332 2010-02-01 18:14:37 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.333 2010-02-01 19:09:40 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.332 2010-02-01 18:14:37 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.333 2010-02-01 19:09:40 stefan Exp $'
 ! !
 
 ExternalStream initialize!