Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: socket periodically loses data

by jhanna (Scribe)
on Feb 13, 2003 at 20:54 UTC ( #235105=note: print w/ replies, xml ) Need Help??


in reply to socket periodically loses data

here's the code in question... Maybe there's a more effecient way, but I think this aughta work...

$buf=''; if($fh->sysread($buf,10240)>0) { $this=$Con{$fh}; $buf=$this->{_}.$buf; while($buf=~/(.*\n)/g) { ${$Con{$fh}}{getline}($fh,$1); last unless $Con{$fh}; # it's possible that the connection can b +e deleted while there's still something in the buffer } if($Con{$fh}) { ($this->{_})=$buf=~/([^\n\r]*)$/s; if(length($this->{_}) > 10000) { ${$Con{$fh}}{getline}($fh,$this->{_}); ($this->{_})=''; } } } else { done($fh); }


Comment on Re: socket periodically loses data
Download Code
Re: Re: socket periodically loses data
by jhanna (Scribe) on Feb 13, 2003 at 23:45 UTC
    Probably nobody cares, but this was the fix:
    $buf=''; if($fh->sysread($buf,4096)>0) { d(2); $this=$Con{$fh}; $buf=$this->{_}.$buf; $bn=$lbn=-1; while(($bn=index($buf,"\n",$bn+1)) >= 0) { $s=substr($buf,$lbn+1,$bn-$lbn); #print DEBUG "doing <$2>\n" if $DEBUG; ${$Con{$fh}}{getline}($fh,$s); last unless $Con{$fh}; # it's possible that the connection can b +e deleted while there's still something in the buffer $lbn=$bn; } d(3); if($Con{$fh}) { ($this->{_})=substr($buf,$lbn+1); if(length($this->{_}) > 10000) { d(4); ${$Con{$fh}}{getline}($fh,$this->{_}); ($this->{_})=''; } } } else { d(5); done($fh); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://235105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2014-09-21 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls