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

Comparing Coro/Coro/Handle.pm (file contents):
Revision 1.74 by root, Sat Jun 20 08:58:00 2009 UTC vs.
Revision 1.75 by root, Mon Jun 22 11:25:53 2009 UTC

294 294
295 $self 295 $self
296} 296}
297 297
298sub cleanup { 298sub cleanup {
299 eval { 299 # gets overriden for Coro::Event
300 $_[0][5]->cancel if $_[0][5];
301 $_[0][6]->cancel if $_[0][6];
302 };
303 @{$_[0]} = (); 300 @{$_[0]} = ();
304} 301}
305 302
306sub OPEN { 303sub OPEN {
307 &cleanup; 304 &cleanup;
364# when DumpValue::dumpValue is used to print this. 361# when DumpValue::dumpValue is used to print this.
365sub FETCH { 362sub FETCH {
366 "$_[0]<$_[0][1]>" 363 "$_[0]<$_[0][1]>"
367} 364}
368 365
369sub readable_anyevent { 366sub _readable_anyevent {
370 my $cb = Coro::rouse_cb; 367 my $cb = Coro::rouse_cb;
371 my $io = 1; 368 my $io = 1;
372 369
373 my $w = AnyEvent->io ( 370 my $w = AnyEvent->io (
374 fh => $_[0][0], 371 fh => $_[0][0],
387 Coro::rouse_wait; 384 Coro::rouse_wait;
388 385
389 $io 386 $io
390} 387}
391 388
392sub writable_anyevent { 389sub _writable_anyevent {
393 my $cb = Coro::rouse_cb; 390 my $cb = Coro::rouse_cb;
394 my $io = 1; 391 my $io = 1;
395 392
396 my $w = AnyEvent->io ( 393 my $w = AnyEvent->io (
397 fh => $_[0][0], 394 fh => $_[0][0],
410 Coro::rouse_wait; 407 Coro::rouse_wait;
411 408
412 $io 409 $io
413} 410}
414 411
415sub readable_coro { 412sub _readable_coro {
416 ($_[0][5] ||= "Coro::Event"->io ( 413 ($_[0][5] ||= "Coro::Event"->io (
417 fd => $_[0][0], 414 fd => $_[0][0],
418 desc => "fh $_[0][1] read watcher", 415 desc => "fh $_[0][1] read watcher",
419 timeout => $_[0][2], 416 timeout => $_[0][2],
420 poll => &Event::Watcher::R + &Event::Watcher::E + &Event::Watcher::T, 417 poll => &Event::Watcher::R + &Event::Watcher::E + &Event::Watcher::T,
421 ))->next->[4] & &Event::Watcher::R 418 ))->next->[4] & &Event::Watcher::R
422} 419}
423 420
424sub writable_coro { 421sub _writable_coro {
425 ($_[0][6] ||= "Coro::Event"->io ( 422 ($_[0][6] ||= "Coro::Event"->io (
426 fd => $_[0][0], 423 fd => $_[0][0],
427 desc => "fh $_[0][1] write watcher", 424 desc => "fh $_[0][1] write watcher",
428 timeout => $_[0][2], 425 timeout => $_[0][2],
429 poll => &Event::Watcher::W + &Event::Watcher::E + &Event::Watcher::T, 426 poll => &Event::Watcher::W + &Event::Watcher::E + &Event::Watcher::T,
430 ))->next->[4] & &Event::Watcher::W 427 ))->next->[4] & &Event::Watcher::W
431} 428}
432 429
433#sub readable_ev { 430#sub _readable_ev {
434# &EV::READ == Coro::EV::timed_io_once (fileno $_[0][0], &EV::READ , $_[0][2]) 431# &EV::READ == Coro::EV::timed_io_once (fileno $_[0][0], &EV::READ , $_[0][2])
435#} 432#}
436# 433#
437#sub writable_ev { 434#sub _writable_ev {
438# &EV::WRITE == Coro::EV::timed_io_once (fileno $_[0][0], &EV::WRITE, $_[0][2]) 435# &EV::WRITE == Coro::EV::timed_io_once (fileno $_[0][0], &EV::WRITE, $_[0][2])
439#} 436#}
440 437
441# decide on event model at runtime 438# decide on event model at runtime
442for my $rw (qw(readable writable)) { 439for my $rw (qw(readable writable)) {
443 no strict 'refs'; 440 no strict 'refs';
444 441
445 *$rw = sub { 442 *$rw = sub {
446 AnyEvent::detect; 443 AnyEvent::detect;
447 if ($AnyEvent::MODEL eq "AnyEvent::Impl::Coro" or $AnyEvent::MODEL eq "AnyEvent::Impl::Event") { 444 if ($AnyEvent::MODEL eq "AnyEvent::Impl::Event" and eval { require Coro::Event }) {
448 require Coro::Event;
449 *$rw = \&{"$rw\_coro"}; 445 *$rw = \&{"_$rw\_coro"};
450 } elsif ($AnyEvent::MODEL eq "AnyEvent::Impl::CoroEV" or $AnyEvent::MODEL eq "AnyEvent::Impl::EV") { 446 *cleanup = sub {
451 require Coro::EV; 447 eval {
448 $_[0][5]->cancel if $_[0][5];
449 $_[0][6]->cancel if $_[0][6];
450 };
451 @{$_[0]} = ();
452 };
453
454 } elsif ($AnyEvent::MODEL eq "AnyEvent::Impl::EV" and eval { require Coro::EV }) {
452 *$rw = \&{"Coro::EV::$rw\_ev"}; 455 *$rw = \&{"Coro::EV::_$rw\_ev"};
453 return &$rw; # Coro 5.0+ doesn't support goto &SLF, and this line is executed once only 456 return &$rw; # Coro 5.0+ doesn't support goto &SLF, and this line is executed once only
457
454 } else { 458 } else {
455 *$rw = \&{"$rw\_anyevent"}; 459 *$rw = \&{"_$rw\_anyevent"};
456 } 460 }
457 goto &$rw 461 goto &$rw
458 }; 462 };
459}; 463};
460 464

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines