… | |
… | |
104 | sub inet_aton { |
104 | sub inet_aton { |
105 | my ($name, $cb) = @_; |
105 | my ($name, $cb) = @_; |
106 | |
106 | |
107 | if (&dotted_quad) { |
107 | if (&dotted_quad) { |
108 | $cb->(Socket::inet_aton $name); |
108 | $cb->(Socket::inet_aton $name); |
|
|
109 | } elsif ($name eq "localhost") { # rfc2606 et al. |
|
|
110 | $cb->(v127.0.0.1); |
109 | } elsif (&has_ev_adns) { |
111 | } elsif (&has_ev_adns) { |
110 | EV::ADNS::submit ($name, &EV::ADNS::r_addr, 0, sub { |
112 | EV::ADNS::submit ($name, &EV::ADNS::r_addr, 0, sub { |
111 | my (undef, undef, @a) = @_; |
113 | my (undef, undef, @a) = @_; |
112 | $cb->(@a ? Socket::inet_aton $a[0] : undef); |
114 | $cb->(@a ? Socket::inet_aton $a[0] : undef); |
113 | }); |
115 | }); |
114 | } else { |
116 | } else { |
115 | _do_asy $cb, sub { Socket::inet_aton $_[0] }, @_; |
117 | _do_asy $cb, sub { Socket::inet_aton $_[0] }, @_; |
|
|
118 | } |
|
|
119 | } |
|
|
120 | |
|
|
121 | =item AnyEvent::Util::fh_nonblocking $fh, $nonblocking |
|
|
122 | |
|
|
123 | Sets the blocking state of the given filehandle (true == nonblocking, |
|
|
124 | false == blocking). Uses fcntl on anything sensible and ioctl FIONBIO on |
|
|
125 | broken (i.e. windows) platforms. |
|
|
126 | |
|
|
127 | =cut |
|
|
128 | |
|
|
129 | sub fh_nonblocking($$) { |
|
|
130 | my ($fh, $nb) = @_; |
|
|
131 | |
|
|
132 | require Fcntl; |
|
|
133 | |
|
|
134 | if ($^O eq "MSWin32") { |
|
|
135 | $nb = (! ! $nb) + 0; |
|
|
136 | ioctl $fh, 0x8004667e, \$nb; # FIONBIO |
|
|
137 | } else { |
|
|
138 | fcntl $fh, &Fcntl::F_SETFL, $nb ? &Fcntl::O_NONBLOCK : 0; |
116 | } |
139 | } |
117 | } |
140 | } |
118 | |
141 | |
119 | 1; |
142 | 1; |
120 | |
143 | |