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/epoll.h> | 10 #include <sys/epoll.h> |
11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "net/quic/crypto/quic_random.h" | 15 #include "net/quic/crypto/quic_random.h" |
16 #include "net/quic/quic_connection.h" | 16 #include "net/quic/quic_connection.h" |
17 #include "net/quic/quic_data_reader.h" | 17 #include "net/quic/quic_data_reader.h" |
18 #include "net/quic/quic_protocol.h" | 18 #include "net/quic/quic_protocol.h" |
19 #include "net/tools/balsa/balsa_headers.h" | 19 #include "net/tools/balsa/balsa_headers.h" |
20 #include "net/tools/quic/quic_epoll_connection_helper.h" | 20 #include "net/tools/quic/quic_epoll_connection_helper.h" |
21 #include "net/tools/quic/quic_reliable_client_stream.h" | |
22 #include "net/tools/quic/quic_socket_utils.h" | 21 #include "net/tools/quic/quic_socket_utils.h" |
| 22 #include "net/tools/quic/quic_spdy_client_stream.h" |
23 | 23 |
24 #ifndef SO_RXQ_OVFL | 24 #ifndef SO_RXQ_OVFL |
25 #define SO_RXQ_OVFL 40 | 25 #define SO_RXQ_OVFL 40 |
26 #endif | 26 #endif |
27 | 27 |
28 namespace net { | 28 namespace net { |
29 namespace tools { | 29 namespace tools { |
30 | 30 |
31 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; | 31 const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET; |
32 | 32 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); | 181 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); |
182 } | 182 } |
183 epoll_server_.UnregisterFD(fd_); | 183 epoll_server_.UnregisterFD(fd_); |
184 close(fd_); | 184 close(fd_); |
185 fd_ = -1; | 185 fd_ = -1; |
186 initialized_ = false; | 186 initialized_ = false; |
187 } | 187 } |
188 | 188 |
189 void QuicClient::SendRequestsAndWaitForResponse( | 189 void QuicClient::SendRequestsAndWaitForResponse( |
190 const CommandLine::StringVector& args) { | 190 const CommandLine::StringVector& args) { |
191 for (size_t i = 0; i < args.size(); i++) { | 191 for (size_t i = 0; i < args.size(); ++i) { |
192 BalsaHeaders headers; | 192 BalsaHeaders headers; |
193 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); | 193 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); |
194 QuicReliableClientStream* stream = CreateReliableClientStream(); | 194 QuicSpdyClientStream* stream = CreateReliableClientStream(); |
195 stream->SendRequest(headers, "", true); | 195 stream->SendRequest(headers, "", true); |
196 stream->set_visitor(this); | 196 stream->set_visitor(this); |
197 } | 197 } |
198 | 198 |
199 while (WaitForEvents()) { } | 199 while (WaitForEvents()) { } |
200 } | 200 } |
201 | 201 |
202 QuicReliableClientStream* QuicClient::CreateReliableClientStream() { | 202 QuicSpdyClientStream* QuicClient::CreateReliableClientStream() { |
203 if (!connected()) { | 203 if (!connected()) { |
204 return NULL; | 204 return NULL; |
205 } | 205 } |
206 | 206 |
207 return session_->CreateOutgoingReliableStream(); | 207 return session_->CreateOutgoingDataStream(); |
208 } | 208 } |
209 | 209 |
210 void QuicClient::WaitForStreamToClose(QuicStreamId id) { | 210 void QuicClient::WaitForStreamToClose(QuicStreamId id) { |
211 DCHECK(connected()); | 211 DCHECK(connected()); |
212 | 212 |
213 while (!session_->IsClosedStream(id)) { | 213 while (!session_->IsClosedStream(id)) { |
214 epoll_server_.WaitForEventsAndExecuteCallbacks(); | 214 epoll_server_.WaitForEventsAndExecuteCallbacks(); |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
(...skipping 20 matching lines...) Expand all Loading... |
238 } | 238 } |
239 } | 239 } |
240 if (connected() && (event->in_events & EPOLLOUT)) { | 240 if (connected() && (event->in_events & EPOLLOUT)) { |
241 session_->connection()->OnCanWrite(); | 241 session_->connection()->OnCanWrite(); |
242 } | 242 } |
243 if (event->in_events & EPOLLERR) { | 243 if (event->in_events & EPOLLERR) { |
244 DLOG(INFO) << "Epollerr"; | 244 DLOG(INFO) << "Epollerr"; |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 void QuicClient::OnClose(ReliableQuicStream* stream) { | 248 void QuicClient::OnClose(QuicDataStream* stream) { |
249 if (!print_response_) { | 249 if (!print_response_) { |
250 return; | 250 return; |
251 } | 251 } |
252 | 252 |
253 QuicReliableClientStream* client_stream = | 253 QuicSpdyClientStream* client_stream = |
254 static_cast<QuicReliableClientStream*>(stream); | 254 static_cast<QuicSpdyClientStream*>(stream); |
255 const BalsaHeaders& headers = client_stream->headers(); | 255 const BalsaHeaders& headers = client_stream->headers(); |
256 printf("%s\n", headers.first_line().as_string().c_str()); | 256 printf("%s\n", headers.first_line().as_string().c_str()); |
257 for (BalsaHeaders::const_header_lines_iterator i = | 257 for (BalsaHeaders::const_header_lines_iterator i = |
258 headers.header_lines_begin(); | 258 headers.header_lines_begin(); |
259 i != headers.header_lines_end(); ++i) { | 259 i != headers.header_lines_end(); ++i) { |
260 printf("%s: %s\n", i->first.as_string().c_str(), | 260 printf("%s: %s\n", i->first.as_string().c_str(), |
261 i->second.as_string().c_str()); | 261 i->second.as_string().c_str()); |
262 } | 262 } |
263 printf("%s\n", client_stream->data().c_str()); | 263 printf("%s\n", client_stream->data().c_str()); |
264 } | 264 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 318 } |
319 | 319 |
320 IPEndPoint client_address(client_ip, client_address_.port()); | 320 IPEndPoint client_address(client_ip, client_address_.port()); |
321 session_->connection()->ProcessUdpPacket( | 321 session_->connection()->ProcessUdpPacket( |
322 client_address, server_address, packet); | 322 client_address, server_address, packet); |
323 return true; | 323 return true; |
324 } | 324 } |
325 | 325 |
326 } // namespace tools | 326 } // namespace tools |
327 } // namespace net | 327 } // namespace net |
OLD | NEW |