ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Event/Handle.pm
(Generate patch)

Comparing Coro/Event/Handle.pm (file contents):
Revision 1.14 by root, Tue Oct 9 23:58:14 2001 UTC vs.
Revision 1.15 by root, Wed Oct 10 00:02:00 2001 UTC

139 139
140You can use this function to implement your own optimized reader when neither 140You can use this function to implement your own optimized reader when neither
141readline nor sysread are viable candidates, like this: 141readline nor sysread are viable candidates, like this:
142 142
143 # first get the _real_ non-blocking filehandle 143 # first get the _real_ non-blocking filehandle
144 # and fetch the current contents of the read buffer 144 # and fetch a reference to the read buffer
145 my $nb_fh = $fh->fh; 145 my $nb_fh = $fh->fh;
146 my $buf = $fh->rbuf; 146 my $buf = \$fh->rbuf;
147 147
148 for(;;) { 148 for(;;) {
149 # now use buffer contents, modifying 149 # now use buffer contents, modifying
150 # if necessary to reflect the removed data 150 # if necessary to reflect the removed data
151 151
152 last if $buf ne ""; # we have leftover data 152 last if $$buf ne ""; # we have leftover data
153 153
154 # read another buffer full of data 154 # read another buffer full of data
155 $fh->readable or die "end of file"; 155 $fh->readable or die "end of file";
156 sysread $nb_fh, $buf, 8192; 156 sysread $nb_fh, $$buf, 8192;
157 } 157 }
158
159 # put the read buffer back
160 $fh->rbuf = $buf;
161 158
162=cut 159=cut
163 160
164sub fh { 161sub fh {
165 (tied ${$_[0]})->[0]; 162 (tied ${$_[0]})->[0];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines