ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.5 by root, Sun Dec 4 09:44:32 2005 UTC vs.
Revision 1.6 by root, Mon Dec 19 17:03:29 2005 UTC

183 connect $txn->{fh}, ... 183 connect $txn->{fh}, ...
184 and !$!{EWOULDBLOCK} 184 and !$!{EWOULDBLOCK}
185 and !$!{EINPROGRESS} 185 and !$!{EINPROGRESS}
186 and Carp::croak "unable to connect: $!\n"; 186 and Carp::croak "unable to connect: $!\n";
187 187
188Then it creates a write-watcher which gets called wehnever an error occurs 188Then it creates a write-watcher which gets called whenever an error occurs
189or the connection succeeds: 189or the connection succeeds:
190 190
191 $txn->{w} = AnyEvent->io (fh => $txn->{fh}, poll => 'w', cb => sub { $txn->fh_ready_w }); 191 $txn->{w} = AnyEvent->io (fh => $txn->{fh}, poll => 'w', cb => sub { $txn->fh_ready_w });
192 192
193And returns this transaction object. The C<fh_ready_w> callback gets 193And returns this transaction object. The C<fh_ready_w> callback gets
210 sysread $txn->{fh}, $txn->{buf}, length $txn->{$buf}; 210 sysread $txn->{fh}, $txn->{buf}, length $txn->{$buf};
211 211
212 if (end-of-file or data complete) { 212 if (end-of-file or data complete) {
213 $txn->{result} = $txn->{buf}; 213 $txn->{result} = $txn->{buf};
214 $txn->{finished}->broadcast; 214 $txn->{finished}->broadcast;
215 $txb->{cb}->($txn) of $txn->{cb}; # also call callback
215 } 216 }
216 217
217The C<result> method, finally, just waits for the finished signal (if the 218The C<result> method, finally, just waits for the finished signal (if the
218request was already finished, it doesn't wait, of course, and returns the 219request was already finished, it doesn't wait, of course, and returns the
219data: 220data:
220 221
221 $txn->{finished}->wait; 222 $txn->{finished}->wait;
222 return $txn->{buf}; 223 return $txn->{result};
223 224
224The actual code goes further and collects all errors (C<die>s, exceptions) 225The actual code goes further and collects all errors (C<die>s, exceptions)
225that occured during request processing. The C<result> method detects 226that occured during request processing. The C<result> method detects
226wether an exception as thrown (it is stored inside the $txn object) 227wether an exception as thrown (it is stored inside the $txn object)
227and just throws the exception, which means connection errors and other 228and just throws the exception, which means connection errors and other

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines