[plt-scheme] select() and syscalls
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:
http://docs.plt-scheme.org/reference/sync.html
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.)
http://planet.plt-scheme.org/package-source/schematics/spgsql.plt/2/3/private/socket.ss
> In general, do I need to write C extensions to do syscalls, or is there a
> better way?
You can use the FFI:
http://docs.plt-scheme.org/foreign/index.html
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:
http://docs.plt-scheme.org/inside/index.html
Ryan