[plt-scheme] FFI - C file handles -> scheme ports

From: Hans Oesterholt-Dijkema (hdnews at gawab.com)
Date: Sun Jan 14 16:47:51 EST 2007

> If I understand, then the question is Windows-specific.
> Under Unix, a socket is a file descriptor, and
> scheme_make_fd_input_port() is ok. Under Windows,
> scheme_make_fd_input_port() actually works with file handles, which
> have the C type HANDLE, and it does not work with Windows sockets.
> So, I think the question is whether there's anything exported by
> MzScheme's C API that is like scheme_make_fd_input_port() but for
> Windows sockets.
> Internally, there is such a function. It's not currently exposed in the
> C API. Would it be useful for me to change MzScheme so that it's
> exposed?
That's exactly what I was hoping for. The SQLite library has a busy 
handler mechanism,
but PostgreSQL hasn't. PostgreSQL asks the library user to do a select 
on the socket
returned by a call to PQsocket() to see if any data should be read.

This looks like a good way to wait on results from PostgeSQL using 
libpq. However,
I'm currently looking at spgsql.plt from PLaneT to replace the SQLID 
psql driver.

In that case I would not need the FFI for postgreSQL, however, I don't 
know about
the performance of this package.


> Another approach is to just create ports in Scheme using
> `make-input-port' and `make-output-port', and implement the various
> callbacks by using the FFI to access recv(), etc.
> The hardest part of this strategy is implementing the evt to indicate
> when data is available or when data can be written. To do that, you
> need to create a new type of evt via scheme_add_evt(), where the wakeup
> function uses scheme_fdset() (which, confusingly enough, works on
> sockets and not file handles under Windows).
> Matthew

Posted on the users mailing list.