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

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.181 by root, Tue Sep 1 10:40:05 2009 UTC vs.
Revision 1.184 by root, Thu Sep 3 13:14:38 2009 UTC

284In some situations you want as low a delay as possible, which can be 284In some situations you want as low a delay as possible, which can be
285accomplishd by setting this option to a true value. 285accomplishd by setting this option to a true value.
286 286
287The default is your opertaing system's default behaviour (most likely 287The default is your opertaing system's default behaviour (most likely
288enabled), this option explicitly enables or disables it, if possible. 288enabled), this option explicitly enables or disables it, if possible.
289
290=item keepalive => <boolean>
291
292Enables (default disable) the SO_KEEPALIVE option on the stream socket:
293normally, TCP connections have no time-out once established, so TCP
294conenctions, once established, can stay alive forever even when the other
295side has long gone. TCP keepalives are a cheap way to take down long-lived
296TCP connections whent he other side becomes unreachable. While the default
297is OS-dependent, TCP keepalives usually kick in after around two hours,
298and, if the other side doesn't reply, take down the TCP connection some 10
299to 15 minutes later.
300
301It is harmless to specify this option for file handles that do not support
302keepalives, and enabling it on connections that are potentially long-lived
303is usually a good idea.
304
305=item oobinline => <boolean>
306
307BSD majorly fucked up the implementation of TCP urgent data. The result
308is that almost no OS implements TCP according to the specs, and every OS
309implements it slightly differently.
310
311If you want to handle TCP urgent data, then setting this flag (the default
312is enabled) gives you the most portable way of getting urgent data, by
313putting it into the stream.
314
315Since BSD emulation of OOB data on top of TCP's urgent data can have
316security implications, AnyEvent::Handle sets this flag automatically
317unless explicitly specified. Note that setting this flag after
318establishing a connection I<may> be a bit too late (data loss could
319already have occured on BSD systems), but at least it will protect you
320from most attacks.
289 321
290=item read_size => <bytes> 322=item read_size => <bytes>
291 323
292The default read block size (the amount of bytes this module will 324The default read block size (the amount of bytes this module will
293try to read during each loop iteration, which affects memory 325try to read during each loop iteration, which affects memory
490 522
491 $self->{_activity} = 523 $self->{_activity} =
492 $self->{_ractivity} = 524 $self->{_ractivity} =
493 $self->{_wactivity} = AE::now; 525 $self->{_wactivity} = AE::now;
494 526
495 $self->timeout (delete $self->{timeout} ) if $self->{timeout}; 527 $self->timeout (delete $self->{timeout} ) if $self->{timeout};
496 $self->rtimeout (delete $self->{rtimeout}) if $self->{rtimeout}; 528 $self->rtimeout (delete $self->{rtimeout} ) if $self->{rtimeout};
497 $self->wtimeout (delete $self->{wtimeout}) if $self->{wtimeout}; 529 $self->wtimeout (delete $self->{wtimeout} ) if $self->{wtimeout};
498 530
499 $self->no_delay (delete $self->{no_delay}) if exists $self->{no_delay}; 531 $self->no_delay (delete $self->{no_delay} ) if exists $self->{no_delay} && $self->{no_delay};
532 $self->keepalive (delete $self->{keepalive}) if exists $self->{keepalive} && $self->{keepalive};
500 533
534 $self->oobinline (exists $self->{oobinline} ? delete $self->{oobinline} : 1);
535
501 $self->starttls (delete $self->{tls}, delete $self->{tls_ctx}) 536 $self->starttls (delete $self->{tls}, delete $self->{tls_ctx})
502 if $self->{tls}; 537 if $self->{tls};
503 538
504 $self->on_drain (delete $self->{on_drain}) if $self->{on_drain}; 539 $self->on_drain (delete $self->{on_drain}) if $self->{on_drain};
505 540
506 $self->start_read 541 $self->start_read
507 if $self->{on_read} || @{ $self->{_queue} }; 542 if $self->{on_read} || @{ $self->{_queue} };
508 543
509 $self->_drain_wbuf; 544 $self->_drain_wbuf;
587sub no_delay { 622sub no_delay {
588 $_[0]{no_delay} = $_[1]; 623 $_[0]{no_delay} = $_[1];
589 624
590 eval { 625 eval {
591 local $SIG{__DIE__}; 626 local $SIG{__DIE__};
592 setsockopt $_[0]{fh}, &Socket::IPPROTO_TCP, &Socket::TCP_NODELAY, int $_[1] 627 setsockopt $_[0]{fh}, Socket::IPPROTO_TCP (), Socket::TCP_NODELAY (), int $_[1]
628 if $_[0]{fh};
629 };
630}
631
632=item $handle->keepalive ($boolean)
633
634Enables or disables the C<keepalive> setting (see constructor argument of
635the same name for details).
636
637=cut
638
639sub keepalive {
640 $_[0]{keepalive} = $_[1];
641
642 eval {
643 local $SIG{__DIE__};
644 setsockopt $_[0]{fh}, Socket::SOL_SOCKET (), Socket::SO_KEEPALIVE (), int $_[1]
645 if $_[0]{fh};
646 };
647}
648
649=item $handle->oobinline ($boolean)
650
651Enables or disables the C<oobinline> setting (see constructor argument of
652the same name for details).
653
654=cut
655
656sub oobinline {
657 $_[0]{oobinline} = $_[1];
658
659 eval {
660 local $SIG{__DIE__};
661 setsockopt $_[0]{fh}, Socket::SOL_SOCKET (), Socket::SO_OOBINLINE (), int $_[1]
662 if $_[0]{fh};
663 };
664}
665
666=item $handle->keepalive ($boolean)
667
668Enables or disables the C<keepalive> setting (see constructor argument of
669the same name for details).
670
671=cut
672
673sub keepalive {
674 $_[0]{keepalive} = $_[1];
675
676 eval {
677 local $SIG{__DIE__};
678 setsockopt $_[0]{fh}, Socket::SOL_SOCKET (), Socket::SO_KEEPALIVE (), int $_[1]
593 if $_[0]{fh}; 679 if $_[0]{fh};
594 }; 680 };
595} 681}
596 682
597=item $handle->on_starttls ($cb) 683=item $handle->on_starttls ($cb)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines