| File | /usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm |
| Statements Executed | 539 |
| Statement Execution Time | 179ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 8 | 1 | 2 | 174ms | 174ms | LWP::Protocol::http::SocketMethods::CORE:sselect (opcode) |
| 1 | 1 | 1 | 1.96ms | 2.08ms | LWP::Protocol::http::BEGIN@216 |
| 3 | 1 | 1 | 1.09ms | 345ms | LWP::Protocol::http::request |
| 8 | 2 | 1 | 215µs | 174ms | LWP::Protocol::http::SocketMethods::can_read |
| 7 | 2 | 1 | 141µs | 174ms | LWP::Protocol::http::SocketMethods::sysread |
| 3 | 1 | 1 | 136µs | 125ms | LWP::Protocol::http::_new_socket |
| 7 | 1 | 2 | 90µs | 90µs | LWP::Protocol::http::SocketMethods::CORE:sysread (opcode) |
| 7 | 2 | 1 | 82µs | 728µs | LWP::Protocol::http::__ANON__[:394] |
| 3 | 1 | 1 | 80µs | 586µs | LWP::Protocol::http::_get_sock_info |
| 9 | 1 | 1 | 77µs | 82µs | LWP::Protocol::http::__ANON__[:167] |
| 3 | 1 | 1 | 50µs | 192µs | LWP::Protocol::http::_fixup_header |
| 15 | 5 | 2 | 30µs | 30µs | LWP::Protocol::http::CORE:match (opcode) |
| 3 | 1 | 2 | 27µs | 27µs | LWP::Protocol::http::CORE:sselect (opcode) |
| 1 | 1 | 1 | 22µs | 26µs | LWP::Protocol::http::BEGIN@3 |
| 5 | 2 | 1 | 15µs | 15µs | LWP::Protocol::http::socket_type |
| 3 | 1 | 1 | 14µs | 14µs | LWP::Protocol::http::SocketMethods::increment_response_count |
| 1 | 1 | 1 | 12µs | 45µs | LWP::Protocol::http::Socket::BEGIN@472 |
| 1 | 1 | 1 | 11µs | 61µs | LWP::Protocol::http::BEGIN@9 |
| 21 | 3 | 2 | 9µs | 9µs | LWP::Protocol::http::CORE:subst (opcode) |
| 2 | 1 | 1 | 8µs | 8µs | LWP::Protocol::http::socket_class |
| 3 | 1 | 1 | 5µs | 5µs | LWP::Protocol::http::_check_sock |
| 2 | 1 | 1 | 4µs | 4µs | LWP::Protocol::http::_extra_sock_opts |
| 0 | 0 | 0 | 0s | 0s | LWP::Protocol::http::SocketMethods::ping |
| 0 | 0 | 0 | 0s | 0s | LWP::Protocol::http::hlist_remove |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package LWP::Protocol::http; | ||||
| 2 | |||||
| 3 | 3 | 73µs | 2 | 31µs | # spent 26µs (22+5) within LWP::Protocol::http::BEGIN@3 which was called
# once (22µs+5µs) by LWP::Protocol::implementor at line 3 # spent 26µs making 1 call to LWP::Protocol::http::BEGIN@3
# spent 5µs making 1 call to strict::import |
| 4 | |||||
| 5 | 1 | 900ns | require HTTP::Response; | ||
| 6 | 1 | 800ns | require HTTP::Status; | ||
| 7 | 1 | 98µs | require Net::HTTP; | ||
| 8 | |||||
| 9 | 3 | 1.43ms | 2 | 112µs | # spent 61µs (11+50) within LWP::Protocol::http::BEGIN@9 which was called
# once (11µs+50µs) by LWP::Protocol::implementor at line 9 # spent 61µs making 1 call to LWP::Protocol::http::BEGIN@9
# spent 50µs making 1 call to vars::import |
| 10 | |||||
| 11 | 1 | 1µs | require LWP::Protocol; | ||
| 12 | 1 | 13µs | @ISA = qw(LWP::Protocol); | ||
| 13 | |||||
| 14 | 1 | 1µs | my $CRLF = "\015\012"; | ||
| 15 | |||||
| 16 | sub _new_socket | ||||
| 17 | # spent 125ms (136µs+125) within LWP::Protocol::http::_new_socket which was called 3 times, avg 41.6ms/call:
# 3 times (136µs+125ms) by LWP::Protocol::http::request at line 155, avg 41.6ms/call | ||||
| 18 | 3 | 4µs | my($self, $host, $port, $timeout) = @_; | ||
| 19 | 3 | 4µs | my $conn_cache = $self->{ua}{conn_cache}; | ||
| 20 | 3 | 2µs | if ($conn_cache) { | ||
| 21 | 3 | 20µs | 6 | 36µs | if (my $sock = $conn_cache->withdraw($self->socket_type, "$host:$port")) { # spent 30µs making 3 calls to LWP::ConnCache::withdraw, avg 10µs/call
# spent 6µs making 3 calls to LWP::Protocol::http::socket_type, avg 2µs/call |
| 22 | 1 | 7µs | 1 | 19µs | return $sock if $sock && !$sock->can_read(0); # spent 19µs making 1 call to LWP::Protocol::http::SocketMethods::can_read |
| 23 | # if the socket is readable, then either the peer has closed the | ||||
| 24 | # connection or there are some garbage bytes on it. In either | ||||
| 25 | # case we abandon it. | ||||
| 26 | $sock->close; | ||||
| 27 | } | ||||
| 28 | } | ||||
| 29 | |||||
| 30 | 2 | 9µs | local($^W) = 0; # IO::Socket::INET can be noisy | ||
| 31 | 2 | 37µs | 6 | 124ms | my $sock = $self->socket_class->new(PeerAddr => $host, # spent 124ms making 2 calls to Net::HTTP::new, avg 62.2ms/call
# spent 8µs making 2 calls to LWP::Protocol::http::socket_class, avg 4µs/call
# spent 4µs making 2 calls to LWP::Protocol::http::_extra_sock_opts, avg 2µs/call |
| 32 | PeerPort => $port, | ||||
| 33 | LocalAddr => $self->{ua}{local_address}, | ||||
| 34 | Proto => 'tcp', | ||||
| 35 | Timeout => $timeout, | ||||
| 36 | KeepAlive => !!$conn_cache, | ||||
| 37 | SendTE => 1, | ||||
| 38 | $self->_extra_sock_opts($host, $port), | ||||
| 39 | ); | ||||
| 40 | |||||
| 41 | 2 | 900ns | unless ($sock) { | ||
| 42 | # IO::Socket::INET leaves additional error messages in $@ | ||||
| 43 | $@ =~ s/^.*?: //; | ||||
| 44 | die "Can't connect to $host:$port ($@)"; | ||||
| 45 | } | ||||
| 46 | |||||
| 47 | # perl 5.005's IO::Socket does not have the blocking method. | ||||
| 48 | 4 | 8µs | 2 | 23µs | eval { $sock->blocking(0); }; # spent 23µs making 2 calls to IO::Socket::blocking, avg 11µs/call |
| 49 | |||||
| 50 | 2 | 15µs | $sock; | ||
| 51 | } | ||||
| 52 | |||||
| 53 | sub socket_type | ||||
| 54 | { | ||||
| 55 | 5 | 24µs | return "http"; | ||
| 56 | } | ||||
| 57 | |||||
| 58 | sub socket_class | ||||
| 59 | # spent 8µs within LWP::Protocol::http::socket_class which was called 2 times, avg 4µs/call:
# 2 times (8µs+0s) by LWP::Protocol::http::_new_socket at line 31, avg 4µs/call | ||||
| 60 | 2 | 1µs | my $self = shift; | ||
| 61 | 2 | 8µs | (ref($self) || $self) . "::Socket"; | ||
| 62 | } | ||||
| 63 | |||||
| 64 | sub _extra_sock_opts # to be overridden by subclass | ||||
| 65 | # spent 4µs within LWP::Protocol::http::_extra_sock_opts which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by LWP::Protocol::http::_new_socket at line 31, avg 2µs/call | ||||
| 66 | 2 | 7µs | return @EXTRA_SOCK_OPTS; | ||
| 67 | } | ||||
| 68 | |||||
| 69 | sub _check_sock | ||||
| 70 | 3 | 9µs | # spent 5µs within LWP::Protocol::http::_check_sock which was called 3 times, avg 2µs/call:
# 3 times (5µs+0s) by LWP::Protocol::http::request at line 156, avg 2µs/call | ||
| 71 | #my($self, $req, $sock) = @_; | ||||
| 72 | } | ||||
| 73 | |||||
| 74 | sub _get_sock_info | ||||
| 75 | # spent 586µs (80+506) within LWP::Protocol::http::_get_sock_info which was called 3 times, avg 195µs/call:
# 3 times (80µs+506µs) by LWP::Protocol::http::request at line 367, avg 195µs/call | ||||
| 76 | 3 | 4µs | my($self, $res, $sock) = @_; | ||
| 77 | 3 | 63µs | 9 | 412µs | if (defined(my $peerhost = $sock->peerhost)) { # spent 231µs making 3 calls to IO::Socket::INET::peerhost, avg 77µs/call
# spent 104µs making 2 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 52µs/call
# spent 64µs making 3 calls to IO::Socket::INET::peerport, avg 21µs/call
# spent 13µs making 1 call to HTTP::Message::AUTOLOAD |
| 78 | $res->header("Client-Peer" => "$peerhost:" . $sock->peerport); | ||||
| 79 | } | ||||
| 80 | } | ||||
| 81 | |||||
| 82 | sub _fixup_header | ||||
| 83 | # spent 192µs (50+142) within LWP::Protocol::http::_fixup_header which was called 3 times, avg 64µs/call:
# 3 times (50µs+142µs) by LWP::Protocol::http::request at line 160, avg 64µs/call | ||||
| 84 | 3 | 4µs | my($self, $h, $url, $proxy) = @_; | ||
| 85 | |||||
| 86 | # Extract 'Host' header | ||||
| 87 | 3 | 11µs | 3 | 58µs | my $hhost = $url->authority; # spent 58µs making 3 calls to URI::_generic::authority, avg 19µs/call |
| 88 | 3 | 15µs | 3 | 3µs | if ($hhost =~ s/^([^\@]*)\@//) { # get rid of potential "user:pass@" # spent 3µs making 3 calls to LWP::Protocol::http::CORE:subst, avg 1µs/call |
| 89 | # add authorization header if we need them. HTTP URLs do | ||||
| 90 | # not really support specification of user and password, but | ||||
| 91 | # we allow it. | ||||
| 92 | if (defined($1) && not $h->header('Authorization')) { | ||||
| 93 | require URI::Escape; | ||||
| 94 | $h->authorization_basic(map URI::Escape::uri_unescape($_), | ||||
| 95 | split(":", $1, 2)); | ||||
| 96 | } | ||||
| 97 | } | ||||
| 98 | 3 | 9µs | 3 | 81µs | $h->init_header('Host' => $hhost); # spent 81µs making 3 calls to HTTP::Headers::init_header, avg 27µs/call |
| 99 | |||||
| 100 | 3 | 10µs | if ($proxy) { | ||
| 101 | # Check the proxy URI's userinfo() for proxy credentials | ||||
| 102 | # export http_proxy="http://proxyuser:proxypass@proxyhost:port" | ||||
| 103 | my $p_auth = $proxy->userinfo(); | ||||
| 104 | if(defined $p_auth) { | ||||
| 105 | require URI::Escape; | ||||
| 106 | $h->proxy_authorization_basic(map URI::Escape::uri_unescape($_), | ||||
| 107 | split(":", $p_auth, 2)) | ||||
| 108 | } | ||||
| 109 | } | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | sub hlist_remove { | ||||
| 113 | my($hlist, $k) = @_; | ||||
| 114 | $k = lc $k; | ||||
| 115 | for (my $i = @$hlist - 2; $i >= 0; $i -= 2) { | ||||
| 116 | next unless lc($hlist->[$i]) eq $k; | ||||
| 117 | splice(@$hlist, $i, 2); | ||||
| 118 | } | ||||
| 119 | } | ||||
| 120 | |||||
| 121 | sub request | ||||
| 122 | # spent 345ms (1.09+344) within LWP::Protocol::http::request which was called 3 times, avg 115ms/call:
# 3 times (1.09ms+344ms) by LWP::UserAgent::send_request at line 178 of LWP/UserAgent.pm, avg 115ms/call | ||||
| 123 | 3 | 5µs | my($self, $request, $proxy, $arg, $size, $timeout) = @_; | ||
| 124 | |||||
| 125 | 3 | 2µs | $size ||= 4096; | ||
| 126 | |||||
| 127 | # check method | ||||
| 128 | 3 | 7µs | 3 | 26µs | my $method = $request->method; # spent 26µs making 3 calls to HTTP::Request::method, avg 9µs/call |
| 129 | 3 | 29µs | 3 | 17µs | unless ($method =~ /^[A-Za-z0-9_!\#\$%&\'*+\-.^\`|~]+$/) { # HTTP token # spent 17µs making 3 calls to LWP::Protocol::http::CORE:match, avg 6µs/call |
| 130 | return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST, | ||||
| 131 | 'Library does not allow method ' . | ||||
| 132 | "$method for 'http:' URLs"; | ||||
| 133 | } | ||||
| 134 | |||||
| 135 | 3 | 7µs | 3 | 9µs | my $url = $request->uri; # spent 9µs making 3 calls to HTTP::Request::uri, avg 3µs/call |
| 136 | 3 | 2µs | my($host, $port, $fullpath); | ||
| 137 | |||||
| 138 | # Check if we're proxy'ing | ||||
| 139 | 3 | 3µs | if (defined $proxy) { | ||
| 140 | # $proxy is an URL to an HTTP server which will proxy this request | ||||
| 141 | $host = $proxy->host; | ||||
| 142 | $port = $proxy->port; | ||||
| 143 | $fullpath = $method eq "CONNECT" ? | ||||
| 144 | ($url->host . ":" . $url->port) : | ||||
| 145 | $url->as_string; | ||||
| 146 | } | ||||
| 147 | else { | ||||
| 148 | 3 | 14µs | 3 | 109µs | $host = $url->host; # spent 109µs making 3 calls to URI::_server::host, avg 36µs/call |
| 149 | 3 | 12µs | 3 | 86µs | $port = $url->port; # spent 86µs making 3 calls to URI::_server::port, avg 29µs/call |
| 150 | 3 | 12µs | 3 | 30µs | $fullpath = $url->path_query; # spent 30µs making 3 calls to URI::_generic::path_query, avg 10µs/call |
| 151 | 3 | 12µs | 3 | 4µs | $fullpath = "/$fullpath" unless $fullpath =~ m,^/,; # spent 4µs making 3 calls to LWP::Protocol::http::CORE:match, avg 1µs/call |
| 152 | } | ||||
| 153 | |||||
| 154 | # connect to remote site | ||||
| 155 | 3 | 11µs | 3 | 125ms | my $socket = $self->_new_socket($host, $port, $timeout); # spent 125ms making 3 calls to LWP::Protocol::http::_new_socket, avg 41.6ms/call |
| 156 | 3 | 9µs | 3 | 5µs | $self->_check_sock($request, $socket); # spent 5µs making 3 calls to LWP::Protocol::http::_check_sock, avg 2µs/call |
| 157 | |||||
| 158 | 3 | 700ns | my @h; | ||
| 159 | 3 | 324µs | 6 | 309µs | my $request_headers = $request->headers->clone; # spent 297µs making 3 calls to Storable::dclone, avg 99µs/call
# spent 13µs making 3 calls to HTTP::Message::headers, avg 4µs/call |
| 160 | 3 | 10µs | 3 | 192µs | $self->_fixup_header($request_headers, $url, $proxy); # spent 192µs making 3 calls to LWP::Protocol::http::_fixup_header, avg 64µs/call |
| 161 | |||||
| 162 | # spent 82µs (77+6) within LWP::Protocol::http::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm:167] which was called 9 times, avg 9µs/call:
# 9 times (77µs+6µs) by HTTP::Headers::scan at line 231 of HTTP/Headers.pm, avg 9µs/call | ||||
| 163 | 9 | 8µs | my($k, $v) = @_; | ||
| 164 | 9 | 25µs | 9 | 3µs | $k =~ s/^://; # spent 3µs making 9 calls to LWP::Protocol::http::CORE:subst, avg 344ns/call |
| 165 | 9 | 20µs | 9 | 3µs | $v =~ s/\n/ /g; # spent 3µs making 9 calls to LWP::Protocol::http::CORE:subst, avg 311ns/call |
| 166 | 9 | 38µs | push(@h, $k, $v); | ||
| 167 | 3 | 34µs | 3 | 226µs | }); # spent 226µs making 3 calls to HTTP::Headers::scan, avg 75µs/call |
| 168 | |||||
| 169 | 3 | 15µs | 3 | 25µs | my $content_ref = $request->content_ref; # spent 25µs making 3 calls to HTTP::Message::content_ref, avg 8µs/call |
| 170 | 3 | 1µs | $content_ref = $$content_ref if ref($$content_ref); | ||
| 171 | 3 | 600ns | my $chunked; | ||
| 172 | 3 | 700ns | my $has_content; | ||
| 173 | |||||
| 174 | 3 | 4µs | if (ref($content_ref) eq 'CODE') { | ||
| 175 | my $clen = $request_headers->header('Content-Length'); | ||||
| 176 | $has_content++ if $clen; | ||||
| 177 | unless (defined $clen) { | ||||
| 178 | push(@h, "Transfer-Encoding" => "chunked"); | ||||
| 179 | $has_content++; | ||||
| 180 | $chunked++; | ||||
| 181 | } | ||||
| 182 | } | ||||
| 183 | else { | ||||
| 184 | # Set (or override) Content-Length header | ||||
| 185 | 3 | 10µs | 3 | 62µs | my $clen = $request_headers->header('Content-Length'); # spent 62µs making 3 calls to HTTP::Headers::header, avg 21µs/call |
| 186 | 3 | 4µs | if (defined($$content_ref) && length($$content_ref)) { | ||
| 187 | 3 | 1µs | $has_content = length($$content_ref); | ||
| 188 | 3 | 3µs | if (!defined($clen) || $clen ne $has_content) { | ||
| 189 | 3 | 1µs | if (defined $clen) { | ||
| 190 | warn "Content-Length header value was wrong, fixed"; | ||||
| 191 | hlist_remove(\@h, 'Content-Length'); | ||||
| 192 | } | ||||
| 193 | 3 | 4µs | push(@h, 'Content-Length' => $has_content); | ||
| 194 | } | ||||
| 195 | } | ||||
| 196 | elsif ($clen) { | ||||
| 197 | warn "Content-Length set when there is no content, fixed"; | ||||
| 198 | hlist_remove(\@h, 'Content-Length'); | ||||
| 199 | } | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | 3 | 2µs | my $write_wait = 0; | ||
| 203 | 3 | 18µs | 6 | 45µs | $write_wait = 2 # spent 44µs making 3 calls to HTTP::Headers::header, avg 15µs/call
# spent 900ns making 3 calls to LWP::Protocol::http::CORE:match, avg 300ns/call |
| 204 | if ($request_headers->header("Expect") || "") =~ /100-continue/; | ||||
| 205 | |||||
| 206 | 3 | 18µs | 3 | 37.9ms | my $req_buf = $socket->format_request($method, $fullpath, @h); # spent 37.9ms making 3 calls to Net::HTTP::Methods::format_request, avg 12.6ms/call |
| 207 | #print "------\n$req_buf\n------\n"; | ||||
| 208 | |||||
| 209 | 3 | 3µs | if (!$has_content || $write_wait || $has_content > 8*1024) { | ||
| 210 | WRITE: | ||||
| 211 | { | ||||
| 212 | # Since this just writes out the header block it should almost | ||||
| 213 | # always succeed to send the whole buffer in a single write call. | ||||
| 214 | my $n = $socket->syswrite($req_buf, length($req_buf)); | ||||
| 215 | unless (defined $n) { | ||||
| 216 | 3 | 1.49ms | 1 | 2.08ms | # spent 2.08ms (1.96+126µs) within LWP::Protocol::http::BEGIN@216 which was called
# once (1.96ms+126µs) by LWP::Protocol::implementor at line 216 # spent 2.08ms making 1 call to LWP::Protocol::http::BEGIN@216 |
| 217 | if ($!{EAGAIN}) { | ||||
| 218 | select(undef, undef, undef, 0.1); | ||||
| 219 | redo WRITE; | ||||
| 220 | } | ||||
| 221 | die "write failed: $!"; | ||||
| 222 | } | ||||
| 223 | if ($n) { | ||||
| 224 | substr($req_buf, 0, $n, ""); | ||||
| 225 | } | ||||
| 226 | else { | ||||
| 227 | select(undef, undef, undef, 0.5); | ||||
| 228 | } | ||||
| 229 | redo WRITE if length $req_buf; | ||||
| 230 | } | ||||
| 231 | } | ||||
| 232 | |||||
| 233 | 3 | 3µs | my($code, $mess, @junk); | ||
| 234 | 3 | 800ns | my $drop_connection; | ||
| 235 | |||||
| 236 | 3 | 2µs | if ($has_content) { | ||
| 237 | 3 | 800ns | my $eof; | ||
| 238 | 3 | 600ns | my $wbuf; | ||
| 239 | 3 | 1µs | my $woffset = 0; | ||
| 240 | 3 | 4µs | if (ref($content_ref) eq 'CODE') { | ||
| 241 | my $buf = &$content_ref(); | ||||
| 242 | $buf = "" unless defined($buf); | ||||
| 243 | $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF | ||||
| 244 | if $chunked; | ||||
| 245 | substr($buf, 0, 0) = $req_buf if $req_buf; | ||||
| 246 | $wbuf = \$buf; | ||||
| 247 | } | ||||
| 248 | else { | ||||
| 249 | 3 | 2µs | if ($req_buf) { | ||
| 250 | 3 | 10µs | my $buf = $req_buf . $$content_ref; | ||
| 251 | 3 | 2µs | $wbuf = \$buf; | ||
| 252 | } | ||||
| 253 | else { | ||||
| 254 | $wbuf = $content_ref; | ||||
| 255 | } | ||||
| 256 | 3 | 800ns | $eof = 1; | ||
| 257 | } | ||||
| 258 | |||||
| 259 | 3 | 3µs | my $fbits = ''; | ||
| 260 | 3 | 8µs | vec($fbits, fileno($socket), 1) = 1; | ||
| 261 | |||||
| 262 | WRITE: | ||||
| 263 | 3 | 6µs | while ($woffset < length($$wbuf)) { | ||
| 264 | |||||
| 265 | 3 | 1µs | my $sel_timeout = $timeout; | ||
| 266 | 3 | 800ns | if ($write_wait) { | ||
| 267 | $sel_timeout = $write_wait if $write_wait < $sel_timeout; | ||||
| 268 | } | ||||
| 269 | 3 | 500ns | my $time_before; | ||
| 270 | 3 | 4µs | $time_before = time if $sel_timeout; | ||
| 271 | |||||
| 272 | 3 | 1µs | my $rbits = $fbits; | ||
| 273 | 3 | 1µs | my $wbits = $write_wait ? undef : $fbits; | ||
| 274 | 3 | 1µs | my $sel_timeout_before = $sel_timeout; | ||
| 275 | 3 | 42µs | 3 | 27µs | SELECT: # spent 27µs making 3 calls to LWP::Protocol::http::CORE:sselect, avg 9µs/call |
| 276 | { | ||||
| 277 | 3 | 2µs | my $nfound = select($rbits, $wbits, undef, $sel_timeout); | ||
| 278 | 3 | 3µs | if ($nfound < 0) { | ||
| 279 | if ($!{EINTR} || $!{EAGAIN}) { | ||||
| 280 | if ($time_before) { | ||||
| 281 | $sel_timeout = $sel_timeout_before - (time - $time_before); | ||||
| 282 | $sel_timeout = 0 if $sel_timeout < 0; | ||||
| 283 | } | ||||
| 284 | redo SELECT; | ||||
| 285 | } | ||||
| 286 | die "select failed: $!"; | ||||
| 287 | } | ||||
| 288 | } | ||||
| 289 | |||||
| 290 | 3 | 1µs | if ($write_wait) { | ||
| 291 | $write_wait -= time - $time_before; | ||||
| 292 | $write_wait = 0 if $write_wait < 0; | ||||
| 293 | } | ||||
| 294 | |||||
| 295 | 3 | 14µs | 3 | 4µs | if (defined($rbits) && $rbits =~ /[^\0]/) { # spent 4µs making 3 calls to LWP::Protocol::http::CORE:match, avg 1µs/call |
| 296 | # readable | ||||
| 297 | my $buf = $socket->_rbuf; | ||||
| 298 | my $n = $socket->sysread($buf, 1024, length($buf)); | ||||
| 299 | unless (defined $n) { | ||||
| 300 | die "read failed: $!" unless $!{EINTR} || $!{EAGAIN}; | ||||
| 301 | # if we get here the rest of the block will do nothing | ||||
| 302 | # and we will retry the read on the next round | ||||
| 303 | } | ||||
| 304 | elsif ($n == 0) { | ||||
| 305 | # the server closed the connection before we finished | ||||
| 306 | # writing all the request content. No need to write any more. | ||||
| 307 | $drop_connection++; | ||||
| 308 | last WRITE; | ||||
| 309 | } | ||||
| 310 | $socket->_rbuf($buf); | ||||
| 311 | if (!$code && $buf =~ /\015?\012\015?\012/) { | ||||
| 312 | # a whole response header is present, so we can read it without blocking | ||||
| 313 | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, | ||||
| 314 | junk_out => \@junk, | ||||
| 315 | ); | ||||
| 316 | if ($code eq "100") { | ||||
| 317 | $write_wait = 0; | ||||
| 318 | undef($code); | ||||
| 319 | } | ||||
| 320 | else { | ||||
| 321 | $drop_connection++; | ||||
| 322 | last WRITE; | ||||
| 323 | # XXX should perhaps try to abort write in a nice way too | ||||
| 324 | } | ||||
| 325 | } | ||||
| 326 | } | ||||
| 327 | 3 | 18µs | 3 | 4µs | if (defined($wbits) && $wbits =~ /[^\0]/) { # spent 4µs making 3 calls to LWP::Protocol::http::CORE:match, avg 1µs/call |
| 328 | 3 | 26µs | 3 | 204µs | my $n = $socket->syswrite($$wbuf, length($$wbuf), $woffset); # spent 204µs making 3 calls to IO::Handle::syswrite, avg 68µs/call |
| 329 | 3 | 3µs | unless (defined $n) { | ||
| 330 | die "write failed: $!" unless $!{EINTR} || $!{EAGAIN}; | ||||
| 331 | $n = 0; # will retry write on the next round | ||||
| 332 | } | ||||
| 333 | elsif ($n == 0) { | ||||
| 334 | die "write failed: no bytes written"; | ||||
| 335 | } | ||||
| 336 | 3 | 2µs | $woffset += $n; | ||
| 337 | |||||
| 338 | 3 | 2µs | if (!$eof && $woffset >= length($$wbuf)) { | ||
| 339 | # need to refill buffer from $content_ref code | ||||
| 340 | my $buf = &$content_ref(); | ||||
| 341 | $buf = "" unless defined($buf); | ||||
| 342 | $eof++ unless length($buf); | ||||
| 343 | $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF | ||||
| 344 | if $chunked; | ||||
| 345 | $wbuf = \$buf; | ||||
| 346 | $woffset = 0; | ||||
| 347 | } | ||||
| 348 | } | ||||
| 349 | } # WRITE | ||||
| 350 | } | ||||
| 351 | |||||
| 352 | 3 | 65µs | 3 | 175ms | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk) # spent 175ms making 3 calls to Net::HTTP::Methods::read_response_headers, avg 58.4ms/call |
| 353 | unless $code; | ||||
| 354 | 3 | 2µs | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk) | ||
| 355 | if $code eq "100"; | ||||
| 356 | |||||
| 357 | 3 | 32µs | 3 | 314µs | my $response = HTTP::Response->new($code, $mess); # spent 314µs making 3 calls to HTTP::Response::new, avg 105µs/call |
| 358 | 3 | 13µs | 3 | 18µs | my $peer_http_version = $socket->peer_http_version; # spent 18µs making 3 calls to Net::HTTP::Methods::__ANON__[Net/HTTP/Methods.pm:104], avg 6µs/call |
| 359 | 3 | 18µs | 3 | 32µs | $response->protocol("HTTP/$peer_http_version"); # spent 32µs making 3 calls to HTTP::Message::protocol, avg 11µs/call |
| 360 | { | ||||
| 361 | 6 | 5µs | local $HTTP::Headers::TRANSLATE_UNDERSCORE; | ||
| 362 | 3 | 25µs | 3 | 212µs | $response->push_header(@h); # spent 184µs making 2 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 92µs/call
# spent 28µs making 1 call to HTTP::Message::AUTOLOAD |
| 363 | } | ||||
| 364 | 3 | 2µs | $response->push_header("Client-Junk" => \@junk) if @junk; | ||
| 365 | |||||
| 366 | 3 | 11µs | 3 | 35µs | $response->request($request); # spent 35µs making 3 calls to HTTP::Response::request, avg 12µs/call |
| 367 | 3 | 13µs | 3 | 586µs | $self->_get_sock_info($response, $socket); # spent 586µs making 3 calls to LWP::Protocol::http::_get_sock_info, avg 195µs/call |
| 368 | |||||
| 369 | 3 | 2µs | if ($method eq "CONNECT") { | ||
| 370 | $response->{client_socket} = $socket; # so it can be picked up | ||||
| 371 | return $response; | ||||
| 372 | } | ||||
| 373 | |||||
| 374 | 3 | 31µs | 5 | 156µs | if (my @te = $response->remove_header('Transfer-Encoding')) { # spent 143µs making 4 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 36µs/call
# spent 13µs making 1 call to HTTP::Message::AUTOLOAD |
| 375 | $response->push_header('Client-Transfer-Encoding', \@te); | ||||
| 376 | } | ||||
| 377 | 3 | 22µs | 6 | 124µs | $response->push_header('Client-Response-Num', scalar $socket->increment_response_count); # spent 110µs making 3 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 37µs/call
# spent 14µs making 3 calls to LWP::Protocol::http::SocketMethods::increment_response_count, avg 5µs/call |
| 378 | |||||
| 379 | 3 | 2µs | my $complete; | ||
| 380 | # spent 728µs (82+646) within LWP::Protocol::http::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm:394] which was called 7 times, avg 104µs/call:
# 4 times (32µs+408µs) by LWP::Protocol::collect at line 158 of LWP/Protocol.pm, avg 110µs/call
# 3 times (50µs+238µs) by LWP::Protocol::collect at line 148 of LWP/Protocol.pm, avg 96µs/call | ||||
| 381 | 7 | 4µs | my $buf = ""; #prevent use of uninitialized value in SSLeay.xs | ||
| 382 | 7 | 2µs | my $n; | ||
| 383 | 7 | 32µs | 7 | 646µs | READ: # spent 646µs making 7 calls to Net::HTTP::Methods::read_entity_body, avg 92µs/call |
| 384 | { | ||||
| 385 | 7 | 3µs | $n = $socket->read_entity_body($buf, $size); | ||
| 386 | 7 | 2µs | unless (defined $n) { | ||
| 387 | redo READ if $!{EINTR} || $!{EAGAIN}; | ||||
| 388 | die "read failed: $!"; | ||||
| 389 | } | ||||
| 390 | 7 | 4µs | redo READ if $n == -1; | ||
| 391 | } | ||||
| 392 | 7 | 3µs | $complete++ if !$n; | ||
| 393 | 7 | 29µs | return \$buf; | ||
| 394 | 3 | 53µs | 3 | 2.84ms | } ); # spent 2.84ms making 3 calls to LWP::Protocol::collect, avg 945µs/call |
| 395 | 3 | 2µs | $drop_connection++ unless $complete; | ||
| 396 | |||||
| 397 | 3 | 28µs | 3 | 14µs | @h = $socket->get_trailers; # spent 14µs making 3 calls to Net::HTTP::Methods::get_trailers, avg 5µs/call |
| 398 | 3 | 2µs | if (@h) { | ||
| 399 | local $HTTP::Headers::TRANSLATE_UNDERSCORE; | ||||
| 400 | $response->push_header(@h); | ||||
| 401 | } | ||||
| 402 | |||||
| 403 | # keep-alive support | ||||
| 404 | 3 | 4µs | unless ($drop_connection) { | ||
| 405 | 3 | 6µs | if (my $conn_cache = $self->{ua}{conn_cache}) { | ||
| 406 | 3 | 25µs | 3 | 107µs | my %connection = map { (lc($_) => 1) } # spent 107µs making 3 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 36µs/call |
| 407 | split(/\s*,\s*/, ($response->header("Connection") || "")); | ||||
| 408 | 3 | 29µs | 4 | 83µs | if (($peer_http_version eq "1.1" && !$connection{close}) || # spent 74µs making 2 calls to LWP::ConnCache::deposit, avg 37µs/call
# spent 9µs making 2 calls to LWP::Protocol::http::socket_type, avg 5µs/call |
| 409 | $connection{"keep-alive"}) | ||||
| 410 | { | ||||
| 411 | $conn_cache->deposit($self->socket_type, "$host:$port", $socket); | ||||
| 412 | } | ||||
| 413 | } | ||||
| 414 | } | ||||
| 415 | |||||
| 416 | 3 | 108µs | $response; | ||
| 417 | } | ||||
| 418 | |||||
| 419 | |||||
| 420 | #----------------------------------------------------------- | ||||
| 421 | package LWP::Protocol::http::SocketMethods; | ||||
| 422 | |||||
| 423 | # spent 174ms (141µs+174) within LWP::Protocol::http::SocketMethods::sysread which was called 7 times, avg 24.9ms/call:
# 5 times (123µs+174ms) by Net::HTTP::Methods::my_readline at line 256 of Net/HTTP/Methods.pm, avg 34.9ms/call
# 2 times (17µs+48µs) by Net::HTTP::Methods::my_read at line 236 of Net/HTTP/Methods.pm, avg 33µs/call | ||||
| 424 | 7 | 3µs | my $self = shift; | ||
| 425 | 7 | 13µs | if (my $timeout = ${*$self}{io_socket_timeout}) { | ||
| 426 | 7 | 19µs | 7 | 174ms | die "read timeout" unless $self->can_read($timeout); # spent 174ms making 7 calls to LWP::Protocol::http::SocketMethods::can_read, avg 24.9ms/call |
| 427 | } | ||||
| 428 | else { | ||||
| 429 | # since we have made the socket non-blocking we | ||||
| 430 | # use select to wait for some data to arrive | ||||
| 431 | $self->can_read(undef) || die "Assert"; | ||||
| 432 | } | ||||
| 433 | 7 | 181µs | 7 | 90µs | sysread($self, $_[0], $_[1], $_[2] || 0); # spent 90µs making 7 calls to LWP::Protocol::http::SocketMethods::CORE:sysread, avg 13µs/call |
| 434 | } | ||||
| 435 | |||||
| 436 | sub can_read { | ||||
| 437 | 8 | 7µs | my($self, $timeout) = @_; | ||
| 438 | 8 | 5µs | my $fbits = ''; | ||
| 439 | 8 | 18µs | vec($fbits, fileno($self), 1) = 1; | ||
| 440 | 8 | 1µs | SELECT: | ||
| 441 | { | ||||
| 442 | 8 | 1µs | my $before; | ||
| 443 | 8 | 8µs | $before = time if $timeout; | ||
| 444 | 8 | 174ms | 8 | 174ms | my $nfound = select($fbits, undef, undef, $timeout); # spent 174ms making 8 calls to LWP::Protocol::http::SocketMethods::CORE:sselect, avg 21.8ms/call |
| 445 | 8 | 8µs | if ($nfound < 0) { | ||
| 446 | if ($!{EINTR} || $!{EAGAIN}) { | ||||
| 447 | # don't really think EAGAIN can happen here | ||||
| 448 | if ($timeout) { | ||||
| 449 | $timeout -= time - $before; | ||||
| 450 | $timeout = 0 if $timeout < 0; | ||||
| 451 | } | ||||
| 452 | redo SELECT; | ||||
| 453 | } | ||||
| 454 | die "select failed: $!"; | ||||
| 455 | } | ||||
| 456 | 8 | 78µs | return $nfound > 0; | ||
| 457 | } | ||||
| 458 | } | ||||
| 459 | |||||
| 460 | sub ping { | ||||
| 461 | my $self = shift; | ||||
| 462 | !$self->can_read(0); | ||||
| 463 | } | ||||
| 464 | |||||
| 465 | # spent 14µs within LWP::Protocol::http::SocketMethods::increment_response_count which was called 3 times, avg 5µs/call:
# 3 times (14µs+0s) by LWP::Protocol::http::request at line 377, avg 5µs/call | ||||
| 466 | 3 | 2µs | my $self = shift; | ||
| 467 | 3 | 23µs | return ++${*$self}{'myhttp_response_count'}; | ||
| 468 | } | ||||
| 469 | |||||
| 470 | #----------------------------------------------------------- | ||||
| 471 | package LWP::Protocol::http::Socket; | ||||
| 472 | 3 | 56µs | 2 | 78µs | # spent 45µs (12+33) within LWP::Protocol::http::Socket::BEGIN@472 which was called
# once (12µs+33µs) by LWP::Protocol::implementor at line 472 # spent 45µs making 1 call to LWP::Protocol::http::Socket::BEGIN@472
# spent 33µs making 1 call to vars::import |
| 473 | 1 | 18µs | @ISA = qw(LWP::Protocol::http::SocketMethods Net::HTTP); | ||
| 474 | |||||
| 475 | 1 | 10µs | 1; | ||
# spent 30µs within LWP::Protocol::http::CORE:match which was called 15 times, avg 2µs/call:
# 3 times (17µs+0s) by LWP::Protocol::http::request at line 129 of LWP/Protocol/http.pm, avg 6µs/call
# 3 times (4µs+0s) by LWP::Protocol::http::request at line 295 of LWP/Protocol/http.pm, avg 1µs/call
# 3 times (4µs+0s) by LWP::Protocol::http::request at line 327 of LWP/Protocol/http.pm, avg 1µs/call
# 3 times (4µs+0s) by LWP::Protocol::http::request at line 151 of LWP/Protocol/http.pm, avg 1µs/call
# 3 times (900ns+0s) by LWP::Protocol::http::request at line 203 of LWP/Protocol/http.pm, avg 300ns/call | |||||
# spent 27µs within LWP::Protocol::http::CORE:sselect which was called 3 times, avg 9µs/call:
# 3 times (27µs+0s) by LWP::Protocol::http::request at line 275 of LWP/Protocol/http.pm, avg 9µs/call | |||||
# spent 9µs within LWP::Protocol::http::CORE:subst which was called 21 times, avg 448ns/call:
# 9 times (3µs+0s) by LWP::Protocol::http::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm:167] at line 164 of LWP/Protocol/http.pm, avg 344ns/call
# 9 times (3µs+0s) by LWP::Protocol::http::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm:167] at line 165 of LWP/Protocol/http.pm, avg 311ns/call
# 3 times (3µs+0s) by LWP::Protocol::http::_fixup_header at line 88 of LWP/Protocol/http.pm, avg 1µs/call | |||||
# spent 174ms within LWP::Protocol::http::SocketMethods::CORE:sselect which was called 8 times, avg 21.8ms/call:
# 8 times (174ms+0s) by LWP::Protocol::http::SocketMethods::can_read at line 444 of LWP/Protocol/http.pm, avg 21.8ms/call | |||||
# spent 90µs within LWP::Protocol::http::SocketMethods::CORE:sysread which was called 7 times, avg 13µs/call:
# 7 times (90µs+0s) by LWP::Protocol::http::SocketMethods::sysread at line 433 of LWP/Protocol/http.pm, avg 13µs/call |