ExternalStream.st
changeset 16551 352de37575d7
parent 16509 2cf139885242
child 16776 fd62ae0ff6fa
--- a/ExternalStream.st	Sat Jun 07 17:08:38 2014 +0200
+++ b/ExternalStream.st	Sat Jun 07 17:09:01 2014 +0200
@@ -2481,7 +2481,10 @@
 finalize
     "some Stream has been collected - close the file if not already done"
 
-    self closeFile
+    "/ with timeout to avoid blocking in a bad pty/socket
+    [
+        self closeFile
+    ] valueWithTimeout:30 seconds.
 ! !
 
 !ExternalStream methodsFor:'initialization'!
@@ -2992,6 +2995,150 @@
     ^ self errorUnsupportedOperation
 !
 
+reset
+    "set the read position to the beginning of the collection"
+
+    self position:0
+!
+
+setToEnd
+    "redefined since it must be implemented differently"
+
+    ^ self subclassResponsibility
+!
+
+sync
+    "make sure, that the OS writes cached data to the disk"
+
+    |error|
+
+    self flush.
+
+%{
+#if !defined(__openVMS__)
+    int fd;
+    int ret;
+    OBJ fp = __INST(handle);
+
+    if (fp == nil)
+	goto out;
+
+    if (__INST(handleType) == @symbol(socketHandle)) {
+	fd = __FILEVal(fp);
+    } else if ((__INST(handleType) == nil)
+	       || (__INST(handleType) == @symbol(filePointer))
+	       || (__INST(handleType) == @symbol(socketFilePointer))
+	       || (__INST(handleType) == @symbol(pipeFilePointer))) {
+	fd = fileno(__FILEVal(fp));
+    } else {
+	error = @symbol(badHandleType);
+	goto out;
+    }
+
+#ifdef WIN32
+     __threadErrno = 0;
+     ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd));
+     if (ret) {
+	 RETURN (self);
+     }
+#else
+     __BEGIN_INTERRUPTABLE__
+     do {
+	 ret = fsync(fd);
+     } while ((ret < 0) && (__threadErrno == EINTR));
+     __END_INTERRUPTABLE__
+
+     if (ret >= 0) {
+	 RETURN (self);
+     }
+#endif /* ! WIN32 */
+     error = __mkSmallInteger(__threadErrno);
+#endif /* ! __openVMS__ */
+out:;
+%}.
+    error notNil ifTrue:[
+	lastErrorNumber := error.
+	self ioError:error.
+	^ self.
+    ].
+    handle isNil ifTrue:[self errorNotOpen].
+
+    "
+	|f|
+	f := 'x' asFilename writeStream.
+	f nextPutAll:'hallo'; sync; syncData; close
+    "
+!
+
+syncData
+    "make sure, that the OS writes cached data to the disk.
+     In this case, metadata is only written, if it is
+     required to read the file's data (so metadata will not be written,
+     if only access/modification time has changed)."
+    |error|
+
+    self flush.
+
+%{
+#if !defined(__openVMS__)
+    int fd;
+    int ret;
+    OBJ fp = __INST(handle);
+
+    if (fp == nil)
+	goto out;
+
+    if (__INST(handleType) == @symbol(socketHandle)) {
+	fd = __FILEVal(fp);
+    } else if ((__INST(handleType) == nil)
+	       || (__INST(handleType) == @symbol(filePointer))
+	       || (__INST(handleType) == @symbol(socketFilePointer))
+	       || (__INST(handleType) == @symbol(pipeFilePointer))) {
+	fd = fileno(__FILEVal(fp));
+    } else {
+	error = @symbol(badHandleType);
+	goto out;
+    }
+
+#ifdef WIN32
+     __threadErrno = 0;
+     ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd));
+     if (ret) {
+	 RETURN (self);
+     }
+#else
+     __BEGIN_INTERRUPTABLE__
+     do {
+	 ret = fdatasync(fd);
+     } while ((ret < 0) && (__threadErrno == EINTR));
+     __END_INTERRUPTABLE__
+
+     if (ret >= 0) {
+	 RETURN (self);
+     }
+#endif /* ! WIN32 */
+     error = __mkSmallInteger(__threadErrno);
+#endif /* ! __openVMS__ */
+out:;
+%}.
+
+    error notNil ifTrue:[
+	lastErrorNumber := error.
+	self ioError:error.
+	^ self.
+    ].
+    handle isNil ifTrue:[^ self errorNotOpen].
+
+    "if notdef HAS_DATASYNC, fall back"
+    self sync.
+
+    "
+	|f|
+	f := 'x' asFilename writeStream.
+	f nextPutAll:'hallo'; sync; syncData; close
+    "
+!
+
 tcgetattr
     "unix only:
      provide the information of a tcgetattr call as a dictionary.
