… | |
… | |
775 | In either case, it will create a list of target hosts (e.g. for multihomed |
775 | In either case, it will create a list of target hosts (e.g. for multihomed |
776 | hosts or hosts with both IPv4 and IPv6 addresses) and try to connect to |
776 | hosts or hosts with both IPv4 and IPv6 addresses) and try to connect to |
777 | each in turn. |
777 | each in turn. |
778 | |
778 | |
779 | After the connection is established, then the C<$connect_cb> will be |
779 | After the connection is established, then the C<$connect_cb> will be |
780 | invoked with the socket file handle (in non-blocking mode) as first and |
780 | invoked with the socket file handle (in non-blocking mode) as first, and |
781 | the peer host (as a textual IP address) and peer port as second and third |
781 | the peer host (as a textual IP address) and peer port as second and third |
782 | arguments, respectively. The fourth argument is a code reference that you |
782 | arguments, respectively. The fourth argument is a code reference that you |
783 | can call if, for some reason, you don't like this connection, which will |
783 | can call if, for some reason, you don't like this connection, which will |
784 | cause C<tcp_connect> to try the next one (or call your callback without |
784 | cause C<tcp_connect> to try the next one (or call your callback without |
785 | any arguments if there are no more connections). In most cases, you can |
785 | any arguments if there are no more connections). In most cases, you can |
… | |
… | |
949 | sysread $state{fh}, my $buf, 1; |
949 | sysread $state{fh}, my $buf, 1; |
950 | |
950 | |
951 | # cygwin 1.5 continously reports "ready' but never delivers |
951 | # cygwin 1.5 continously reports "ready' but never delivers |
952 | # an error with getpeername or sysread. |
952 | # an error with getpeername or sysread. |
953 | # cygwin 1.7 only reports readyness *once*, but is otherwise |
953 | # cygwin 1.7 only reports readyness *once*, but is otherwise |
954 | # the same, which is atcually more broken. |
954 | # the same, which is actually more broken. |
955 | # Work around both by using unportable SO_ERROR for cygwin. |
955 | # Work around both by using unportable SO_ERROR for cygwin. |
956 | $! = (unpack "l", getsockopt $state{fh}, Socket::SOL_SOCKET(), Socket::SO_ERROR()) || Errno::EAGAIN |
956 | $! = (unpack "l", getsockopt $state{fh}, Socket::SOL_SOCKET(), Socket::SO_ERROR()) || Errno::EAGAIN |
957 | if AnyEvent::CYGWIN && $! == Errno::EAGAIN; |
957 | if AnyEvent::CYGWIN && $! == Errno::EAGAIN; |
958 | } |
958 | } |
959 | |
959 | |
… | |
… | |
999 | the socket before it tries to bind to it. See SECURITY CONSIDERATIONS, |
999 | the socket before it tries to bind to it. See SECURITY CONSIDERATIONS, |
1000 | below. |
1000 | below. |
1001 | |
1001 | |
1002 | For each new connection that could be C<accept>ed, call the C<< |
1002 | For each new connection that could be C<accept>ed, call the C<< |
1003 | $accept_cb->($fh, $host, $port) >> with the file handle (in non-blocking |
1003 | $accept_cb->($fh, $host, $port) >> with the file handle (in non-blocking |
1004 | mode) as first and the peer host and port as second and third arguments |
1004 | mode) as first, and the peer host and port as second and third arguments |
1005 | (see C<tcp_connect> for details). |
1005 | (see C<tcp_connect> for details). |
1006 | |
1006 | |
1007 | Croaks on any errors it can detect before the listen. |
1007 | Croaks on any errors it can detect before the listen. |
1008 | |
1008 | |
1009 | If called in non-void context, then this function returns a guard object |
1009 | If called in non-void context, then this function returns a guard object |
1010 | whose lifetime it tied to the TCP server: If the object gets destroyed, |
1010 | whose lifetime it tied to the TCP server: If the object gets destroyed, |
1011 | the server will be stopped (but existing accepted connections will |
1011 | the server will be stopped (but existing accepted connections will |
1012 | continue). |
1012 | not be affected). |
1013 | |
1013 | |
1014 | If you need more control over the listening socket, you can provide a |
1014 | If you need more control over the listening socket, you can provide a |
1015 | C<< $prepare_cb->($fh, $host, $port) >>, which is called just before the |
1015 | C<< $prepare_cb->($fh, $host, $port) >>, which is called just before the |
1016 | C<listen ()> call, with the listen file handle as first argument, and IP |
1016 | C<listen ()> call, with the listen file handle as first argument, and IP |
1017 | address and port number of the local socket endpoint as second and third |
1017 | address and port number of the local socket endpoint as second and third |