| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/quic/quic_client.h" | 5 #include "net/tools/quic/quic_client.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "net/quic/crypto/quic_random.h" | 14 #include "net/quic/crypto/quic_random.h" |
| 15 #include "net/quic/quic_connection.h" | 15 #include "net/quic/quic_connection.h" |
| 16 #include "net/quic/quic_data_reader.h" | 16 #include "net/quic/quic_data_reader.h" |
| 17 #include "net/quic/quic_protocol.h" | 17 #include "net/quic/quic_protocol.h" |
| 18 #include "net/quic/quic_server_id.h" | 18 #include "net/quic/quic_server_id.h" |
| 19 #include "net/tools/balsa/balsa_headers.h" | 19 #include "net/tools/balsa/balsa_headers.h" |
| 20 #include "net/tools/epoll_server/epoll_server.h" | 20 #include "net/tools/epoll_server/epoll_server.h" |
| 21 #include "net/tools/quic/quic_epoll_connection_helper.h" | 21 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 22 #include "net/tools/quic/quic_socket_utils.h" | 22 #include "net/tools/quic/quic_socket_utils.h" |
| 23 #include "net/tools/quic/quic_spdy_client_stream.h" | 23 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 24 #include "net/tools/quic/spdy_utils.h" |
| 24 | 25 |
| 25 #ifndef SO_RXQ_OVFL | 26 #ifndef SO_RXQ_OVFL |
| 26 #define SO_RXQ_OVFL 40 | 27 #define SO_RXQ_OVFL 40 |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 using std::string; | 30 using std::string; |
| 30 using std::vector; | 31 using std::vector; |
| 31 | 32 |
| 32 namespace net { | 33 namespace net { |
| 33 namespace tools { | 34 namespace tools { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 243 } |
| 243 | 244 |
| 244 void QuicClient::SendRequest(const BalsaHeaders& headers, | 245 void QuicClient::SendRequest(const BalsaHeaders& headers, |
| 245 StringPiece body, | 246 StringPiece body, |
| 246 bool fin) { | 247 bool fin) { |
| 247 QuicSpdyClientStream* stream = CreateReliableClientStream(); | 248 QuicSpdyClientStream* stream = CreateReliableClientStream(); |
| 248 if (stream == nullptr) { | 249 if (stream == nullptr) { |
| 249 LOG(DFATAL) << "stream creation failed!"; | 250 LOG(DFATAL) << "stream creation failed!"; |
| 250 return; | 251 return; |
| 251 } | 252 } |
| 252 stream->SendRequest(headers, body, fin); | 253 stream->SendRequest( |
| 254 SpdyUtils::RequestHeadersToSpdyHeaders(headers), body, fin); |
| 253 stream->set_visitor(this); | 255 stream->set_visitor(this); |
| 254 } | 256 } |
| 255 | 257 |
| 256 void QuicClient::SendRequestAndWaitForResponse( | 258 void QuicClient::SendRequestAndWaitForResponse( |
| 257 const BalsaHeaders& headers, | 259 const BalsaHeaders& headers, |
| 258 StringPiece body, | 260 StringPiece body, |
| 259 bool fin) { | 261 bool fin) { |
| 260 SendRequest(headers, body, fin); | 262 SendRequest(headers, body, fin); |
| 261 while (WaitForEvents()) {} | 263 while (WaitForEvents()) {} |
| 262 } | 264 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 session_->connection()->OnCanWrite(); | 316 session_->connection()->OnCanWrite(); |
| 315 } | 317 } |
| 316 if (event->in_events & NET_POLLERR) { | 318 if (event->in_events & NET_POLLERR) { |
| 317 DVLOG(1) << "NET_POLLERR"; | 319 DVLOG(1) << "NET_POLLERR"; |
| 318 } | 320 } |
| 319 } | 321 } |
| 320 | 322 |
| 321 void QuicClient::OnClose(QuicDataStream* stream) { | 323 void QuicClient::OnClose(QuicDataStream* stream) { |
| 322 QuicSpdyClientStream* client_stream = | 324 QuicSpdyClientStream* client_stream = |
| 323 static_cast<QuicSpdyClientStream*>(stream); | 325 static_cast<QuicSpdyClientStream*>(stream); |
| 326 BalsaHeaders headers; |
| 327 SpdyUtils::FillBalsaResponseHeaders(client_stream->headers(), &headers); |
| 328 |
| 324 if (response_listener_.get() != nullptr) { | 329 if (response_listener_.get() != nullptr) { |
| 325 response_listener_->OnCompleteResponse( | 330 response_listener_->OnCompleteResponse( |
| 326 stream->id(), client_stream->headers(), client_stream->data()); | 331 stream->id(), headers, client_stream->data()); |
| 327 } | 332 } |
| 328 | 333 |
| 329 // Store response headers and body. | 334 // Store response headers and body. |
| 330 if (store_response_) { | 335 if (store_response_) { |
| 331 latest_response_code_ = client_stream->headers().parsed_response_code(); | 336 latest_response_code_ = headers.parsed_response_code(); |
| 332 client_stream->headers().DumpHeadersToString(&latest_response_headers_); | 337 headers.DumpHeadersToString(&latest_response_headers_); |
| 333 latest_response_body_ = client_stream->data(); | 338 latest_response_body_ = client_stream->data(); |
| 334 } | 339 } |
| 335 } | 340 } |
| 336 | 341 |
| 337 bool QuicClient::connected() const { | 342 bool QuicClient::connected() const { |
| 338 return session_.get() && session_->connection() && | 343 return session_.get() && session_->connection() && |
| 339 session_->connection()->connected(); | 344 session_->connection()->connected(); |
| 340 } | 345 } |
| 341 | 346 |
| 342 bool QuicClient::goaway_received() const { | 347 bool QuicClient::goaway_received() const { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 QuicEncryptedPacket packet(buf, bytes_read, false); | 402 QuicEncryptedPacket packet(buf, bytes_read, false); |
| 398 | 403 |
| 399 IPEndPoint client_address(client_ip, client_address_.port()); | 404 IPEndPoint client_address(client_ip, client_address_.port()); |
| 400 session_->connection()->ProcessUdpPacket( | 405 session_->connection()->ProcessUdpPacket( |
| 401 client_address, server_address, packet); | 406 client_address, server_address, packet); |
| 402 return true; | 407 return true; |
| 403 } | 408 } |
| 404 | 409 |
| 405 } // namespace tools | 410 } // namespace tools |
| 406 } // namespace net | 411 } // namespace net |
| OLD | NEW |