<div dir="ltr"><div><div><div>Cool! The open-fd-input-port is a great function. <br></div><br></div><div>Inotify cannot handle subtrees. I will try to make it more convenience. <br></div><div>I plan to make a tool like guard - <a href="https://github.com/guard/guard">https://github.com/guard/guard</a><br>
<br></div>It&#39;s useful to run unit tests while some files are changed.<br><br></div>Thanks,<br>Haiwei<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 30 January 2013 20:52, Laurent <span dir="ltr">&lt;<a href="mailto:laurent.orseau@gmail.com" target="_blank">laurent.orseau@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>For the record, Kevin Tew&#39;s function makes it easy to use:<br><a href="https://github.com/kazzmir/x11-racket/blob/master/fd.rkt" target="_blank">https://github.com/kazzmir/x11-racket/blob/master/fd.rkt</a><br>
<br></div>

<div>For example, that&#39;s what I use in my own version of libinotify FFI:<br><a href="https://github.com/Metaxal/linux-tools/blob/master/inotify.rkt" target="_blank">https://github.com/Metaxal/linux-tools/blob/master/inotify.rkt</a><span class="HOEnZb"><font color="#888888"><br>


</font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div>Laurent<br></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 30, 2013 at 12:28 PM, Tim Brown <span dir="ltr">&lt;<a href="mailto:tim@timb.net" target="_blank">tim@timb.net</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Resend... original (and previous resend!) sent from an address not<br>
valid for the list.<br>
<br>
---------- Forwarded message ----------<br>
From: Tim Brown &lt;<a href="mailto:tim.brown@timb.net" target="_blank">tim.brown@timb.net</a>&gt;<br>
Date: 30 January 2013 10:01<br>
Subject: Re: [racket] How to invoke a blocking foreign function<br>
without blocking whole racket?<br>
To: Haiwei Zhou &lt;<a href="mailto:highfly22@gmail.com" target="_blank">highfly22@gmail.com</a>&gt;<br>
Cc: <a href="mailto:users@racket-lang.org" target="_blank">users@racket-lang.org</a><br>
<br>
<br>
There are internal FFI calls: scheme_make_fd_input_port and<br>
scheme_make_fd_output_port, documented in<br>
<a href="http://docs.racket-lang.org/inside/Ports_and_the_Filesystem.html?q=to%20port#%28idx._%28gentag._480._%28lib._scribblings/inside/inside..scrbl%29%29%29" target="_blank">http://docs.racket-lang.org/inside/Ports_and_the_Filesystem.html?q=to%20port#(idx._(gentag._480._(lib._scribblings/inside/inside..scrbl)))</a><br>



<br>
If you would normally be able to poll (or select) from the port, then<br>
a little bit of work will allow you to tie your IO closer to the<br>
racket events system.<br>
<br>
There are more involved variants, I&#39;ve mostly only needed this level<br>
of access at the racket level; servicing the known-to-be ready fd is<br>
done by your FFI library.<br>
<span><font color="#888888"><br>
Tim<br>
</font></span><div><div><br>
On 30 Jan 2013 09:44, &quot;Haiwei Zhou&quot; &lt;<a href="mailto:highfly22@gmail.com" target="_blank">highfly22@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; 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>



&gt;<br>
&gt; After realized that the foreign function blocks the caller thread, I used dynamic-place 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>



&gt;<br>
&gt; Racket is amazing simple after you know the bloody details.<br>
&gt;<br>
&gt; Haiwei<br>
&gt;<br>
&gt;<br>
&gt; On 30 January 2013 14:23, Haiwei Zhou &lt;<a href="mailto:highfly22@gmail.com" target="_blank">highfly22@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi,<br>
&gt;&gt;<br>
&gt;&gt;  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>
&gt;&gt;<br>
&gt;&gt; (define _read (get-ffi-obj &quot;read&quot; libc (_fun #:async-apply (lambda (f) (f))<br>
&gt;&gt;                                              #:save-errno &#39;posix<br>
&gt;&gt;                                             _fd_t<br>
&gt;&gt;                                             (output : (_bytes o size))<br>
&gt;&gt;                                             (size : _uint32)<br>
&gt;&gt;                                             -&gt; (r : _int32)<br>
&gt;&gt;                                             -&gt; (values r saved-errno output))))<br>
&gt;&gt;<br>
&gt;&gt; I am confused by the term callback. Is the callback called in the racket thread or another OS thread?<br>
&gt;&gt;<br>
&gt;&gt; Thanks,<br>
&gt;&gt; Haiwei<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div><div><div>&gt; ____________________<br>
&gt;   Racket Users list:<br>
&gt;   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
&gt;<br>
____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>