GDBInternalPipeStream.st
changeset 62 e1e763c6ac19
parent 34 4662b462b28e
child 75 0b8ce7d74318
--- a/GDBInternalPipeStream.st	Wed Mar 04 22:03:48 2015 +0000
+++ b/GDBInternalPipeStream.st	Sun Mar 08 06:01:49 2015 +0000
@@ -1,5 +1,9 @@
+"{ Encoding: utf8 }"
+
 "{ Package: 'jv:libgdbs' }"
 
+"{ NameSpace: Smalltalk }"
+
 Stream subclass:#GDBInternalPipeStream
 	instanceVariableNames:'buffer first last accessLock dataAvailable spaceAvailable closed'
 	classVariableNames:'DefaultBufferSize'
@@ -305,6 +309,26 @@
     ] loop.
 
     "Modified: / 11-06-2014 / 21:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+peek
+    "return the next element from the stream but do not advance position (might block until something is written)"
+
+    | c |
+
+    [
+        accessLock critical:[
+            ("self hasData"last ~~ 0) ifTrue:[ 
+                c := buffer at: first.
+                ^ c
+            ] ifFalse:[ 
+                closed ifTrue:[ ^ nil ]
+            ].
+        ].
+        dataAvailable wait.
+    ] loop.
+
+    "Created: / 08-03-2015 / 05:54:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBInternalPipeStream methodsFor:'synchronization'!