ExternalStream.st
changeset 24778 f1e7d1b7437c
parent 24654 ed1f7d888617
child 25134 9eac80392554
--- a/ExternalStream.st	Fri Sep 13 08:41:56 2019 +0200
+++ b/ExternalStream.st	Sat Sep 14 17:59:46 2019 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1988 by Claus Gittinger
 	      All Rights Reserved
@@ -4901,7 +4899,7 @@
     "
 	(FileStream newTemporary
 	    nextPutUtf16:$B;
-	    nextPutUtf16:$Ä;
+	    nextPutUtf16:$Ä;
 	    nextPutUtf16:(Character codePoint:16r10CCCC);
 	    reset;
 	    binary;
@@ -6160,26 +6158,29 @@
     |fd outputSema hasTimedout wasBlocked|
 
     handle isNil ifTrue:[
-	^ self errorNotOpen
+        ^ self errorNotOpen
     ].
     mode == #readonly ifTrue:[
-	^ self errorReadOnly
+        ^ self errorReadOnly
     ].
 
     fd := self fileHandle.
     (OperatingSystem writeCheck:fd) ifTrue:[^ false].
 
     wasBlocked := OperatingSystem blockInterrupts.
-    outputSema := Semaphore name:'writeWait'.
-    hasTimedout := [
-	Processor signal:outputSema onOutput:fd.
-	(outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
-    ] ifCurtailed:[
-	Processor disableSemaphore:outputSema.
-	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
-    ].
-    hasTimedout ifTrue:[
-	Processor disableSemaphore:outputSema.
+    "/ check again - now inside lock
+    (OperatingSystem writeCheck:fd) ifFalse:[
+        outputSema := Semaphore name:'writeWait'.
+        hasTimedout := [
+            Processor signal:outputSema onOutput:fd.
+            (outputSema waitWithTimeoutMs:timeoutOrNil state:#ioWait) isNil.
+        ] ifCurtailed:[
+            Processor disableSemaphore:outputSema.
+            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+        ].
+        hasTimedout ifTrue:[
+            Processor disableSemaphore:outputSema.
+        ].
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
     ^ hasTimedout
@@ -6868,7 +6869,7 @@
     ].
 
     "
-	'Bönnigheim' asUnicode16String errorPrintCR
+	'Bönnigheim' asUnicode16String errorPrintCR
     "
 !