CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
sysopen blocks too much.


New User

Mar 4, 2003, 5:50 AM

Post #1 of 2 (572 views)
sysopen blocks too much. Can't Post

I am a client/server type architecture where I have one server process looping though a list of clients. I am using pipes for communication (this program is not sophisticated enough for sockets) and am using sysopen to block until another piece of data arrives on the pipe.

The problem is that sysopen blocks too hard! I know that if the pipe is broken during a read or write, perl provides a sigpipe error signal. But it does nothing if sysopen is just waiting for more information.

How can I protect against the deletion of the unix pipe, while the server program is running and waiting for more info, but not actively reading/writing at the time the pipe is destroyed?

Code below...

while (1) {
print "Waiting for incoming pipe\n";
sysopen(FIFO, $incomingPipe, O_RDONLY) or die "can't write $incomingPipe: $!";
print "Got it from incoming pipe\n";

while (<FIFO>) { # do while pipe is open forever.
print "read a line from incoming pipe\n";

my @params = split; # split all incoming parameters.
my $outgoingPipe = shift @params; # grab the first one.
logMessage(1, "Processing parcel : @params");

# now do all the work!
my $returnValue = &processParcel( @params );
print "Return Value 4 = $returnValue\n";

# write output to the outgoing pipe.
open (OUT_PIPE, "> $outgoingPipe");
print OUT_PIPE "$returnValue\n";
close OUT_PIPE;
print "Closing FIFO\n";
close FIFO;

(This post was edited by bkreitman on Mar 5, 2003, 7:40 AM)


Mar 14, 2003, 8:57 AM

Post #2 of 2 (560 views)
Re: [bkreitman] sysopen blocks too much. [In reply to] Can't Post

I'm guessing since you're using Pipes for your server/client program, that you are also using something like tcpcat on each end and simply redirecting that to the pipe?

If so, I think the best advice would be to actually re-write this section of code. If you take a look at the IO::Select module, it is very ideal for efficient multiple file nonblocking code. You could probably use this with your current Pipe configuration, but the perldoc on that module has a sample code that would get you WELL on your way, fast! in getting a full socket-based server program up and running.

Otherwise, you can open files in a non-blocking fashion in your "open" call. But concidering the instability and headaches that a server/client architecture using pipes presents, you'd really be better off implementing the above.

-- Jon


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives