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.8 by root, Mon Sep 24 00:16:30 2001 UTC vs.
Revision 1.9 by root, Mon Sep 24 00:51:19 2001 UTC

15=over 4 15=over 4
16 16
17=cut 17=cut
18 18
19package Coro::Handle; 19package Coro::Handle;
20
21no warnings;
20 22
21use Errno (); 23use Errno ();
22use base 'Exporter'; 24use base 'Exporter';
23 25
24$VERSION = 0.45; 26$VERSION = 0.45;
56 58
57sub unblock($) { 59sub unblock($) {
58 new_from_fh Coro::Handle $_[0]; 60 new_from_fh Coro::Handle $_[0];
59} 61}
60 62
61sub read { read $_[0], $_[1], $_[2], $_[3] }
62sub sysread { sysread $_[0], $_[1], $_[2], $_[3] }
63sub syswrite { syswrite $_[0], $_[1], $_[2], $_[3] }
64
65=item $fh->writable, $fh->readable 63=item $fh->writable, $fh->readable
66 64
67Wait until the filehandle is readable or writable (and return true) or 65Wait until the filehandle is readable or writable (and return true) or
68until an error condition happens (and return false). 66until an error condition happens (and return false).
69 67
89 87
90=cut 88=cut
91 89
92sub autoflush { !0 } 90sub autoflush { !0 }
93 91
94=item $fh->fileno, $fh->close 92=item $fh->fileno, $fh->close,
93$fh->read, $fh->sysread, $fh->syswrite,
94$fh->print, $fh->printf
95 95
96Work like their function equivalents. 96Work like their function equivalents (except read, which works like
97sysread. You should not use the read function with Coro::Handles, it will
98work but it's not efficient).
97 99
98=cut 100=cut
99 101
100sub fileno { tied(${$_[0]})->FILENO } 102sub read { Coro::Handle::FH::READ (tied ${$_[0]}, $_[1], $_[2], $_[3]) }
101sub close { tied(${$_[0]})->CLOSE } 103sub sysread { Coro::Handle::FH::READ (tied ${$_[0]}, $_[1], $_[2], $_[3]) }
104sub syswrite { Coro::Handle::FH::WRITE (tied ${$_[0]}, $_[1], $_[2], $_[3]) }
105sub print { Coro::Handle::FH::WRITE (tied ${+shift}, join "", @_) }
106sub printf { Coro::Handle::FH::PRINTF(tied ${+shift}, @_) }
107sub fileno { Coro::Handle::FH::FILENO(tied ${$_[0]}) }
108sub close { Coro::Handle::FH::CLOSE (tied ${$_[0]}) }
102 109
103=item $fh->timeout([...]) 110=item $fh->timeout([...])
104 111
105The optional agrument sets the new timeout (in seconds) for this 112The optional agrument sets the new timeout (in seconds) for this
106handle. Returns the current (new) value. 113handle. Returns the current (new) value.
131 tied(${$_[0]})->{fh}; 138 tied(${$_[0]})->{fh};
132} 139}
133 140
134package Coro::Handle::FH; 141package Coro::Handle::FH;
135 142
143no warnings;
144
136use Fcntl (); 145use Fcntl ();
137use Errno (); 146use Errno ();
138use Carp 'croak'; 147use Carp 'croak';
139 148
140use Coro::Event; 149use Coro::Event;
141use Event::Watcher qw(R W E); 150use Event::Watcher qw(R W E);
142
143use base 'Tie::Handle';
144 151
145# formerly a hash, but we are speed-critical, so try 152# formerly a hash, but we are speed-critical, so try
146# to be faster even if it hurts. 153# to be faster even if it hurts.
147# 154#
148# 0 FH 155# 0 FH
186 if ($r) { 193 if ($r) {
187 fcntl $self->[0], &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK 194 fcntl $self->[0], &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK
188 or croak "fcntl(O_NONBLOCK): $!"; 195 or croak "fcntl(O_NONBLOCK): $!";
189 } 196 }
190 $r; 197 $r;
198}
199
200sub PRINT {
201 WRITE($_[0], $_[1]);
202}
203
204sub PRINTF {
205 WRITE(shift, sprintf(shift,@_));
206}
207
208sub GETC {
209 my $buf;
210 READ($_[0], $buf, 1);
211 $buf;
212}
213
214sub BINMODE {
215 binmode $_[0][0];
216}
217
218sub TELL {
219 use Carp (); Carp::croak("Coro::Handle's don't support tell()");
220}
221
222sub SEEK {
223 use Carp (); Carp::croak("Coro::Handle's don't support seek()");
224}
225
226sub EOF {
227 use Carp (); Carp::croak("Coro::Handle's don't support eof()");
191} 228}
192 229
193sub CLOSE { 230sub CLOSE {
194 &cleanup; 231 &cleanup;
195 close $_[0][0]; 232 close $_[0][0];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines