Lisp HUG Maillist Archive

Waiting for (some) input available?

I have a socket stream and I'd like to use READ-SEQUENCE on it when
there's some data available. However, I don't want to wait until there's
necessarily a full sequence's worth of data available. I think I want
something like this:

  - (setf socket (open-tcp-stream ... :read-timeout 0))

  - (setf buffer (make-array 1024 :element-type '(unsigned-byte 8)))

  - (some-waiting-function socket)

  - (read-sequence buffer socket)

The last step would immediately read some pending octets from the
socket, if there were any. 

I don't think I want a read-timeout of nil on the stream, since that
seems to wait until the buffer is completely full.

What should I do in place of some-waiting-function? Or is there some
other approach to read whatever's available on a socket, regardless of
the amount of data it might be?

Zach


Re: Waiting for (some) input available?

On 1 Oct 2008, at 16:13, Zach Beane wrote:
>
> I have a socket stream and I'd like to use READ-SEQUENCE on it when
> there's some data available. However, I don't want to wait until  
> there's
> necessarily a full sequence's worth of data available. I think I want
> something like this:
>
>  - (setf socket (open-tcp-stream ... :read-timeout 0))
>
>  - (setf buffer (make-array 1024 :element-type '(unsigned-byte 8)))
>
>  - (some-waiting-function socket)
>
>  - (read-sequence buffer socket)
>
> The last step would immediately read some pending octets from the
> socket, if there were any.
>
> I don't think I want a read-timeout of nil on the stream, since that
> seems to wait until the buffer is completely full.
>
> What should I do in place of some-waiting-function? Or is there some
> other approach to read whatever's available on a socket, regardless of
> the amount of data it might be?



wait-for-input-streams-returning-first  seems like it's what you are  
after.


see http://www.lispworks.com/documentation/lw50/LWRM/html/lwref-728.htm



Sean


Updated at: 2020-12-10 08:42 UTC