[Glass] Is there a #upToEnd kind of read for a none blocking GsSocket?
Richard Sargent via Glass
glass at lists.gemtalksystems.com
Wed Jul 5 13:44:02 PDT 2017
GLASS mailing list wrote
> 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:
Mariano, I like what you are trying to do. But, I think the name you have
chosen is flawed.
The fact that you had to write a comment where you used it to explain what
you meant is a red flag for that. "retrieve all we have in the pipes" is
quite different from the usual Stream implementation for #upToEnd. It sounds
like you want to use a name more like #allAvailable. (Note that I don't
think that's the best possible name, but I don't have a better one at this
moment.)
> -----
> 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
>
> _______________________________________________
> Glass mailing list
> Glass at .gemtalksystems
> http://lists.gemtalksystems.com/mailman/listinfo/glass
--
View this message in context: http://forum.world.st/Is-there-a-upToEnd-kind-of-read-for-a-none-blocking-GsSocket-tp4953564p4953607.html
Sent from the GLASS mailing list archive at Nabble.com.
More information about the Glass
mailing list