[Openmcl-devel] Read all available input from socket stream?

Zach Beane xach at xach.com
Wed Jul 24 05:59:24 PDT 2013

Gary Byers <gb at clozure.com> writes:

> Here's a very simple test case that tries to do something similar to
> what your code is apparently trying to do.
> ;---
> (defun server ()
>   (let* ((lsock (make-socket :connect :passive :local-host "localhost" :local-port 40000 :reuse-address t))
>          (data (make-array 10 :element-type '(unsigned-byte 8))))
>     (dotimes (i 10) (setf (aref data i) i))
>     (let* ((stream (accept-connection lsock :wait t)))
>       (write-sequence data stream)
>       (when t
>         (sleep 5)
>         (write-sequence data stream))
>       (close stream)
>       (close lsock))))
> (defun test ()
>   (process-run-function "server" #'server)
>   (let* ((stream (make-socket :remote-host "localhost" :remote-port 40000))
>          (data (make-array 19 :element-type '(unsigned-byte 8)))
>          (n (read-sequence data stream)))
>     (close stream)
>     (format t "~& requested 19 octets, got ~d" n)))
> ;---
> Calling (TEST) shoud pause for ~5 seconds, then report that it requested
> and go 19 octets.  Does this fail for you ?  If not, how does the code
> that you're dealing with differ ?
> If you change the WHEN T in #'SERVER to WHEN NIL (and wait a few minutes,
> since I'm likely not using :reuse-address correctly), the server will close
> its side of the connection after writing 10 octets; READ-SEQUENCE will see
> that the stream is at EOF after those 10 octets are read.  This (EOF) is the
> only situation in which READ-SEQUENCE should return prematurely, and it's the
> only situation I'm aware of in which it does so in CCL.

Is there another function available for when you want to get the
available 10 octets immediately?


More information about the Openmcl-devel mailing list