… | |
… | |
67 | Wait until the filehandle is readable or writable (and return true) or |
67 | Wait until the filehandle is readable or writable (and return true) or |
68 | until an error condition happens (and return false). |
68 | until an error condition happens (and return false). |
69 | |
69 | |
70 | =cut |
70 | =cut |
71 | |
71 | |
72 | sub readable { tied(${$_[0]})->readable } |
72 | sub readable { Coro::Handle::FH::readable(tied ${$_[0]}) } |
73 | sub writable { tied(${$_[0]})->writable } |
73 | sub writable { Coro::Handle::FH::writable(tied ${$_[0]}) } |
74 | |
74 | |
75 | =item $fh->readline([$terminator]) |
75 | =item $fh->readline([$terminator]) |
76 | |
76 | |
77 | Like the builtin of the same name, but allows you to specify the input |
77 | Like the builtin of the same name, but allows you to specify the input |
78 | record separator in a coroutine-safe manner (i.e. not using a global |
78 | record separator in a coroutine-safe manner (i.e. not using a global |
… | |
… | |
214 | $res += $r; |
214 | $res += $r; |
215 | last unless $len; |
215 | last unless $len; |
216 | } elsif ($! != Errno::EAGAIN) { |
216 | } elsif ($! != Errno::EAGAIN) { |
217 | last; |
217 | last; |
218 | } |
218 | } |
219 | last unless $self->writable; |
219 | last unless writable $self; |
220 | } |
220 | } |
221 | |
221 | |
222 | return $res; |
222 | return $res; |
223 | } |
223 | } |
224 | |
224 | |
… | |
… | |
251 | $res += $r; |
251 | $res += $r; |
252 | last unless $len && $r; |
252 | last unless $len && $r; |
253 | } elsif ($! != Errno::EAGAIN) { |
253 | } elsif ($! != Errno::EAGAIN) { |
254 | last; |
254 | last; |
255 | } |
255 | } |
256 | last unless $self->readable; |
256 | last unless readable $self; |
257 | } |
257 | } |
258 | |
258 | |
259 | return $res; |
259 | return $res; |
260 | } |
260 | } |
261 | |
261 | |
… | |
… | |
272 | return $res; |
272 | return $res; |
273 | } |
273 | } |
274 | my $r = sysread $self->{fh}, $self->{rb}, 8192, length $self->{rb}; |
274 | my $r = sysread $self->{fh}, $self->{rb}, 8192, length $self->{rb}; |
275 | if (defined $r) { |
275 | if (defined $r) { |
276 | return undef unless $r; |
276 | return undef unless $r; |
277 | } elsif ($! != Errno::EAGAIN || !$self->readable) { |
277 | } elsif ($! != Errno::EAGAIN || !readable $self) { |
278 | return undef; |
278 | return undef; |
279 | } |
279 | } |
280 | } |
280 | } |
281 | } |
281 | } |
282 | |
282 | |