Changeset 100

Show
Ignore:
Timestamp:
08/16/06 15:23:42 (2 years ago)
Author:
msergeant
Message:

Converted comment based docs to POD and fix some of those docs to match reality (msergeant).


Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGES

    r99 r100  
    22   -- Added local_ip_string() and local_addr_string() (msergeant). 
    33   -- Removed bogus 'ticker' code from KQueue event loop (msergeant). 
     4   -- Converted comment based docs to POD and fix some of those docs 
     5      to match reality (msergeant). 
    46 
    571.52: (2006-07-09) 
  • trunk/Socket.pm

    r99 r100  
    7777perlbal, mogilefsd, or ddlockd. 
    7878 
    79 =head1 AUTHORS 
    80  
    81 Brad Fitzpatrick <brad@danga.com> - author 
    82  
    83 Michael Granger <ged@danga.com> - docs, testing 
    84  
    85 Mark Smith <junior@danga.com> - contributor, heavy user, testing 
    86  
    87 Matt Sergeant <matt@sergeant.org> - kqueue support 
    88  
    89 =head1 BUGS 
    90  
    91 Not documented enough. 
    92  
    93 tcp_cork only works on Linux for now.  No BSD push/nopush support. 
    94  
    95 =head1 LICENSE 
    96  
    97 License is granted to use and distribute this module under the same 
    98 terms as Perl itself. 
     79=head1 API 
     80 
     81Note where "C<CLASS>" is used below, normally you would call these methods as: 
     82 
     83  Danga::Socket->method(...); 
     84 
     85However using a subclass works too. 
     86 
     87The CLASS methods are all methods for the event loop part of Danga::Socket, 
     88whereas the object methods are all used on your subclasses. 
    9989 
    10090=cut 
     
    177167##################################################################### 
    178168 
    179 # (CLASS) method: reset all state 
     169=head2 C<< CLASS->Reset() >> 
     170 
     171Reset all state 
     172 
     173=cut 
    180174sub Reset { 
    181175    %DescriptorMap = (); 
     
    192186} 
    193187 
    194 ### (CLASS) METHOD: HaveEpoll() 
    195 ### Returns a true value if this class will use IO::Epoll for async IO. 
     188=head2 C<< CLASS->HaveEpoll() >> 
     189 
     190Returns a true value if this class will use IO::Epoll for async IO. 
     191 
     192=cut 
    196193sub HaveEpoll { 
    197194    _InitPoller(); 
     
    199196} 
    200197 
    201 ### (CLASS) METHOD: WatchedSockets() 
    202 ### Returns the number of file descriptors which are registered with the global 
    203 ### poll object. 
     198=head2 C<< CLASS->WatchedSockets() >> 
     199 
     200Returns the number of file descriptors which are registered with the global 
     201poll object. 
     202 
     203=cut 
    204204sub WatchedSockets { 
    205205    return scalar keys %DescriptorMap; 
     
    207207*watched_sockets = *WatchedSockets; 
    208208 
    209 ### (CLASS) METHOD: EnableProfiling() 
    210 ### Turns profiling on, clearing current profiling data. 
     209=head2 C<< CLASS->EnableProfiling() >> 
     210 
     211Turns profiling on, clearing current profiling data. 
     212 
     213=cut 
    211214sub EnableProfiling { 
    212215    if ($opt_bsd_resource) { 
     
    218221} 
    219222 
    220 ### (CLASS) METHOD: DisableProfiling() 
    221 ### Turns off profiling, but retains data up to this point 
     223=head2 C<< CLASS->DisableProfiling() >> 
     224 
     225Turns off profiling, but retains data up to this point 
     226 
     227=cut 
    222228sub DisableProfiling { 
    223229    $DoProfile = 0; 
    224230} 
    225231 
    226 ### (CLASS) METHOD: ProfilingData() 
    227 ### Returns reference to a hash of data in format above (see %Profiling) 
     232=head2 C<< CLASS->ProfilingData() >> 
     233 
     234Returns reference to a hash of data in format: 
     235 
     236  ITEM => [ utime, stime, #calls ] 
     237 
     238=cut 
    228239sub ProfilingData { 
    229240    return \%Profiling; 
    230241} 
    231242 
    232 ### (CLASS) METHOD: ToClose() 
    233 ### Return the list of sockets that are awaiting close() at the end of the 
    234 ### current event loop. 
     243=head2 C<< CLASS->ToClose() >> 
     244 
     245Return the list of sockets that are awaiting close() at the end of the 
     246current event loop. 
     247 
     248=cut 
    235249sub ToClose { return @ToClose; } 
    236250 
    237 ### (CLASS) METHOD: OtherFds( [%fdmap] ) 
    238 ### Get/set the hash of file descriptors that need processing in parallel with 
    239 ### the registered Danga::Socket objects. 
     251=head2 C<< CLASS->OtherFds( [%fdmap] ) >> 
     252 
     253Get/set the hash of file descriptors that need processing in parallel with 
     254the registered Danga::Socket objects. 
     255 
     256=cut 
    240257sub OtherFds { 
    241258    my $class = shift; 
     
    244261} 
    245262 
    246 ### (CLASS) METHOD: AddOtherFds( [%fdmap] ) 
    247 ### Add fds to the OtherFds hash for processing. 
     263=head2 C<< CLASS->AddOtherFds( [%fdmap] ) >> 
     264 
     265Add fds to the OtherFds hash for processing. 
     266 
     267=cut 
    248268sub AddOtherFds { 
    249269    my $class = shift; 
     
    252272} 
    253273 
    254 ### (CLASS) METHOD: SetLoopTimeout( $timeout ) 
    255 ### Set the loop timeout for the event loop to some value in milliseconds. 
     274=head2 C<< CLASS->SetLoopTimeout( $timeout ) >> 
     275 
     276Set the loop timeout for the event loop to some value in milliseconds. 
     277 
     278A timeout of 0 (zero) means poll forever. A timeout of -1 means poll and return 
     279immediately. 
     280 
     281=cut 
    256282sub SetLoopTimeout { 
    257283    return $LoopTimeout = $_[1] + 0; 
    258284} 
    259285 
    260 ### (CLASS) METHOD: DebugMsg( $format, @args ) 
    261 ### Print the debugging message specified by the C<sprintf>-style I<format> and 
    262 ### I<args> 
     286=head2 C<< CLASS->DebugMsg( $format, @args ) >> 
     287 
     288Print the debugging message specified by the C<sprintf>-style I<format> and 
     289I<args> 
     290 
     291=cut 
    263292sub DebugMsg { 
    264293    my ( $class, $fmt, @args ) = @_; 
     
    267296} 
    268297 
    269 ### (CLASS) METHOD: AddTimer( $seconds, $coderef ) 
    270 ### Add a timer to occur $seconds from now. $seconds may be fractional. Don't 
    271 ### expect this to be accurate though. 
     298=head2 C<< CLASS->AddTimer( $seconds, $coderef ) >> 
     299 
     300Add a timer to occur $seconds from now. $seconds may be fractional, but timers 
     301are not guaranteed to fire at the exact time you ask for. 
     302 
     303Returns a timer object which you can call C<< $timer->cancel >> on if you need to. 
     304 
     305=cut 
    272306sub AddTimer { 
    273307    my $class = shift; 
     
    297331} 
    298332 
    299  
    300 ### (CLASS) METHOD: DescriptorMap() 
    301 ### Get the hash of Danga::Socket objects keyed by the file descriptor they are 
    302 ### wrapping. 
     333=head2 C<< CLASS->DescriptorMap() >> 
     334 
     335Get the hash of Danga::Socket objects keyed by the file descriptor (fileno) they 
     336are wrapping. 
     337 
     338Returns a hash in list context or a hashref in scalar context. 
     339 
     340=cut 
    303341sub DescriptorMap { 
    304342    return wantarray ? %DescriptorMap : \%DescriptorMap; 
     
    333371} 
    334372 
    335 ### FUNCTION: EventLoop() 
    336 ### Start processing IO events. 
     373=head2 C<< CLASS->EventLoop() >> 
     374 
     375Start processing IO events. In most daemon programs this never exits. See 
     376C<PostLoopCallback> below for how to exit the loop. 
     377 
     378=cut 
    337379sub EventLoop { 
    338380    my $class = shift; 
     
    599641} 
    600642 
    601 ### CLASS METHOD: SetPostLoopCallback 
    602 ### Sets post loop callback function.  Pass a subref and it will be 
    603 ### called every time the event loop finishes.  Return 1 from the sub 
    604 ### to make the loop continue, else it will exit.  The function will 
    605 ### be passed two parameters: \%DescriptorMap, \%OtherFds. 
     643=head2 C<< CLASS->SetPostLoopCallback( CODEREF ) >> 
     644 
     645Sets post loop callback function.  Pass a subref and it will be 
     646called every time the event loop finishes. 
     647 
     648Return 1 (or any true value) from the sub to make the loop continue, 0 or false 
     649and it will exit. 
     650 
     651The callback function will be passed two parameters: \%DescriptorMap, \%OtherFds. 
     652 
     653=cut 
    606654sub SetPostLoopCallback { 
    607655    my ($class, $ref) = @_; 
     
    682730##################################################################### 
    683731 
    684 ### METHOD: new( $socket ) 
    685 ### Create a new Danga::Socket object for the given I<socket> which will react 
    686 ### to events on it during the C<wait_loop>. 
     732=head2 OBJECT METHODS 
     733 
     734=head2 C<< CLASS->new( $socket ) >> 
     735 
     736Create a new Danga::Socket subclass object for the given I<socket> which will 
     737react to events on it during the C<EventLoop>. 
     738 
     739This is normally (always?) called from your subclass via: 
     740 
     741  $class->SUPER::new($socket); 
     742 
     743=cut 
    687744sub new { 
    688745    my Danga::Socket $self = shift; 
     
    733790##################################################################### 
    734791 
    735 ### METHOD: tcp_cork( $boolean ) 
    736 ### Turn TCP_CORK on or off depending on the value of I<boolean>. 
     792=head2 C<< $obj->tcp_cork( $boolean ) >> 
     793 
     794Turn TCP_CORK on or off depending on the value of I<boolean>. 
     795 
     796=cut 
    737797sub tcp_cork { 
    738798    my Danga::Socket $self = $_[0]; 
     
    770830} 
    771831 
    772 ### METHOD: steal_socket 
    773 ### Basically returns our socket and makes it so that we don't try to close it, 
    774 ### but we do remove it from epoll handlers.  THIS CLOSES $self.  It is the same 
    775 ### thing as calling close, except it gives you the socket to use. 
     832=head2 C<< $obj->steal_socket() >> 
     833 
     834Basically returns our socket and makes it so that we don't try to close it, 
     835but we do remove it from epoll handlers.  THIS CLOSES $self.  It is the same 
     836thing as calling close, except it gives you the socket to use. 
     837 
     838=cut 
    776839sub steal_socket { 
    777840    my Danga::Socket $self = $_[0]; 
     
    787850} 
    788851 
    789 ### METHOD: close( [$reason] ) 
    790 ### Close the socket. The I<reason> argument will be used in debugging messages. 
     852=head2 C<< $obj->close( [$reason] ) >> 
     853 
     854Close the socket. The I<reason> argument will be used in debugging messages. 
     855 
     856=cut 
    791857sub close { 
    792858    my Danga::Socket $self = $_[0]; 
     
    857923} 
    858924 
    859 ### METHOD: sock() 
    860 ### Returns the underlying IO::Handle for the object. 
     925=head2 C<< $obj->sock() >> 
     926 
     927Returns the underlying IO::Handle for the object. 
     928 
     929=cut 
    861930sub sock { 
    862931    my Danga::Socket $self = shift; 
     
    864933} 
    865934 
     935=head2 C<< $obj->set_writer_func( CODEREF ) >> 
     936 
     937Sets a function to use instead of C<syswrite()> when writing data to the socket. 
     938 
     939=cut 
    866940sub set_writer_func { 
    867941   my Danga::Socket $self = shift; 
     
    871945} 
    872946 
    873 ### METHOD: write( $data ) 
    874 ### Write the specified data to the underlying handle.  I<data> may be scalar, 
    875 ### scalar ref, code ref (to run when there), or undef just to kick-start. 
    876 ### Returns 1 if writes all went through, or 0 if there are writes in queue. If 
    877 ### it returns 1, caller should stop waiting for 'writable' events) 
     947=head2 C<< $obj->write( $data ) >> 
     948 
     949Write the specified data to the underlying handle.  I<data> may be scalar, 
     950scalar ref, code ref (to run when there), or undef just to kick-start. 
     951Returns 1 if writes all went through, or 0 if there are writes in queue. If 
     952it returns 1, caller should stop waiting for 'writable' events) 
     953 
     954=cut 
    878955sub write { 
    879956    my Danga::Socket $self; 
     
    10001077} 
    10011078 
    1002 ### METHOD: push_back_read( $buf ) 
    1003 ### Push back I<buf> (a scalar or scalarref) into the read stream 
     1079=head2 C<< $obj->push_back_read( $buf ) >> 
     1080 
     1081Push back I<buf> (a scalar or scalarref) into the read stream. Useful if you read 
     1082more than you need to and want to return this data on the next "read". 
     1083 
     1084=cut 
    10041085sub push_back_read { 
    10051086    my Danga::Socket $self = shift; 
     
    10091090} 
    10101091 
    1011 ### METHOD: read( $bytecount ) 
    1012 ### Read at most I<bytecount> bytes from the underlying handle; returns scalar 
    1013 ### ref on read, or undef on connection closed. 
     1092=head2 C<< $obj->read( $bytecount ) >> 
     1093 
     1094Read at most I<bytecount> bytes from the underlying handle; returns scalar 
     1095ref on read, or undef on connection closed. 
     1096 
     1097=cut 
    10141098sub read { 
    10151099    my Danga::Socket $self = shift; 
     
    10501134} 
    10511135 
    1052  
    1053 ### (VIRTUAL) METHOD: event_read() 
    1054 ### Readable event handler. Concrete deriviatives of Danga::Socket should 
    1055 ### provide an implementation of this. The default implementation will die if 
    1056 ### called. 
     1136=head2 (VIRTUAL) C<< $obj->event_read() >> 
     1137 
     1138Readable event handler. Concrete deriviatives of Danga::Socket should 
     1139provide an implementation of this. The default implementation will die if 
     1140called. 
     1141 
     1142=cut 
    10571143sub event_read  { die "Base class event_read called for $_[0]\n"; } 
    10581144 
    1059  
    1060 ### (VIRTUAL) METHOD: event_err() 
    1061 ### Error event handler. Concrete deriviatives of Danga::Socket should 
    1062 ### provide an implementation of this. The default implementation will die if 
    1063 ### called. 
     1145=head2 (VIRTUAL) C<< $obj->event_err() >> 
     1146 
     1147Error event handler. Concrete deriviatives of Danga::Socket should 
     1148provide an implementation of this. The default implementation will die if 
     1149called. 
     1150 
     1151=cut 
    10641152sub event_err   { die "Base class event_err called for $_[0]\n"; } 
    10651153 
    1066  
    1067 ### (VIRTUAL) METHOD: event_hup() 
    1068 ### 'Hangup' event handler. Concrete deriviatives of Danga::Socket should 
    1069 ### provide an implementation of this. The default implementation will die if 
    1070 ### called. 
     1154=head2 (VIRTUAL) C<< $obj->event_hup() >> 
     1155 
     1156'Hangup' event handler. Concrete deriviatives of Danga::Socket should 
     1157provide an implementation of this. The default implementation will die if 
     1158called. 
     1159 
     1160=cut 
    10711161sub event_hup   { die "Base class event_hup called for $_[0]\n"; } 
    10721162 
    1073  
    1074 ### METHOD: event_write() 
    1075 ### Writable event handler. Concrete deriviatives of Danga::Socket may wish to 
    1076 ### provide an implementation of this. The default implementation calls 
    1077 ### C<write()> with an C<undef>. 
     1163=head2 C<< $obj->event_write() >> 
     1164 
     1165Writable event handler. Concrete deriviatives of Danga::Socket may wish to 
     1166provide an implementation of this. The default implementation calls 
     1167C<write()> with an C<undef>. 
     1168 
     1169=cut 
    10781170sub event_write { 
    10791171    my $self = shift; 
     
    10811173} 
    10821174 
    1083  
    1084 ### METHOD: watch_read( $boolean ) 
    1085 ### Turn 'readable' event notification on or off. 
     1175=head2 C<< $obj->watch_read( $boolean ) >> 
     1176 
     1177Turn 'readable' event notification on or off. 
     1178 
     1179=cut 
    10861180sub watch_read { 
    10871181    my Danga::Socket $self = shift; 
     
    11091203} 
    11101204 
    1111 ### METHOD: watch_write( $boolean ) 
    1112 ### Turn 'writable' event notification on or off. 
     1205=head2 C<< $obj->watch_write( $boolean ) >> 
     1206 
     1207Turn 'writable' event notification on or off. 
     1208 
     1209=cut 
    11131210sub watch_write { 
    11141211    my Danga::Socket $self = shift; 
     
    11361233} 
    11371234 
    1138 # METHOD: dump_error( $message ) 
    1139 # Prints to STDERR a backtrace with information about this socket and what lead 
    1140 # up to the dump_error call. 
     1235=head2 C<< $obj->dump_error( $message ) >> 
     1236 
     1237Prints to STDERR a backtrace with information about this socket and what lead 
     1238up to the dump_error call. 
     1239 
     1240=cut 
    11411241sub dump_error { 
    11421242    my $i = 0; 
     
    11511251} 
    11521252 
    1153  
    1154 ### METHOD: debugmsg( $format, @args ) 
    1155 ### Print the debugging message specified by the C<sprintf>-style I<format> and 
    1156 ### I<args> if the object's C<debug_level> is greater than or equal to the given 
    1157 ### I<level>. 
     1253=head2 C<< $obj->debugmsg( $format, @args ) >> 
     1254 
     1255Print the debugging message specified by the C<sprintf>-style I<format> and 
     1256I<args>. 
     1257 
     1258=cut 
    11581259sub debugmsg { 
    11591260    my ( $self, $fmt, @args ) = @_; 
     
    11651266 
    11661267 
    1167 ### METHOD: peer_ip_string() 
    1168 ### Returns the string describing the peer's IP 
     1268=head2 C<< $obj->peer_ip_string() >> 
     1269 
     1270Returns the string describing the peer's IP 
     1271 
     1272=cut 
    11691273sub peer_ip_string { 
    11701274    my Danga::Socket $self = shift; 
     
    11891293} 
    11901294 
    1191 ### METHOD: peer_addr_string() 
    1192 ### Returns the string describing the peer for the socket which underlies this 
    1193 ### object in form "ip:port" 
     1295=head2 C<< $obj->peer_addr_string() >> 
     1296 
     1297Returns the string describing the peer for the socket which underlies this 
     1298object in form "ip:port" 
     1299 
     1300=cut 
    11941301sub peer_addr_string { 
    11951302    my Danga::Socket $self = shift; 
     
    11981305} 
    11991306 
    1200 ### METHOD: local_ip_string() 
    1201 ### Returns the string describing the local IP 
     1307=head2 C<< $obj->local_ip_string() >> 
     1308 
     1309Returns the string describing the local IP 
     1310 
     1311=cut 
    12021312sub local_ip_string { 
    12031313    my Danga::Socket $self = shift; 
     
    12141324} 
    12151325 
    1216 ### METHOD: local_addr_string() 
    1217 ### Returns the string describing the local end of the socket which underlies this 
    1218 ### object in form "ip:port" 
     1326=head2 C<< $obj->local_addr_string() >> 
     1327 
     1328Returns the string describing the local end of the socket which underlies this 
     1329object in form "ip:port" 
     1330 
     1331=cut 
    12191332sub local_addr_string { 
    12201333    my Danga::Socket $self = shift; 
     
    12241337 
    12251338 
    1226 ### METHOD: as_string() 
    1227 ### Returns a string describing this socket. 
     1339=head2 C<< $obj->as_string() >> 
     1340 
     1341Returns a string describing this socket. 
     1342 
     1343=cut 
    12281344sub as_string { 
    12291345    my Danga::Socket $self = shift; 
     
    12511367} 
    12521368 
     1369=head1 AUTHORS 
     1370 
     1371Brad Fitzpatrick <brad@danga.com> - author 
     1372 
     1373Michael Granger <ged@danga.com> - docs, testing 
     1374 
     1375Mark Smith <junior@danga.com> - contributor, heavy user, testing 
     1376 
     1377Matt Sergeant <matt@sergeant.org> - kqueue support, docs, timers, other bits 
     1378 
     1379=head1 BUGS 
     1380 
     1381Not documented enough (but isn't that true of every project?). 
     1382 
     1383tcp_cork only works on Linux for now.  No BSD push/nopush support. 
     1384 
     1385=head1 LICENSE 
     1386 
     1387License is granted to use and distribute this module under the same 
     1388terms as Perl itself. 
     1389 
     1390=cut 
     1391 
    125313921; 
    12541393