I'm not familiar with what Net::Telnet does internally, but the following old usenet post may help.... it involves taking the fileevent on the FILEDESCRIPTOR of the socket. The following shows the filedescriptor accessed by sysread, but fileno probably could be used.
From: [1]Benjamin Goldberg ([2]goldbb2@earthlink.net) Subject: New FAQ idea. Newsgroups: [4]comp.lang.perl.misc Date: 2002-11-16 21:35:19 PST One question that is frequently asked: Why does my IO deadlock, even though I'm using IO::Select or Tk::fi +leevent? You've probably got some code which does something like this: $MW->fileevent( $socket, 'readable', sub { my $line = <$socket> or $MW->fileevent( $socket, 'readable', ''), return; # process $line } ); Or like this: my $select = IO::Select->new($socket); while( () = $select->can_read($timeout) ) { my $line = <$socket> or last; # process $line } The reason for the problem is that <> buffers data, but when IO::Selec +t and Tk::filehandle test for readability, they can only see the underlying *unbuffered* filedescriptor, and the data that gets buffere +d confuses them. The solution is to use the IO operator which works directly on the underlying unbuffered filedescriptor (sysread), and do your buffering yourself, in a seperate variable. Be very careful that sysread is onl +y called *once* for each time that you've been told that a handle is readable -- otherwise, it's quite possible that when the second call i +s made, no data will be there, and you'll get blocked. Change your code to be like one of the following: my $buffer = ""; $MW->fileevent( $socket, 'readable', sub { sysread( $socket, $buffer, 8192, length $buffer ) or $MW->fileevent( $socket, 'readable', '' ), return; while( $buffer =~ s/^(.*\n)// ) { my $line = $1; # process $line } } ); Or like this: my $select = IO::Select->new($socket); my $buffer = ""; while( () = $select->can_read($timeout) ) { sysread( $socket, $buffer, 8192, length $buffer ) or last; while( $buffer =~ s/^(.*\n)// ) { my $line = $1; # process $line } } It's important to be aware that one call to sysread can return less th +an one line, or it could return more than one line. By using a while loo +p in this manner, both cases are dealt with equally well.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: TK filehandle by zentara
in thread TK filehandle by willsthegreat

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.