… | |
… | |
284 | In some situations you want as low a delay as possible, which can be |
284 | In some situations you want as low a delay as possible, which can be |
285 | accomplishd by setting this option to a true value. |
285 | accomplishd by setting this option to a true value. |
286 | |
286 | |
287 | The default is your opertaing system's default behaviour (most likely |
287 | The default is your opertaing system's default behaviour (most likely |
288 | enabled), this option explicitly enables or disables it, if possible. |
288 | enabled), this option explicitly enables or disables it, if possible. |
|
|
289 | |
|
|
290 | =item keepalive => <boolean> |
|
|
291 | |
|
|
292 | Enables (default disable) the SO_KEEPALIVE option on the stream socket: |
|
|
293 | normally, TCP connections have no time-out once established, so TCP |
|
|
294 | conenctions, once established, can stay alive forever even when the other |
|
|
295 | side has long gone. TCP keepalives are a cheap way to take down long-lived |
|
|
296 | TCP connections whent he other side becomes unreachable. While the default |
|
|
297 | is OS-dependent, TCP keepalives usually kick in after around two hours, |
|
|
298 | and, if the other side doesn't reply, take down the TCP connection some 10 |
|
|
299 | to 15 minutes later. |
|
|
300 | |
|
|
301 | It is harmless to specify this option for file handles that do not support |
|
|
302 | keepalives, and enabling it on connections that are potentially long-lived |
|
|
303 | is usually a good idea. |
|
|
304 | |
|
|
305 | =item oobinline => <boolean> |
|
|
306 | |
|
|
307 | BSD majorly fucked up the implementation of TCP urgent data. The result |
|
|
308 | is that almost no OS implements TCP according to the specs, and every OS |
|
|
309 | implements it slightly differently. |
|
|
310 | |
|
|
311 | If you want to handle TCP urgent data, then setting this flag (the default |
|
|
312 | is enabled) gives you the most portable way of getting urgent data, by |
|
|
313 | putting it into the stream. |
|
|
314 | |
|
|
315 | Since BSD emulation of OOB data on top of TCP's urgent data can have |
|
|
316 | security implications, AnyEvent::Handle sets this flag automatically |
|
|
317 | unless explicitly specified. Note that setting this flag after |
|
|
318 | establishing a connection I<may> be a bit too late (data loss could |
|
|
319 | already have occured on BSD systems), but at least it will protect you |
|
|
320 | from most attacks. |
289 | |
321 | |
290 | =item read_size => <bytes> |
322 | =item read_size => <bytes> |
291 | |
323 | |
292 | The default read block size (the amount of bytes this module will |
324 | The default read block size (the amount of bytes this module will |
293 | try to read during each loop iteration, which affects memory |
325 | try 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; |
… | |
… | |
587 | sub no_delay { |
622 | sub 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 | |
|
|
634 | Enables or disables the C<keepalive> setting (see constructor argument of |
|
|
635 | the same name for details). |
|
|
636 | |
|
|
637 | =cut |
|
|
638 | |
|
|
639 | sub 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 | |
|
|
651 | Enables or disables the C<oobinline> setting (see constructor argument of |
|
|
652 | the same name for details). |
|
|
653 | |
|
|
654 | =cut |
|
|
655 | |
|
|
656 | sub 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 | |
|
|
668 | Enables or disables the C<keepalive> setting (see constructor argument of |
|
|
669 | the same name for details). |
|
|
670 | |
|
|
671 | =cut |
|
|
672 | |
|
|
673 | sub 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) |