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

Comparing Coro/Event/Select.pm (file contents):
Revision 1.3 by root, Tue Aug 30 21:32:17 2005 UTC vs.
Revision 1.4 by root, Tue Nov 29 10:45:32 2005 UTC

26package Coro::Select; 26package Coro::Select;
27 27
28use base Exporter; 28use base Exporter;
29 29
30use Coro; 30use Coro;
31use Coro::Event;
31use Event; 32use Event;
32 33
33$VERSION = 1.31; 34$VERSION = 1.31;
34 35
35BEGIN { 36BEGIN {
37} 38}
38 39
39sub import { 40sub import {
40 my $pkg = shift; 41 my $pkg = shift;
41 if (@_) { 42 if (@_) {
42 $pkg->export(caller(0), @_); 43 $pkg->export (caller (0), @_);
43 } else { 44 } else {
44 $pkg->export("CORE::GLOBAL", "select"); 45 $pkg->export ("CORE::GLOBAL", "select");
45 } 46 }
46} 47}
47 48
48sub select(;*$$$) { # not the correct prototype, but well... :() 49sub select(;*$$$) { # not the correct prototype, but well... :()
49 if (@_ == 0) { 50 if (@_ == 0) {
50 return CORE::select; 51 return CORE::select;
51 } elsif (@_ == 1) { 52 } elsif (@_ == 1) {
52 return CORE::select $_[0]; 53 return CORE::select $_[0];
53 } elsif (defined $_[3] && !$_[3]) { 54 } elsif (defined $_[3] && !$_[3]) {
54 return CORE::select(@_); 55 return CORE::select (@_);
55 } else { 56 } else {
56 my $current = $Coro::current; 57 my $current = $Coro::current;
57 my $nfound = 0; 58 my $nfound = 0;
58 my @w; 59 my @w;
59 for ([0, 'r'], [1, 'w'], [2, 'e']) { 60 for ([0, 'r'], [1, 'w'], [2, 'e']) {
62 my $rvec = \$_[$i]; 63 my $rvec = \$_[$i];
63 for my $b (0 .. (8 * length $vec)) { 64 for my $b (0 .. (8 * length $vec)) {
64 if (vec $vec, $b, 1) { 65 if (vec $vec, $b, 1) {
65 (vec $$rvec, $b, 1) = 0; 66 (vec $$rvec, $b, 1) = 0;
66 push @w, 67 push @w,
67 Event->io(fd => $b, poll => $poll, cb => sub { 68 Event->io (fd => $b, poll => $poll, cb => sub {
68 (vec $$rvec, $b, 1) = 1; 69 (vec $$rvec, $b, 1) = 1;
69 $nfound++; 70 $nfound++;
70 $current->ready; 71 $current->ready;
71 }); 72 });
72 } 73 }
73 } 74 }
74 } 75 }
75 } 76 }
76 77
77 push @w, 78 push @w,
78 Event->timer(after => $_[3], cb => sub { 79 Event->timer (after => $_[3], cb => sub {
79 $current->ready; 80 $current->ready;
80 }); 81 });
81 82
82 Coro::schedule; 83 Coro::schedule;
83 # wait here 84 # wait here

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines