Changeset 26

Show
Ignore:
Timestamp:
10/18/04 17:55:33 (4 years ago)
Author:
bradfitz
Message:

more docs, getting ready for a release

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MANIFEST

    r15 r26  
    22MANIFEST 
    33Socket.pm 
     4META.yml                                 Module meta-data (added by MakeMaker) 
  • trunk/Makefile.PL

    r5 r26  
    1515    NAME                    => 'Danga::Socket', 
    1616    VERSION_FROM            => 'Socket.pm', # finds $VERSION 
    17     AUTHOR                  => 'Michael Granger <ged@danga.com>', 
     17    AUTHOR                  => 'Brad Fitzpatrick <brad@danga.com>', 
    1818    ABSTRACT                => 'Async socket class', 
    1919    PREREQ_PM               => { 
     
    2525        CI                      => "cvs commit", 
    2626        RCS_LABEL               => 'cvs tag RELEASE_$(VERSION_SYM)', 
    27         SUFFIX                  => ".bz2", 
     27        SUFFIX                  => ".gz", 
    2828        DIST_DEFAULT            => 'all tardist', 
    29         COMPRESS                => "bzip2", 
     29        COMPRESS                => "gzip", 
    3030    }, 
    3131 
  • trunk/Socket.pm

    r25 r26  
    33=head1 NAME 
    44 
    5 Danga::Socket - Event-driven async IO class 
     5Danga::Socket - Event loop and event-driven async socket base class 
    66 
    77=head1 SYNOPSIS 
    88 
     9  package My::Socket 
     10  use Danga::Socket; 
    911  use base ('Danga::Socket'); 
     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(); 
    1059 
    1160=head1 DESCRIPTION 
    1261 
    1362This is an abstract base class which provides the basic framework for 
    14 event-driven asynchronous IO. 
     63event-driven asynchronous IO, designed to be fast. 
     64 
     65Callers subclass Danga::Socket.  Danga::Socket's constructor registers 
     66itself with the Danga::Socket event loop (which uses the efficient 
     67epoll on Linux 2.6) and invokes callbacks on the object for readability, 
     68writability, errors, and other conditions. 
     69 
     70=head1 MORE INFO 
     71 
     72For now, see servers using Danga::Socket for guidance.  For example: 
     73perlbal, mogilefsd, or ddlockd. 
     74 
     75=head1 AUTHORS 
     76 
     77Brad Fitzpatrick <brad@danga.com>, Michael Granger <ged@danga.com>, 
     78Mark Smith <marksmith@danga.com> 
     79 
     80=head1 BUGS 
     81 
     82Not documented. 
     83 
     84Doesn't use kqueue on FreeBSD because it looks hard to do without XS 
     85which this code happily avoids.  (epoll is implemented with only 
     86Perl's 'syscall') 
     87 
     88Syscall numbers 254, 255, and 256 are used when SYS_epoll_* constants 
     89aren't available, but those numbers are hard-coded values from the i386 
     90Linux architecture. 
     91 
     92The packed data used with the epoll syscalls is likely only to work on 
     9332-bit Linux x86.  None of this code has been tested much on other 
     94platforms or architectures. 
     95 
     96=head1 LICENSE 
     97 
     98License is granted to use and distribute this module under the same 
     99terms as Perl itself. 
    15100 
    16101=cut