I'm running into some problems with IO::Select examining an IO::Pipe in ActivePerl 5.8.7 (stock install) on Windows XP. For some reason, even though the writing thread is indicating that it is writing to its end of the pipe, an IO::Select can_read([timeout]) call never indicates readiness. What's more, it doesn't seem to be blocking. Am I doing something wrong, or am I just running into an OS-compatibility brick wall?

The following is simple test code. It sets up a reading parent and a writing child. The child prints (syswrites, actually) "[W]" after every write. The parent should print "[r][d:HELLO!\n:d]" for every line it reads, but it prints "[x]" to indicate that it is not ready. Examining the scalar return of $ios->can_read(); shows a zero value, but the call does not block, as the documentation says it should in such a case.

That said, if someone can recommend a better method for information exchange between threads that is non-blocking (or at least can indicate blocking), and is cross-platform on stock Perl 5.8 installs, I'd be quite grateful. Pointers (um... I mean... references) to relevant docs or sites are greatly appreciated. Thanks!

use strict; use IO::Pipe; use IO::Select; my $pipe = new IO::Pipe; if ( fork() ) { print "Parent live\n"; $pipe->reader(); my $ios = IO::Select->new(); $ios->add($pipe); while (1) { print "Handles: " . scalar $ios->handles . ", " . scalar $ios->can_read(1) . " ready.\n"; if ( $ios->can_read(1) ) { while (<$pipe>) { syswrite( STDOUT, "[r]", 3 ); print "[d:$_:d]\n"; } } else { syswrite( STDOUT, "[b]", 3 ); sleep 1; } } } else { print "Child live\n"; $pipe->writer(); $pipe->autoflush(1); while (1) { $pipe->print("HELLO!\n"); syswrite( STDOUT, "[W]", 3 ); sleep 1; } }

Update: Thanks, everyone, for having a look. I'll be taking a look at local sockets... I think that'll work well.


In reply to IO::Select on an IO::Pipe not doing anything by FLEB

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.