@@ -3184,150 +3331,6 @@
     lflags at:#extproc put:extproc.
     lflags at:#tostop put:tostop.
     ^ ret
-!
-
-reset
-    "set the read position to the beginning of the collection"
-
-    self position:0
-!
-
-setToEnd
-    "redefined since it must be implemented differently"
-
-    ^ self subclassResponsibility
-!
-
-sync
-    "make sure, that the OS writes cached data to the disk"
-
-    |error|
-
-    self flush.
-
-%{
-#if !defined(__openVMS__)
-    int fd;
-    int ret;
-    OBJ fp = __INST(handle);
-
-    if (fp == nil)
-	goto out;
-
-    if (__INST(handleType) == @symbol(socketHandle)) {
-	fd = __FILEVal(fp);
-    } else if ((__INST(handleType) == nil)
-	       || (__INST(handleType) == @symbol(filePointer))
-	       || (__INST(handleType) == @symbol(socketFilePointer))
-	       || (__INST(handleType) == @symbol(pipeFilePointer))) {
-	fd = fileno(__FILEVal(fp));
-    } else {
-	error = @symbol(badHandleType);
-	goto out;
-    }
-
-#ifdef WIN32
-     __threadErrno = 0;
-     ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd));
-     if (ret) {
-	 RETURN (self);
-     }
-#else
-     __BEGIN_INTERRUPTABLE__
-     do {
-	 ret = fsync(fd);
-     } while ((ret < 0) && (__threadErrno == EINTR));
-     __END_INTERRUPTABLE__
-
-     if (ret >= 0) {
-	 RETURN (self);
-     }
-#endif /* ! WIN32 */
-     error = __mkSmallInteger(__threadErrno);
-#endif /* ! __openVMS__ */
-out:;
-%}.
-    error notNil ifTrue:[
-	lastErrorNumber := error.
-	self ioError:error.
-	^ self.
-    ].
-    handle isNil ifTrue:[self errorNotOpen].
-
-    "
-	|f|
-	f := 'x' asFilename writeStream.
-	f nextPutAll:'hallo'; sync; syncData; close
-    "
-!
-
-syncData
-    "make sure, that the OS writes cached data to the disk.
-     In this case, metadata is only written, if it is
-     required to read the file's data (so metadata will not be written,
-     if only access/modification time has changed)."
-    |error|
-
-    self flush.
-
-%{
-#if !defined(__openVMS__)
-    int fd;
-    int ret;
-    OBJ fp = __INST(handle);
-
-    if (fp == nil)
-	goto out;
-
-    if (__INST(handleType) == @symbol(socketHandle)) {
-	fd = __FILEVal(fp);
-    } else if ((__INST(handleType) == nil)
-	       || (__INST(handleType) == @symbol(filePointer))
-	       || (__INST(handleType) == @symbol(socketFilePointer))
-	       || (__INST(handleType) == @symbol(pipeFilePointer))) {
-	fd = fileno(__FILEVal(fp));
-    } else {
-	error = @symbol(badHandleType);
-	goto out;
-    }
-
-#ifdef WIN32
-     __threadErrno = 0;
-     ret = __STX_API_NOINT_CALL1( "FlushFileBuffers", FlushFileBuffers, _get_osfhandle(fd));
-     if (ret) {
-	 RETURN (self);
-     }
-#else
-     __BEGIN_INTERRUPTABLE__
-     do {
-	 ret = fdatasync(fd);
-     } while ((ret < 0) && (__threadErrno == EINTR));
-     __END_INTERRUPTABLE__
-
-     if (ret >= 0) {
-	 RETURN (self);
-     }
-#endif /* ! WIN32 */
-     error = __mkSmallInteger(__threadErrno);
-#endif /* ! __openVMS__ */
-out:;
-%}.
-
-    error notNil ifTrue:[
-	lastErrorNumber := error.
-	self ioError:error.
-	^ self.
-    ].
-    handle isNil ifTrue:[^ self errorNotOpen].
-
-    "if notdef HAS_DATASYNC, fall back"
-    self sync.
-
-    "
-	|f|
-	f := 'x' asFilename writeStream.
-	f nextPutAll:'hallo'; sync; syncData; close
-    "
 ! !
 
 !ExternalStream methodsFor:'non homogenous reading'!
@@ -6088,11 +6091,11 @@
 !ExternalStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.392 2014-06-02 11:50:27 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.393 2014-06-07 15:09:01 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.392 2014-06-02 11:50:27 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.393 2014-06-07 15:09:01 cg Exp $'
 ! !