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.102 by root, Thu Jul 30 16:39:19 2009 UTC vs.
Revision 1.106 by root, Wed Aug 5 20:50:27 2009 UTC

45 45
46use base 'Exporter'; 46use base 'Exporter';
47 47
48our @EXPORT = qw( 48our @EXPORT = qw(
49 getprotobyname 49 getprotobyname
50 parse_hostport 50 parse_hostport format_hostport
51 parse_ipv4 parse_ipv6 51 parse_ipv4 parse_ipv6
52 parse_ip parse_address 52 parse_ip parse_address
53 format_ipv4 format_ipv6 53 format_ipv4 format_ipv6
54 format_ip format_address 54 format_ip format_address
55 address_family 55 address_family
56 inet_aton 56 inet_aton
57 tcp_server 57 tcp_server
58 tcp_connect 58 tcp_connect
59); 59);
60 60
61our $VERSION = 4.881; 61our $VERSION = 4.901;
62 62
63=item $ipn = parse_ipv4 $dotted_quad 63=item $ipn = parse_ipv4 $dotted_quad
64 64
65Tries to parse the given dotted quad IPv4 address and return it in 65Tries to parse the given dotted quad IPv4 address and return it in
66octet form (or undef when it isn't in a parsable format). Supports all 66octet form (or undef when it isn't in a parsable format). Supports all
278 278
279 # hostnames must not contain :'s 279 # hostnames must not contain :'s
280 return if $host =~ /:/ && !parse_ipv6 $host; 280 return if $host =~ /:/ && !parse_ipv6 $host;
281 281
282 ($host, $port) 282 ($host, $port)
283}
284
285=item $string = format_hostport $host, $port
286
287Takes a host (in textual form) and a port and formats in unambigiously in
288a way that C<parse_hostport> can parse it again. C<$port> can be C<undef>.
289
290=cut
291
292sub format_hostport($;$) {
293 my ($host, $port) = @_;
294
295 $port = ":$port" if length $port;
296 $host = "[$host]" if $host =~ /:/;
297
298 "$host$port"
283} 299}
284 300
285=item $sa_family = address_family $ipn 301=item $sa_family = address_family $ipn
286 302
287Returns the address family/protocol-family (AF_xxx/PF_xxx, in one value :) 303Returns the address family/protocol-family (AF_xxx/PF_xxx, in one value :)
811 $! = Errno::ETIMEDOUT; 827 $! = Errno::ETIMEDOUT;
812 $state{next}(); 828 $state{next}();
813 }) if $timeout; 829 }) if $timeout;
814 830
815 # called when the connect was successful, which, 831 # called when the connect was successful, which,
816 # in theory, could be the case immediately (but never is in practise) 832 # in theory, could be the case immediately
833 # (but only happens in special cases)
817 $state{connected} = sub { 834 $state{connected} = sub {
818 # we are connected, or maybe there was an error 835 # we are connected, or maybe there was an error
819 if (my $sin = getpeername $state{fh}) { 836 if (my $sin = getpeername $state{fh}) {
820 my ($port, $host) = unpack_sockaddr $sin; 837 my ($port, $host) = unpack_sockaddr $sin;
821 838

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines