[Glass] Is there a #upToEnd kind of read for a none blocking GsSocket?

Mariano Martinez Peck via Glass glass at lists.gemtalksystems.com
Wed Jul 5 11:48:00 PDT 2017


I am trying to use GsHostProcess and provide a polling API for it.
Something like this:


------

runAndWaitPollingEvery: pollingMsPeriod onExitDo: anExitBlock

  | process delay outStream errStream |
  delay := Delay forMilliseconds: pollingMsPeriod.
  outStream := WriteStream new.
  errStream := WriteStream new.

  process := GsHostProcess fork: aCommandString.

  [ process childHasExited ]
  whileFalse: [
delay wait.
                "retrieve all we have in the pipes to make room and avoid
locks"
outStream nextPutAll: *process stdout upToEnd.*
errStream nextPutAll: *process stderr upToEnd.*
].

  outStream nextPutAll: *process stdout upToEnd.*
  errStream nextPutAll: *process stderr upToEnd.*

  process stdout close.
  process stderr close.

  aBlock cull: outStream contents cull: errStream contents

--------

I tried to implement an GsSocket >> upToEnd like this:

-----
upToEnd
| newStream buffer nextBytes |
buffer := buffer1 species new: 1000.
newStream := WriteStream on: (buffer1 species new: 100).
[self readWillNotBlock not or: [(nextBytes := self read: buffer size into:
buffer startingAt: 1) isEmpty]]
whileFalse: [newStream nextPutAll: nextBytes].
^ newStream contents
-----

Does that sound correct?

Thanks a lot in advance,


-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20170705/1ccc0340/attachment.html>


More information about the Glass mailing list