<p>There are internal FFI calls: scheme_make_fd_input_port and scheme_make_fd_output_port, documented in <a href="http://docs.racket-lang.org/inside/Ports_and_the_Filesystem.html?q=to%20port#(idx._(gentag._480._(lib._scribblings/inside/inside..scrbl)))">http://docs.racket-lang.org/inside/Ports_and_the_Filesystem.html?q=to%20port#(idx._(gentag._480._(lib._scribblings/inside/inside..scrbl)))</a></p>

<p>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.</p>
<p>There are more involved variants, I&#39;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.</p>
<p>Tim</p>
<div class="gmail_quote">On 30 Jan 2013 09:44, &quot;Haiwei Zhou&quot; &lt;<a href="mailto:highfly22@gmail.com">highfly22@gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Finally, I figured out the callback from this letter: <a href="http://lists.racket-lang.org/users/archive/2010-July/040409.html" target="_blank">http://lists.racket-lang.org/users/archive/2010-July/040409.html</a> . I wish I red this letter early.<br>

</div><div><br></div><div>After realized that the foreign function blocks the caller thread, I used <span title="Provided from: racket/place, racket"><span><a>dynamic-place</a></span></span><span></span> to create worker thread. The code is here : <a href="https://github.com/highfly22/alert/blob/master/inotify.rkt" target="_blank">https://github.com/highfly22/alert/blob/master/inotify.rkt</a><br>

<br></div><div>Racket is amazing simple after you know the bloody details.<br><br></div><div>Haiwei</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 30 January 2013 14:23, Haiwei Zhou <span dir="ltr">&lt;<a href="mailto:highfly22@gmail.com" target="_blank">highfly22@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi,<br><br></div> 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.<br>


<br>(define _read (get-ffi-obj &quot;read&quot; libc (_fun #:async-apply (lambda (f) (f))<br>                                             #:save-errno &#39;posix<br>                                            _fd_t<br>                                            (output : (_bytes o size))<br>


                                            (size : _uint32)<br>                                            -&gt; (r : _int32)<br>                                            -&gt; (values r saved-errno output))))<br></div>


<br></div><div>I am confused by the term callback. Is the callback called in the racket thread or another OS thread?<br><br></div><div>Thanks,<br>Haiwei<br></div></div>
</blockquote></div><br></div>
<br>____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div>