I'm working on a project that works with a line by line protocols (POP3 and SMTP). I'm running into a problem where IO::Select->can_read is reporting that a socket doesn't have anything on it when it does. This only happens when I'm reading a bunch of lines from the socket (retrieving a message). Here's a boiled down test example that should connect, get a specified message, and then quit. I should probably be keeping track of states to know what to send next, but this is just to figure out the can_read problem. It hangs on the same line all the time, but will print everything out if more data comes in on the socket.
#!/usr/bin/perl use IO::Socket; use IO::Select; $user = shift || die "Usage: $0 user password server msgnum\n"; $pass = shift || die "Usage: $0 user password server msgnum\n"; $server = shift || die "Usage: $0 user password server msgnum\n"; $msgnum = shift || die "Usage: $0 user password server msgnum\n"; sub setgreen { print "\033[00;32m"; } sub setred { print "\033[00;31m"; } sub setnormal { printf "\033[00m"; } $dstsock = IO::Socket::INET->new( PeerAddr => $server, PeerPort => 110, Proto => 'tcp'); $readables = IO::Select->new(); $readables->add($dstsock); $notdone = 1; while ($notdone) { my @ready = $readables->can_read(0); foreach $sock (@ready) { $data = <$dstsock>; if ($data) { setred; print "$data"; setnormal; if ($data =~ /^\+OK Qpopper/) { print $dstsock "user $user\r\n"; setgreen(); print "user $pass\r\n"; setnormal; } if ($data =~ /^\+OK Password/) { print $dstsock "pass $pass\r\n"; setgreen(); print "pass $pass\r\n"; setnormal; } if ($data =~ /^\+OK $user/) { print $dstsock "retr $msgnum\r\n"; setgreen(); print "retr $msgnum\r\n"; setnormal; } if ($data =~ /^\.$/) { print $dstsock "quit\r\n"; setgreen(); print "quit\r\n"; setnormal; } } else { $notdone = 0; close $dstsock; close $srcsock; } } }

In reply to IO::Socket should be readable, but isn't.... by blogan

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.