| 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 // A toy client, which connects to a specified port and sends QUIC | 5 // A toy client, which connects to a specified port and sends QUIC |
| 6 // request to that endpoint. | 6 // request to that endpoint. |
| 7 | 7 |
| 8 #ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ | 8 #ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ |
| 9 #define NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ | 9 #define NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
| 19 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" |
| 20 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 21 #include "net/quic/crypto/crypto_handshake.h" | 21 #include "net/quic/crypto/crypto_handshake.h" |
| 22 #include "net/quic/quic_config.h" | 22 #include "net/quic/quic_config.h" |
| 23 #include "net/quic/quic_framer.h" | 23 #include "net/quic/quic_framer.h" |
| 24 #include "net/quic/quic_packet_creator.h" | 24 #include "net/quic/quic_packet_creator.h" |
| 25 #include "net/quic/quic_packet_reader.h" |
| 25 #include "net/tools/quic/quic_simple_client_session.h" | 26 #include "net/tools/quic/quic_simple_client_session.h" |
| 26 #include "net/tools/quic/quic_simple_client_stream.h" | 27 #include "net/tools/quic/quic_simple_client_stream.h" |
| 27 | 28 |
| 28 namespace net { | 29 namespace net { |
| 29 | 30 |
| 30 struct HttpRequestInfo; | 31 struct HttpRequestInfo; |
| 31 class ProofVerifier; | 32 class ProofVerifier; |
| 32 class QuicServerId; | 33 class QuicServerId; |
| 33 class QuicConnectionHelper; | 34 class QuicConnectionHelper; |
| 34 class UDPClientSocket; | 35 class UDPClientSocket; |
| 35 | 36 |
| 36 namespace tools { | 37 namespace tools { |
| 37 | 38 |
| 38 namespace test { | 39 namespace test { |
| 39 class QuicClientPeer; | 40 class QuicClientPeer; |
| 40 } // namespace test | 41 } // namespace test |
| 41 | 42 |
| 42 class QuicSimpleClient : public QuicDataStream::Visitor { | 43 class QuicSimpleClient : public QuicDataStream::Visitor, |
| 44 public QuicPacketReader::Visitor { |
| 43 public: | 45 public: |
| 44 class ResponseListener { | 46 class ResponseListener { |
| 45 public: | 47 public: |
| 46 ResponseListener() {} | 48 ResponseListener() {} |
| 47 virtual ~ResponseListener() {} | 49 virtual ~ResponseListener() {} |
| 48 virtual void OnCompleteResponse(QuicStreamId id, | 50 virtual void OnCompleteResponse(QuicStreamId id, |
| 49 const HttpResponseHeaders& response_headers, | 51 const HttpResponseHeaders& response_headers, |
| 50 const std::string& response_body) = 0; | 52 const std::string& response_body) = 0; |
| 51 }; | 53 }; |
| 52 | 54 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Wait for events until the stream with the given ID is closed. | 108 // Wait for events until the stream with the given ID is closed. |
| 107 void WaitForStreamToClose(QuicStreamId id); | 109 void WaitForStreamToClose(QuicStreamId id); |
| 108 | 110 |
| 109 // Wait for events until the handshake is confirmed. | 111 // Wait for events until the handshake is confirmed. |
| 110 void WaitForCryptoHandshakeConfirmed(); | 112 void WaitForCryptoHandshakeConfirmed(); |
| 111 | 113 |
| 112 // Wait up to 50ms, and handle any events which occur. | 114 // Wait up to 50ms, and handle any events which occur. |
| 113 // Returns true if there are any outstanding requests. | 115 // Returns true if there are any outstanding requests. |
| 114 bool WaitForEvents(); | 116 bool WaitForEvents(); |
| 115 | 117 |
| 116 // Start the read loop on the socket. | 118 // QuicPacketReader::Visitor |
| 117 void StartReading(); | 119 void OnReadError(int result) override; |
| 118 | 120 bool OnPacket(const QuicEncryptedPacket& packet, |
| 119 // Called on reads that complete asynchronously. Dispatches the packet and | 121 IPEndPoint local_address, |
| 120 // calls StartReading() again. | 122 IPEndPoint peer_address) override; |
| 121 void OnReadComplete(int result); | |
| 122 | 123 |
| 123 // QuicDataStream::Visitor | 124 // QuicDataStream::Visitor |
| 124 void OnClose(QuicDataStream* stream) override; | 125 void OnClose(QuicDataStream* stream) override; |
| 125 | 126 |
| 126 QuicSimpleClientSession* session() { return session_.get(); } | 127 QuicSimpleClientSession* session() { return session_.get(); } |
| 127 | 128 |
| 128 bool connected() const; | 129 bool connected() const; |
| 129 bool goaway_received() const; | 130 bool goaway_received() const; |
| 130 | 131 |
| 131 void set_bind_to_address(IPAddressNumber address) { | 132 void set_bind_to_address(IPAddressNumber address) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 272 |
| 272 // If true, store the latest response code, headers, and body. | 273 // If true, store the latest response code, headers, and body. |
| 273 bool store_response_; | 274 bool store_response_; |
| 274 // HTTP response code from most recent response. | 275 // HTTP response code from most recent response. |
| 275 size_t latest_response_code_; | 276 size_t latest_response_code_; |
| 276 // HTTP headers from most recent response. | 277 // HTTP headers from most recent response. |
| 277 std::string latest_response_headers_; | 278 std::string latest_response_headers_; |
| 278 // Body of most recent response. | 279 // Body of most recent response. |
| 279 std::string latest_response_body_; | 280 std::string latest_response_body_; |
| 280 | 281 |
| 281 bool read_pending_; | |
| 282 | |
| 283 // The number of iterations of the read loop that have completed synchronously | |
| 284 // and without posting a new task to the message loop. | |
| 285 int synchronous_read_count_; | |
| 286 | |
| 287 // The target buffer of the current read. | |
| 288 scoped_refptr<IOBufferWithSize> read_buffer_; | |
| 289 | |
| 290 // The log used for the sockets. | 282 // The log used for the sockets. |
| 291 NetLog net_log_; | 283 NetLog net_log_; |
| 292 | 284 |
| 285 scoped_ptr<QuicPacketReader> packet_reader_; |
| 286 |
| 293 base::WeakPtrFactory<QuicSimpleClient> weak_factory_; | 287 base::WeakPtrFactory<QuicSimpleClient> weak_factory_; |
| 294 | 288 |
| 295 DISALLOW_COPY_AND_ASSIGN(QuicSimpleClient); | 289 DISALLOW_COPY_AND_ASSIGN(QuicSimpleClient); |
| 296 }; | 290 }; |
| 297 | 291 |
| 298 } // namespace tools | 292 } // namespace tools |
| 299 } // namespace net | 293 } // namespace net |
| 300 | 294 |
| 301 #endif // NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ | 295 #endif // NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_H_ |
| OLD | NEW |