#FEATURE
authorStefan Vogel <sv@exept.de>
Wed, 25 Nov 2015 19:44:31 +0100
changeset 18956 9ef063595474
parent 18955 34d0eee1f6d9
child 18957 e0bb91eae748
#FEATURE class: ExternalStream added: #writeExceptionWaitWithTimeoutMs:
ExternalStream.st
--- a/ExternalStream.st	Wed Nov 25 19:43:30 2015 +0100
+++ b/ExternalStream.st	Wed Nov 25 19:44:31 2015 +0100
@@ -5613,6 +5613,44 @@
     ^ hasTimedout
 !
 
+writeExceptionWaitWithTimeoutMs:timeout
+    "suspend the current process, until the receiver
+     becomes ready for reading or writing or a timeout (in milliseconds) expired.
+     Return true if a timeout occured (i.e. false, if data is available).
+     Return immediate if the receiver is already ready.
+     The other threads are not affected by the wait."
+
+    |fd sema hasTimedout wasBlocked|
+
+    handle isNil ifTrue:[
+        ^ self errorNotOpen
+    ].
+
+    fd := self fileDescriptor.
+    (OperatingSystem writeExceptionCheck:fd) ifTrue:[^ false].
+
+    wasBlocked := OperatingSystem blockInterrupts.
+    sema := Semaphore new name:'writeExceptionWait'.
+    [
+        timeout notNil ifTrue:[
+            Processor signal:sema afterMilliseconds:timeout
+        ].
+        Processor signal:sema onOutput:fd.
+        Processor signal:sema onException:fd.
+        Processor activeProcess state:#ioWait.
+        sema wait.
+        hasTimedout := timeout notNil and:[(OperatingSystem readWriteCheck:fd) not].
+    ] ifCurtailed:[
+        Processor disableSemaphore:sema.
+        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+    ].
+    timeout notNil ifTrue:[
+        Processor disableSemaphore:sema.
+    ].
+    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+    ^ hasTimedout
+!
+
 writeWaitWithTimeoutMs:timeout
     "suspend the current process, until the receiver
      becomes ready for writing or a timeout (in milliseconds) expired.