[Openmcl-devel] direct usage of socket file descriptor

Gary Byers gb at clozure.com
Sun May 8 00:09:37 PDT 2011

You can get at the socket handle via

(stream-device stream direction) ; where direction is one of :input or :output

For a socket-based stream, either value of direction will generally yield the
same handle.

You can generally do anything you want with the socket handle, but trying
to do I/O on the same socket (from the stream and from foreign code) concurrently
will generally have unpredictable effects.  These effects might be somewhat
different on Windows than on other OSes: blocking I/O operations on sockets
generally involve what Microsoft calls "overlapped I/O", and I don't know
what's documented to happen if an I/O operation is performed on a socket
while there's a pending overlapped I/O operation on the same socket.  I don't
think it's likely that that would cause some sort of memory corruption or
hard crash, but it might lead to some sort of unexpected behavior

You can probably lose in other ways (changing socket options ), but in the
case where it's known that the stream isn't doing I/O itself and has no
buffered data doing I/O on the socket directly shouldn't have any visible
effects.  The stream's just going to do I/O on the socket at various points
in time, to fill/flush its buffers, so doing that from foreign code should
work fine (as long as the stream and foreign code aren't getting in each
other's way.)

On Sun, 8 May 2011, Anton Vodonosov wrote:

> Hello.
> Is it safe to retrieve a socket handle like this:
>     (ccl::ioblock-device (ccl::stream-ioblock socket t))
> and then perform some IO on it directly (in foreign code).
> Can this lead to any problems (like the Windows crush we are discussing in another thread)?
> Best regards,
> - Anton
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list