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_CLIENT_H_ | 8 #ifndef NET_TOOLS_QUIC_QUIC_CLIENT_H_ |
9 #define NET_TOOLS_QUIC_QUIC_CLIENT_H_ | 9 #define NET_TOOLS_QUIC_QUIC_CLIENT_H_ |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const QuicVersionVector& supported_versions, | 54 const QuicVersionVector& supported_versions, |
55 bool print_response, | 55 bool print_response, |
56 EpollServer* epoll_server); | 56 EpollServer* epoll_server); |
57 QuicClient(IPEndPoint server_address, | 57 QuicClient(IPEndPoint server_address, |
58 const QuicServerId& server_id, | 58 const QuicServerId& server_id, |
59 const QuicVersionVector& supported_versions, | 59 const QuicVersionVector& supported_versions, |
60 bool print_response, | 60 bool print_response, |
61 const QuicConfig& config, | 61 const QuicConfig& config, |
62 EpollServer* epoll_server); | 62 EpollServer* epoll_server); |
63 | 63 |
64 virtual ~QuicClient(); | 64 ~QuicClient() override; |
65 | 65 |
66 // Initializes the client to create a connection. Should be called exactly | 66 // Initializes the client to create a connection. Should be called exactly |
67 // once before calling StartConnect or Connect. Returns true if the | 67 // once before calling StartConnect or Connect. Returns true if the |
68 // initialization succeeds, false otherwise. | 68 // initialization succeeds, false otherwise. |
69 bool Initialize(); | 69 bool Initialize(); |
70 | 70 |
71 // "Connect" to the QUIC server, including performing synchronous crypto | 71 // "Connect" to the QUIC server, including performing synchronous crypto |
72 // handshake. | 72 // handshake. |
73 bool Connect(); | 73 bool Connect(); |
74 | 74 |
(...skipping 23 matching lines...) Expand all Loading... |
98 void WaitForStreamToClose(QuicStreamId id); | 98 void WaitForStreamToClose(QuicStreamId id); |
99 | 99 |
100 // Wait for events until the handshake is confirmed. | 100 // Wait for events until the handshake is confirmed. |
101 void WaitForCryptoHandshakeConfirmed(); | 101 void WaitForCryptoHandshakeConfirmed(); |
102 | 102 |
103 // Wait up to 50ms, and handle any events which occur. | 103 // Wait up to 50ms, and handle any events which occur. |
104 // Returns true if there are any outstanding requests. | 104 // Returns true if there are any outstanding requests. |
105 bool WaitForEvents(); | 105 bool WaitForEvents(); |
106 | 106 |
107 // From EpollCallbackInterface | 107 // From EpollCallbackInterface |
108 virtual void OnRegistration(EpollServer* eps, | 108 void OnRegistration(EpollServer* eps, int fd, int event_mask) override {} |
109 int fd, | 109 void OnModification(int fd, int event_mask) override {} |
110 int event_mask) override {} | 110 void OnEvent(int fd, EpollEvent* event) override; |
111 virtual void OnModification(int fd, int event_mask) override {} | |
112 virtual void OnEvent(int fd, EpollEvent* event) override; | |
113 // |fd_| can be unregistered without the client being disconnected. This | 111 // |fd_| can be unregistered without the client being disconnected. This |
114 // happens in b3m QuicProber where we unregister |fd_| to feed in events to | 112 // happens in b3m QuicProber where we unregister |fd_| to feed in events to |
115 // the client from the SelectServer. | 113 // the client from the SelectServer. |
116 virtual void OnUnregistration(int fd, bool replaced) override {} | 114 void OnUnregistration(int fd, bool replaced) override {} |
117 virtual void OnShutdown(EpollServer* eps, int fd) override {} | 115 void OnShutdown(EpollServer* eps, int fd) override {} |
118 | 116 |
119 // QuicDataStream::Visitor | 117 // QuicDataStream::Visitor |
120 virtual void OnClose(QuicDataStream* stream) override; | 118 void OnClose(QuicDataStream* stream) override; |
121 | 119 |
122 QuicClientSession* session() { return session_.get(); } | 120 QuicClientSession* session() { return session_.get(); } |
123 | 121 |
124 bool connected() const; | 122 bool connected() const; |
125 | 123 |
126 void set_bind_to_address(IPAddressNumber address) { | 124 void set_bind_to_address(IPAddressNumber address) { |
127 bind_to_address_ = address; | 125 bind_to_address_ = address; |
128 } | 126 } |
129 | 127 |
130 IPAddressNumber bind_to_address() const { return bind_to_address_; } | 128 IPAddressNumber bind_to_address() const { return bind_to_address_; } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 EpollServer* epoll_server() { return epoll_server_; } | 183 EpollServer* epoll_server() { return epoll_server_; } |
186 QuicConfig* config() { return &config_; } | 184 QuicConfig* config() { return &config_; } |
187 | 185 |
188 private: | 186 private: |
189 friend class net::tools::test::QuicClientPeer; | 187 friend class net::tools::test::QuicClientPeer; |
190 | 188 |
191 // A packet writer factory that always returns the same writer | 189 // A packet writer factory that always returns the same writer |
192 class DummyPacketWriterFactory : public QuicConnection::PacketWriterFactory { | 190 class DummyPacketWriterFactory : public QuicConnection::PacketWriterFactory { |
193 public: | 191 public: |
194 DummyPacketWriterFactory(QuicPacketWriter* writer); | 192 DummyPacketWriterFactory(QuicPacketWriter* writer); |
195 virtual ~DummyPacketWriterFactory(); | 193 ~DummyPacketWriterFactory() override; |
196 | 194 |
197 virtual QuicPacketWriter* Create(QuicConnection* connection) const override; | 195 QuicPacketWriter* Create(QuicConnection* connection) const override; |
198 | 196 |
199 private: | 197 private: |
200 QuicPacketWriter* writer_; | 198 QuicPacketWriter* writer_; |
201 }; | 199 }; |
202 | 200 |
203 // Used during initialization: creates the UDP socket FD, sets socket options, | 201 // Used during initialization: creates the UDP socket FD, sets socket options, |
204 // and binds the socket to our address. | 202 // and binds the socket to our address. |
205 bool CreateUDPSocket(); | 203 bool CreateUDPSocket(); |
206 | 204 |
207 // Read a UDP packet and hand it to the framer. | 205 // Read a UDP packet and hand it to the framer. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // when the stream is closed (in OnClose). | 264 // when the stream is closed (in OnClose). |
267 bool print_response_; | 265 bool print_response_; |
268 | 266 |
269 DISALLOW_COPY_AND_ASSIGN(QuicClient); | 267 DISALLOW_COPY_AND_ASSIGN(QuicClient); |
270 }; | 268 }; |
271 | 269 |
272 } // namespace tools | 270 } // namespace tools |
273 } // namespace net | 271 } // namespace net |
274 | 272 |
275 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ | 273 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ |
OLD | NEW |