[ts-gen] Hooking into shim directly via C/C++
pippin at owlriver.net
Mon Aug 31 15:04:22 EDT 2009
Thanks for the kind words about the order journaling. Thanks
also for contributing code to the list, and for helping other
> ... some sort of shim 'server' accepting new commands ... while
> still listening for tws ... I choose a select loop on a fifo/named
> pipe instead of opening a port ... allows ... simple things from
> bash/awk scripts ... I just echo all commands into the fifo.
> So I ...
While I'm at it, let me acknowledge some other posts: for Ken Feng
and Mike Gruen alike, glad you liked the archtecture writeup.
Now, back to the IO multiplexing issue. First, Nils, glad to see
you're already using select(). Next, , for those looking at the
man page for select, please note the following text that should be
included near the end:
> SEE ALSO
> For a tutorial with discussion and examples,
> see select_tut(2).
If you try man 2 select_tut, you should get the tutorial directly,
and if your system doesn't have it, still it's easy to find elsewhere
using google. If you read it for the first time, you may get bogged
down in the C programming language minutae, and perhaps believe it
has nothing to offer for ruby scripts. Not so!
There is a section "Select Law", including 11 rules that you should
at least understand before you break them. Rules 3, 4, and 9 are
especially important and apply equally to scripts as well as C
programs. Depending on the quality of the IO buffering layer in
your scripting language's libraries, the other rules may be
significant as well. If you want to ignore the C-specific details,
read at least the Description, feel free to then skip to the section
"Practical", and what ever you do, don't miss the following section
on the laws of select.
I repeat some of the laws below since they are absolutely critical,
but please see the original document as well.
3. No file descriptor must be added to any set if you do not intend to
check its result after the select() call, and respond appropri-
ately. See next rule.
4. After select() returns, all file descriptors in all sets should be
checked to see if they are ready.
9. If the functions read(2), recv(2), write(2), and send(2) fail with
errors other than those listed in 7., or one of the input functions
returns 0, indicating end of file, then you should not pass that
descriptor to select() again. In the above example, I close the
descriptor immediately, and then set it to -1 to prevent it being
included in a set.
This page is part of release 3.05 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
There are no author credits in the select_tut page besides the above
More information about the ts-general