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

Comparing AnyEvent/lib/AnyEvent/Socket.pm (file contents):
Revision 1.127 by root, Mon Oct 11 04:17:55 2010 UTC vs.
Revision 1.130 by root, Fri Jan 14 17:43:11 2011 UTC

775In either case, it will create a list of target hosts (e.g. for multihomed 775In either case, it will create a list of target hosts (e.g. for multihomed
776hosts or hosts with both IPv4 and IPv6 addresses) and try to connect to 776hosts or hosts with both IPv4 and IPv6 addresses) and try to connect to
777each in turn. 777each in turn.
778 778
779After the connection is established, then the C<$connect_cb> will be 779After the connection is established, then the C<$connect_cb> will be
780invoked with the socket file handle (in non-blocking mode) as first and 780invoked with the socket file handle (in non-blocking mode) as first, and
781the peer host (as a textual IP address) and peer port as second and third 781the peer host (as a textual IP address) and peer port as second and third
782arguments, respectively. The fourth argument is a code reference that you 782arguments, respectively. The fourth argument is a code reference that you
783can call if, for some reason, you don't like this connection, which will 783can call if, for some reason, you don't like this connection, which will
784cause C<tcp_connect> to try the next one (or call your callback without 784cause C<tcp_connect> to try the next one (or call your callback without
785any arguments if there are no more connections). In most cases, you can 785any 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
999the socket before it tries to bind to it. See SECURITY CONSIDERATIONS, 999the socket before it tries to bind to it. See SECURITY CONSIDERATIONS,
1000below. 1000below.
1001 1001
1002For each new connection that could be C<accept>ed, call the C<< 1002For 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
1004mode) as first and the peer host and port as second and third arguments 1004mode) 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
1007Croaks on any errors it can detect before the listen. 1007Croaks on any errors it can detect before the listen.
1008 1008
1009If called in non-void context, then this function returns a guard object 1009If called in non-void context, then this function returns a guard object
1010whose lifetime it tied to the TCP server: If the object gets destroyed, 1010whose lifetime it tied to the TCP server: If the object gets destroyed,
1011the server will be stopped (but existing accepted connections will 1011the server will be stopped (but existing accepted connections will
1012continue). 1012not be affected).
1013 1013
1014If you need more control over the listening socket, you can provide a 1014If you need more control over the listening socket, you can provide a
1015C<< $prepare_cb->($fh, $host, $port) >>, which is called just before the 1015C<< $prepare_cb->($fh, $host, $port) >>, which is called just before the
1016C<listen ()> call, with the listen file handle as first argument, and IP 1016C<listen ()> call, with the listen file handle as first argument, and IP
1017address and port number of the local socket endpoint as second and third 1017address and port number of the local socket endpoint as second and third

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines