For the record, Kevin Tew's function makes it easy to use: https://github.com/kazzmir/x11-racket/blob/master/fd.rkt
For example, that's what I use in my own version of libinotify FFI: https://github.com/Metaxal/linux-tools/blob/master/inotify.rkt Laurent On Wed, Jan 30, 2013 at 12:28 PM, Tim Brown <t...@timb.net> wrote: > Resend... original (and previous resend!) sent from an address not > valid for the list. > > ---------- Forwarded message ---------- > From: Tim Brown <tim.br...@timb.net> > Date: 30 January 2013 10:01 > Subject: Re: [racket] How to invoke a blocking foreign function > without blocking whole racket? > To: Haiwei Zhou <highfl...@gmail.com> > Cc: users@racket-lang.org > > > There are internal FFI calls: scheme_make_fd_input_port and > scheme_make_fd_output_port, documented in > > http://docs.racket-lang.org/inside/Ports_and_the_Filesystem.html?q=to%20port#(idx._(gentag._480._(lib._scribblings/inside/inside..scrbl))) > > If you would normally be able to poll (or select) from the port, then > a little bit of work will allow you to tie your IO closer to the > racket events system. > > There are more involved variants, I've mostly only needed this level > of access at the racket level; servicing the known-to-be ready fd is > done by your FFI library. > > Tim > > On 30 Jan 2013 09:44, "Haiwei Zhou" <highfl...@gmail.com> wrote: > > > > Finally, I figured out the callback from this letter: > http://lists.racket-lang.org/users/archive/2010-July/040409.html . I wish > I red this letter early. > > > > After realized that the foreign function blocks the caller thread, I > used dynamic-place to create worker thread. The code is here : > https://github.com/highfly22/alert/blob/master/inotify.rkt > > > > Racket is amazing simple after you know the bloody details. > > > > Haiwei > > > > > > On 30 January 2013 14:23, Haiwei Zhou <highfl...@gmail.com> wrote: > >> > >> Hi, > >> > >> I try to wrap inotify API. After adding a watcher, I try to read > events from file descriptor. But the racket thread is blocking until the > read operation is done. Here is the definition of read. > >> > >> (define _read (get-ffi-obj "read" libc (_fun #:async-apply (lambda (f) > (f)) > >> #:save-errno 'posix > >> _fd_t > >> (output : (_bytes o size)) > >> (size : _uint32) > >> -> (r : _int32) > >> -> (values r saved-errno > output)))) > >> > >> I am confused by the term callback. Is the callback called in the > racket thread or another OS thread? > >> > >> Thanks, > >> Haiwei > > > > > > > > ____________________ > > Racket Users list: > > http://lists.racket-lang.org/users > > > ____________________ > Racket Users list: > http://lists.racket-lang.org/users >
____________________ Racket Users list: http://lists.racket-lang.org/users