Unexpected Result From Pipe Read

J

John

All:

I have set up a named pipe to transfer data between threads. While the
transfer is successful, I'm perplexed by the system messages I trap along
the way. As a necessity, I start attempting to read from the pipe ahead
of writing to the pipe using:

<code snip>

do {
open (FIFO_READ, "< $FIFO");
if ($!) {
print "Exception: $! - sleeping 1 seconds and trying again\n";
sleep(1);
} # end if
else {
print "No exception...\n";
$exception_flag = 0;
} # end else

} until ( !$exception_flag ) ;

The output continues to be "Exception: No such file or directory -
sleeping 1 seconds and trying again" until something is written to the
pipe at which time the exception becomes:

"Exception: Illegal seek - sleeping 1 seconds and trying again"

At this point the data is transfered, but I find it odd that this is the
exception message at this point in the process.

The pipe for writing is created with:

<code snip>

my $FIFO = $path;

unless (-p $FIFO) { # unless the file is not a pipe
system('/bin/mknod', $FIFO, 'p')
&& die "can't mknod $FIFO: $!";
} # end unless

# next line blocks until there is a reader

open(FIFO_WRITE, "> $FIFO") || die "can't write $FIFO: $!";
print "WRITE_TO_PIPE - Writing $phrase to pipe: $phrase\n";
print FIFO_WRITE "$phrase\n";
close FIFO_WRITE;
sleep 1; # to avoid dup signals

I am interested to hear your thoughts about the messages I'm receiving.
If you believe that this question is better suited for a Linux newsgroup,
please let me know and I will move this question over there.

Thanks in advance!

John
 
X

xhoster

John said:
All:

I have set up a named pipe to transfer data between threads. While the
transfer is successful, I'm perplexed by the system messages I trap along
the way. As a necessity, I start attempting to read from the pipe ahead
of writing to the pipe using:

<code snip>

do {
open (FIFO_READ, "< $FIFO");
if ($!) {

from perldoc perlvar:

$! If used numerically, yields the current value of the C
"errno" variable, or in other words, if a system or library
call fails, it sets this variable. This means that the
value of $! is meaningful only immediately after a failure:

Note the last sentence. You check the open itself for failure. Only if
the opened failed should you inspect $!.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top