| | 12 | use fields ('my_attribute'); |
|---|
| | 13 | |
|---|
| | 14 | sub new { |
|---|
| | 15 | my My::Socket $self = shift; |
|---|
| | 16 | $self = fields::new($self) unless ref $self; |
|---|
| | 17 | $self->SUPER::new( @_ ); |
|---|
| | 18 | |
|---|
| | 19 | $self->{my_attribute} = 1234; |
|---|
| | 20 | return $self; |
|---|
| | 21 | } |
|---|
| | 22 | |
|---|
| | 23 | sub event_err { ... } |
|---|
| | 24 | sub event_hup { ... } |
|---|
| | 25 | sub event_write { ... } |
|---|
| | 26 | sub event_read { ... } |
|---|
| | 27 | sub close { ... } |
|---|
| | 28 | |
|---|
| | 29 | $my_sock->tcp_cork($bool); |
|---|
| | 30 | |
|---|
| | 31 | # write returns 1 if all writes have gone through, or 0 if there |
|---|
| | 32 | # are writes in queue |
|---|
| | 33 | $my_sock->write($scalar); |
|---|
| | 34 | $my_sock->write($scalarref); |
|---|
| | 35 | $my_sock->write(sub { ... }); # run when previous data written |
|---|
| | 36 | $my_sock->write(undef); # kick-starts |
|---|
| | 37 | |
|---|
| | 38 | # read max $bytecount bytes, or undef on connection closed |
|---|
| | 39 | $scalar_ref = $my_sock->read($bytecount); |
|---|
| | 40 | |
|---|
| | 41 | # watch for writability. not needed with ->write(). write() |
|---|
| | 42 | # will automatically turn on watch_write when you wrote too much |
|---|
| | 43 | # and turn it off when done |
|---|
| | 44 | $my_sock->watch_write($bool); |
|---|
| | 45 | |
|---|
| | 46 | # watch for readability |
|---|
| | 47 | $my_sock->watch_read($bool); |
|---|
| | 48 | |
|---|
| | 49 | # if you read too much and want to push some back on |
|---|
| | 50 | # readable queue. (not incredibly well-tested) |
|---|
| | 51 | $my_sock->push_back_read($buf); # scalar or scalar ref |
|---|
| | 52 | |
|---|
| | 53 | Danga::Socket->AddOtherFds(..); |
|---|
| | 54 | Danga::Socket->SetLoopTimeout(..); |
|---|
| | 55 | Danga::Socket->DescriptorMap(); |
|---|
| | 56 | Danga::Socket->WatchedSockets(); # count of DescriptorMap keys |
|---|
| | 57 | Danga::Socket->SetPostLoopCallback($code); |
|---|
| | 58 | Danga::Socket->EventLoop(); |
|---|
| 14 | | event-driven asynchronous IO. |
|---|
| | 63 | event-driven asynchronous IO, designed to be fast. |
|---|
| | 64 | |
|---|
| | 65 | Callers subclass Danga::Socket. Danga::Socket's constructor registers |
|---|
| | 66 | itself with the Danga::Socket event loop (which uses the efficient |
|---|
| | 67 | epoll on Linux 2.6) and invokes callbacks on the object for readability, |
|---|
| | 68 | writability, errors, and other conditions. |
|---|
| | 69 | |
|---|
| | 70 | =head1 MORE INFO |
|---|
| | 71 | |
|---|
| | 72 | For now, see servers using Danga::Socket for guidance. For example: |
|---|
| | 73 | perlbal, mogilefsd, or ddlockd. |
|---|
| | 74 | |
|---|
| | 75 | =head1 AUTHORS |
|---|
| | 76 | |
|---|
| | 77 | Brad Fitzpatrick <brad@danga.com>, Michael Granger <ged@danga.com>, |
|---|
| | 78 | Mark Smith <marksmith@danga.com> |
|---|
| | 79 | |
|---|
| | 80 | =head1 BUGS |
|---|
| | 81 | |
|---|
| | 82 | Not documented. |
|---|
| | 83 | |
|---|
| | 84 | Doesn't use kqueue on FreeBSD because it looks hard to do without XS |
|---|
| | 85 | which this code happily avoids. (epoll is implemented with only |
|---|
| | 86 | Perl's 'syscall') |
|---|
| | 87 | |
|---|
| | 88 | Syscall numbers 254, 255, and 256 are used when SYS_epoll_* constants |
|---|
| | 89 | aren't available, but those numbers are hard-coded values from the i386 |
|---|
| | 90 | Linux architecture. |
|---|
| | 91 | |
|---|
| | 92 | The packed data used with the epoll syscalls is likely only to work on |
|---|
| | 93 | 32-bit Linux x86. None of this code has been tested much on other |
|---|
| | 94 | platforms or architectures. |
|---|
| | 95 | |
|---|
| | 96 | =head1 LICENSE |
|---|
| | 97 | |
|---|
| | 98 | License is granted to use and distribute this module under the same |
|---|
| | 99 | terms as Perl itself. |
|---|