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.10 by root, Mon Sep 24 01:36:21 2001 UTC vs.
Revision 1.11 by root, Mon Sep 24 02:05:44 2001 UTC

130 130
131Returns the "real" (non-blocking) filehandle. Use this if you want to 131Returns the "real" (non-blocking) filehandle. Use this if you want to
132do operations on the file handle you cannot do using the Coro::Handle 132do operations on the file handle you cannot do using the Coro::Handle
133interface. 133interface.
134 134
135=item $fh->unsysread($data) 135=item $fh->rbuf
136 136
137Pushes the given data into the input buffer. The following calls to 137Returns the current contents of the raed buffer (this is an lvalue, so you
138read/sysread will first return this data. 138can change the read buffer if you like).
139
140You can use this fucntion to implement your own optimized reader when neither
141readline nor sysread are viable candidates, like this:
142
143 # first get the _real_ non-blocking filehandle
144 # and fetch the current contents of the read buffer
145 my $nb_fh = $fh->fh;
146 my $buf = $fh->rbuf;
147
148 for(;;) {
149 # now use buffer contents, modifying
150 # if necessary to reflect the removed data
151
152 last if $buf ne ""; # we have leftover data
153
154 # read another buffer full of data
155 $fh->readable or die "end of file";
156 sysread $nb_fh, $buf, 8192;
157 }
158
159 # put the read buffer back
160 $fh->rbuf = $buf;
139 161
140=cut 162=cut
141 163
142sub fh { 164sub fh {
143 (tied ${$_[0]})->[0]; 165 (tied ${$_[0]})->[0];
144} 166}
145 167
146sub unsysread { 168sub rbuf : lvalue {
147 substr tied(${$_[0]})->[3], 0, 0, $_[1]; 169 tied(${$_[0]})->[3];
148} 170}
149 171
150package Coro::Handle::FH; 172package Coro::Handle::FH;
151 173
152no warnings qw(uninitialized); 174no warnings qw(uninitialized);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines