[Openmcl-devel] Setting time out value when creating a connected stream socket with MAKE-SOCKET

Gary Byers gb at clozure.com
Wed Dec 26 13:18:58 PST 2007

Way back when (when threads were cooperatively scheduled), all
socketes were created non-blocking; you couldn't block indefinitely
waiting for network I/O without locking out the lisp scheduler,
so there was code that handled the EAGAIN/EWOULDBLOCK error that's
returned when an I/O operation on a non-blocking socket can't
complete immediately, and the lisp scheduler would do periodic
short-lived #_select calls to try to determine which thread's
sockets were ready to do I/O and which threads should therefore
get activated.

That's all (thankfully) gone, but there's still some low-level
I/O code that basically says "it'd be better to wait forever
in #_select than to wait forever in #_read",

Using non-blocking sockets and a #_select timeout was the traditional way of doing this,but it doesn't always work a whole lot better in C programs
than it would in Lisp programs.

Modern Unices define socket options (#$SO_RCVTIMEO and 
#$SO_SNDTIMEO) that cause reads and writes that block longer
than the specified time to return EAGAIN/EWOULDBLOCK.  So:

- If we only care about setting timeout options on socket creation,
it'd be fairly straightforward to add :READ-TIMEOUT and :WRITE-TIMEOUT
options to MAKE-SOCKET and arrange that those options set the
appropriate socket options.  (It'd be harder to set these options
on the fly, though that might be possible.)

- any current code in CCL that handles EAGAIN as a transient
condition on a non-blocking fd should be changed to signal
a timeout error if the fd in question is blocking.  (If the
fd in question is non-blocking, they may want to ask how
it got that way ...)

Would that do it (assuming that #$SO_RCVTIMEO and #$SO_SNDTIMEO
are implemented on all interesting platforms ?)

On Wed, 26 Dec 2007, Erik Huelsmann wrote:

> Hi,
> I'm still the maintainer of usocket [a cross Lisp, cross OS portable
> sockets abstraction layer/portability layer]. I've been kindly
> requested to extend the functionality of usocket with a user
> configurable time out period on a connected stream socket.
> Unfortunately, I've been unable to determine how I should achieve that
> with CCL. Since you have chosen to provide nearly the same interface
> as Franz, this is how Franz does it:
> (sys:with-timeout (<time-out-value> :connection-timed-out)
>  (make-socket :type :stream :connect :active :host
> "www.common-lisp.net" :port 80))
> which returns :connection-timed-out upon timeout.
> SBCL and CMUCL will allow me to implement the above using non-blocking
> sockets, but it looks like CCL won't let me create non-blocking
> sockets either...
> Could you give me any advice or pointers on how to proceed?
> Thanks in advance!
> bye,
> Erik.
> http://www.common-lisp.net/project/usocket/
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list