I have a server script that runs all the time in a dialog with a remote device (IE via RS232). The remote device must get regular input from the perl script otherwise it alarms.
I want to connect to this process from a CGI script to ask it to get info from the device, to this end I have opened two pipes one for writing requests to the server application and one for the server to write back the requested data.
After working around the blocking behaviour of pipes (blocking interferes with the regular servicing of the device) I have encountered a problem I am having trouble solving. The CGI script is only intermittently connecting to the pipes, so most of the time there is no reader/writer on the named pipe endpoints from the servers point of view. If something goes wrong, and the server writes on the output pipe when there is no reader, then it gets a SIGPIPE (Ignored) and subsequent writes fail even if a reader subsequently connects and is present when writing.
Other that catching SIGPIPE, and reopening the pipe after each SIGPIPE, is there any other way to work around this problem. For example can I test if there is a reader on the pipe before writing to it ?
What better ways are there for a many-to-one connection than pipes that support non-blocking I/O.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.