Here is my (curent) variation of the above gets function:

sub gets { my $timeout; my($str, $c, $rin, $rout, $found, $timeleft); #be really pessimistic about how long it will take for the fist char $timeout = 120; #time in seconds $rin = ''; vec($rin, fileno(COM), 1) = 1; while (1) { ($found, $timeleft) = select($rout=$rin, undef, undef, $timeout); + #look for input for up to $timeout seconds last unless $found; #give up if nothing was found $timeout = $timeout - $timeleft; $timeout ||= 15; #the $timeout must be >= 15 seconds sysread(COM, $c, 1); #read the next char if (($c ne "\0")&&($c =~ /[\w\*\-\t\:\/ ]/)) { #sanitize the data $str .= $c; #put the char at the end of the string } elsif ($c =~ /\r/) { #Note: must only match \n OR \r. Matching +both does odd stuff last; } } return $str; }

This version will hopefully take care of some of those *really* slow connections and not waste *too* much time after the transfer is complete.
As for performance, Im not terribly concerned because the datastream is at 1200 baud and sofar this has proven fast enough. It also allows me to do some filtering of the data as it comes in.


In reply to Re: Re: Re: Serial I/O and time question by shepner
in thread Serial I/O and time question by shepner

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.