Daemonizing CRM114 using FIFO

James Lee <csejl-/[email protected]>
Newsgroups gmane.mail.spam.crm114
Message-ID <[email protected]>
Hi,

I'm in the process of daemonizing CRM114 and had a few questions.  First, here's what I have so far:

- My C program (server) creates a FIFO (/tmp/dynamic_fifo) and runs this command: /usr/bin/crm /home/me/dynamic.crm < /home/me/start.txt

- /home/me/dynamic.crm looks like this:

{
    isolate (:content:)
 
  # classify dummy content to load the css files so that we don't have
to reinitialize repeatedly in the :do_it: function below
   
classify <osb unique microgroom> (\/home\/me\/css\/A.css
\/home\/me\/css\/B.css \/home\/me\/css\/C.css \/home\/me\/css\/D.css)
(:content:)
    :loop:
    syscall /:do_it: <\/tmp\/dynamic_fifo >>\/home\/me\/result\/result.txt /
    goto /:loop:/
    exit
}
{
    :do_it:
    input
 
  classify <osb unique microgroom> (\/home\/me\/css\/A.css
\/home\/me\/css\/B.css \/home\/me\/css\/C.css \/home\/me\/css\/D.css)
(:_dw:)
    output /lala :*:_dw:\n/
    exit
}

- Another C program (client) opens the FIFO in write-only mode and writes some content (a "message" to be classified) in a loop.

The
first issue I'm having is that I have to open() and close() the FIFO
every time I write inside the loop.  My finding is that the close()
call simulates typing ctrl-D on the console.  The second issue is that
I have to usleep() or run a dummy for-loop after the close() to make
sure CRM114 receives and acts upon one chunk of data at a time. 
Without the wait, my :do_it: function only gets called once.  I think
this has to do with how the kernel buffers and writes to FIFO.  It
appears that it ignores the close() if the same FIFO is opened and
written right away.

My goal is to have the server program run
forever and have the client send as many messages as possible as fast
as possible.  Having to open() and close() every time I send a message
slows down the process but it's not a biggie.  The wait part after each
close() seems to be the major performance bottleneck since I can only
sleep as little as 15-20 ms on the 2.4 kernel and 4-6 ms on the 2.6
kernel.  The dummy for-loop takes too many CPU cycles and is just as
slow.  And neither of them is a guaranteed solution.

In this
model, is there a way for me to use a special word or character to mark
the end of a message so the CRM114 part doesn't depend on whether
close() is received or not?  If not, is there a better way to
accomplish this?

Thanks in advance,

-James

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.