On Sun, 2009-02-08 at 02:16 -0500, Matthew Mondor wrote:
On Sun, 08 Feb 2009 01:59:56 +0530 Chaitanya Gupta mail@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-q... (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.