[iolib-devel] Bug when using READ-LINE on non-blocking fds

Stelian Ionescu stelian.ionescu-zeus at poste.it
Sun Feb 8 13:09:08 UTC 2009


On Sun, 2009-02-08 at 02:16 -0500, Matthew Mondor wrote:
> On Sun, 08 Feb 2009 01:59:56 +0530
> Chaitanya Gupta <mail at chaitanyagupta.com> wrote:
> 
> > On that note, does iolib provide any function to read a chunk of data 
> > without blocking i.e. something like READ-CHAR-NO-HANG for sequences? 
> > (or, something akin to what read(2) provides when O_NONBLOCK is set).
> 
> It is possible to use RECEIVE-FROM which would signal
> IOLIB.SYSCALLS:EWOULDBLOCK if the socket is non-blocking and no
> remaining data is ready to read, or IOLIB.SYSCALLS:EINTR on reception
> of a signal, but I'm not sure if this could work with buffering, or if
> it would conflict with stream operations (i.e. in C you wouldn't use
> stdio fread()/fgets() and read() concurrently).

It's possible: you can use drain-input-buffer to copy data from the
buffers(it returns two values: the offset of the first element of the
sequence that wasn't overwritten, and the number of octets remaining in
the buffer or NIL if there aren't any left). After that you can use
receive-from. Technically, you can use it at any moment, but since there
may be data left in the stream buffer, you lose ordering of the stream
data)

> I've used RECEIVE-FROM without issues when creating sockets with 0
> bytes receive and send buffers and using custom buffers.

About receive-from, I should probably make it clearer in the
documentation that you must either specify (buffer,start,end) or size:
if you specify size and not buffer, a new array is consed and the data
is copied there.

> An example may be found at
> http://cvs.pulsar-zone.net/cgi-bin/cvsweb.cgi/mmondor/mmsoftware/cl/lib/rw-queue.lisp?rev=1.5;content-type=text%2Fplain
> (Note that READ-LINE-FROM-QUEUE and WRITE-STRING-TO-QUEUE are
> SBCL-specific as they use SB-EXT to convert between UTF-8 strings and
> 8-bit bytes representations).

Since you use iolib, you might as well use babel's o-t-s and s-t-o
functions.

-- 
Stelian Ionescu a.k.a. fe[nl]ix
Quidquid latine dictum sit, altum videtur.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/iolib-devel/attachments/20090208/b58a7eb3/attachment.sig>


More information about the iolib-devel mailing list