[plt-scheme] select() and syscalls

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Sun Jul 5 01:04:53 EDT 2009

Tom Novelli wrote:
> I'm curious... does PLT Scheme support POSIX 'select'?  All I can find are
> Vyzo's 'socket' package and Matthew Flatt's mention of 'object-wait' 7 years
> ago: http://www.cs.utah.edu/plt/mailarch/plt-scheme-2002/msg00521.html (Yes,
> I'm interested in SCSH for PLT :-)

'object-wait' is now called 'sync', and it is designed to work with PLT 
Scheme's ports, which act as "synchronizable events". See the docs here:


If you just need sockets for simple IO, then you can use the FFI to 
create them and wrap them as Scheme ports. Then you can deal with them 
at the Scheme level, using 'sync' instead of the 'select' syscall. Even 
if you want to add other functionality to sockets, you might still use 
that as a starting point.

Here's code I've written to do that for Unix/local sockets. Feel free to 
take it and adapt it if you find it useful. (I don't know if Vyzo's 
package creates Scheme ports, but even if not it's probably possible to 
combine them.)


> In general, do I need to write C extensions to do syscalls, or is there a
> better way?

You can use the FFI:


For documentation on the internal C API (like the function that creates 
Scheme ports from a file descriptor, scheme_make_fd_output_port), see 
this document:



Posted on the users mailing list.