[erlang-questions] Using select in a Port
jm
jeffm@REDACTED
Mon Oct 22 07:13:57 CEST 2007
Per Hedeland wrote:
> jm <jeffm@REDACTED> wrote:
>> it appears somthing is causing erlang to close stdin to the port,
>
> Yes, that was pretty clear from your earlier results.
Just had to prove it.
>> but
>> I'm scratching my head as to why as no error is logged by the node.
>
> Is the port owner process still running? The port gets automatically
> closed when the owner exits.
In cleaning up the code I'd introduced another bug which is what the
output in the email message was generated by. It was caused be me
leaving out a return(0) after the part which generated the response for
the list command. This caused it to fall though after sending the
correct response and execute
int process_command(const char *command, char *buf, int *index, note_t
*nlist) {
ei_x_buff result;
.....
/* Prepare the output buffer that will hold {ok, Result} or {error,
Reason} */
if (ei_x_new_with_version(&result) ||
ei_x_encode_tuple_header(&result, 2) ||
ei_x_encode_atom(&result, "error") ||
ei_x_encode_atom(&result, "unsupported_command"))
return(-1);
write_cmd(&result);
ei_x_free(&result);
return(0);
} /* end of function */
It does however make me further suspect that it's the event messages,
those not in response to commands, which the port is sending which is
causing the problem.
Rather than post snipets of code I've made it available at
http://ghostgun.com/software/erlang/inotify/notify_play_buggy.tar.bz2
I've been resisting this as I'd like to get it to work myself, worse I
think the bug is either starring me in the face or is a gap in my
knowledge of how to write an erlang port. Most of the code is straight
forward there's nothing really tricky anywhere. Second, this port/module
is Linux specific as it uses the inotify kernel interface. To run it
you'll need a Linux box with a recent kernel (2.6.13 or later, I'm using
2.6.21 on a debian box).
The way I've been testing it is to run the follow in the erlang shell
from within the base directory
> inotify:start().
> inotify:open().
> inotify:list().
> inotify:add(3, "file", all)
Then in another window cd to the base directory and
$ cat file
file is actually an empty file in the base directory. This triggers two
events open and close_nowrite. This is were it crashes. If you get
further than this your doing better than me.
As far as licensing is concerned, in case it matters to anyone reading
this, it's planned to release this under the Erlang Public License,
LGPL, or something similar once this is working.
Jeff.
More information about the erlang-questions
mailing list