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