| 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> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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 |
| 33 QuicClient::QuicClient(IPEndPoint server_address, | 33 QuicClient::QuicClient(IPEndPoint server_address, |
| 34 const string& server_hostname, | 34 const string& server_hostname, |
| 35 const QuicVersion version) | 35 const QuicVersion version, |
| 36 bool print_response) |
| 36 : server_address_(server_address), | 37 : server_address_(server_address), |
| 37 server_hostname_(server_hostname), | 38 server_hostname_(server_hostname), |
| 38 local_port_(0), | 39 local_port_(0), |
| 39 fd_(-1), | 40 fd_(-1), |
| 40 initialized_(false), | 41 initialized_(false), |
| 41 packets_dropped_(0), | 42 packets_dropped_(0), |
| 42 overflow_supported_(false), | 43 overflow_supported_(false), |
| 43 version_(version) { | 44 version_(version), |
| 45 print_response_(print_response) { |
| 44 config_.SetDefaults(); | 46 config_.SetDefaults(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 QuicClient::QuicClient(IPEndPoint server_address, | 49 QuicClient::QuicClient(IPEndPoint server_address, |
| 48 const string& server_hostname, | 50 const string& server_hostname, |
| 49 const QuicConfig& config, | 51 const QuicConfig& config, |
| 50 const QuicVersion version) | 52 const QuicVersion version) |
| 51 : server_address_(server_address), | 53 : server_address_(server_address), |
| 52 server_hostname_(server_hostname), | 54 server_hostname_(server_hostname), |
| 53 config_(config), | 55 config_(config), |
| 54 local_port_(0), | 56 local_port_(0), |
| 55 fd_(-1), | 57 fd_(-1), |
| 56 initialized_(false), | 58 initialized_(false), |
| 57 packets_dropped_(0), | 59 packets_dropped_(0), |
| 58 overflow_supported_(false), | 60 overflow_supported_(false), |
| 59 version_(version) { | 61 version_(version), |
| 62 print_response_(false) { |
| 60 } | 63 } |
| 61 | 64 |
| 62 QuicClient::~QuicClient() { | 65 QuicClient::~QuicClient() { |
| 63 if (connected()) { | 66 if (connected()) { |
| 64 session()->connection()->SendConnectionClosePacket( | 67 session()->connection()->SendConnectionClosePacket( |
| 65 QUIC_PEER_GOING_AWAY, ""); | 68 QUIC_PEER_GOING_AWAY, ""); |
| 66 } | 69 } |
| 67 } | 70 } |
| 68 | 71 |
| 69 bool QuicClient::Initialize() { | 72 bool QuicClient::Initialize() { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 174 |
| 172 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); | 175 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); |
| 173 epoll_server_.UnregisterFD(fd_); | 176 epoll_server_.UnregisterFD(fd_); |
| 174 close(fd_); | 177 close(fd_); |
| 175 fd_ = -1; | 178 fd_ = -1; |
| 176 initialized_ = false; | 179 initialized_ = false; |
| 177 } | 180 } |
| 178 | 181 |
| 179 void QuicClient::SendRequestsAndWaitForResponse( | 182 void QuicClient::SendRequestsAndWaitForResponse( |
| 180 const CommandLine::StringVector& args) { | 183 const CommandLine::StringVector& args) { |
| 181 for (uint32_t i = 0; i < args.size(); i++) { | 184 for (size_t i = 0; i < args.size(); i++) { |
| 182 BalsaHeaders headers; | 185 BalsaHeaders headers; |
| 183 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); | 186 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); |
| 184 CreateReliableClientStream()->SendRequest(headers, "", true); | 187 QuicReliableClientStream* stream = CreateReliableClientStream(); |
| 188 stream->SendRequest(headers, "", true); |
| 189 stream->set_visitor(this); |
| 185 } | 190 } |
| 186 | 191 |
| 187 while (WaitForEvents()) { } | 192 while (WaitForEvents()) { } |
| 188 } | 193 } |
| 189 | 194 |
| 190 QuicReliableClientStream* QuicClient::CreateReliableClientStream() { | 195 QuicReliableClientStream* QuicClient::CreateReliableClientStream() { |
| 191 if (!connected()) { | 196 if (!connected()) { |
| 192 return NULL; | 197 return NULL; |
| 193 } | 198 } |
| 194 | 199 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 231 } |
| 227 } | 232 } |
| 228 if (connected() && (event->in_events & EPOLLOUT)) { | 233 if (connected() && (event->in_events & EPOLLOUT)) { |
| 229 session_->connection()->OnCanWrite(); | 234 session_->connection()->OnCanWrite(); |
| 230 } | 235 } |
| 231 if (event->in_events & EPOLLERR) { | 236 if (event->in_events & EPOLLERR) { |
| 232 DLOG(INFO) << "Epollerr"; | 237 DLOG(INFO) << "Epollerr"; |
| 233 } | 238 } |
| 234 } | 239 } |
| 235 | 240 |
| 241 void QuicClient::OnClose(ReliableQuicStream* stream) { |
| 242 if (!print_response_) { |
| 243 return; |
| 244 } |
| 245 |
| 246 QuicReliableClientStream* client_stream = |
| 247 static_cast<QuicReliableClientStream*>(stream); |
| 248 const BalsaHeaders& headers = client_stream->headers(); |
| 249 printf("%s\n", headers.first_line().as_string().c_str()); |
| 250 for (BalsaHeaders::const_header_lines_iterator i = |
| 251 headers.header_lines_begin(); |
| 252 i != headers.header_lines_end(); ++i) { |
| 253 printf("%s: %s\n", i->first.as_string().c_str(), |
| 254 i->second.as_string().c_str()); |
| 255 } |
| 256 printf("%s\n", client_stream->data().c_str()); |
| 257 } |
| 258 |
| 236 QuicPacketCreator::Options* QuicClient::options() { | 259 QuicPacketCreator::Options* QuicClient::options() { |
| 237 if (session() == NULL) { | 260 if (session() == NULL) { |
| 238 return NULL; | 261 return NULL; |
| 239 } | 262 } |
| 240 return session_->options(); | 263 return session_->options(); |
| 241 } | 264 } |
| 242 | 265 |
| 243 bool QuicClient::connected() const { | 266 bool QuicClient::connected() const { |
| 244 return session_.get() && session_->connection() && | 267 return session_.get() && session_->connection() && |
| 245 session_->connection()->connected(); | 268 session_->connection()->connected(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 303 } |
| 281 | 304 |
| 282 IPEndPoint client_address(client_ip, client_address_.port()); | 305 IPEndPoint client_address(client_ip, client_address_.port()); |
| 283 session_->connection()->ProcessUdpPacket( | 306 session_->connection()->ProcessUdpPacket( |
| 284 client_address, server_address, packet); | 307 client_address, server_address, packet); |
| 285 return true; | 308 return true; |
| 286 } | 309 } |
| 287 | 310 |
| 288 } // namespace tools | 311 } // namespace tools |
| 289 } // namespace net | 312 } // namespace net |
| OLD | NEW |