| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 fd_ = -1; | 228 fd_ = -1; |
| 229 initialized_ = false; | 229 initialized_ = false; |
| 230 } | 230 } |
| 231 | 231 |
| 232 void QuicClient::SendRequestsAndWaitForResponse( | 232 void QuicClient::SendRequestsAndWaitForResponse( |
| 233 const base::CommandLine::StringVector& args) { | 233 const base::CommandLine::StringVector& args) { |
| 234 for (size_t i = 0; i < args.size(); ++i) { | 234 for (size_t i = 0; i < args.size(); ++i) { |
| 235 BalsaHeaders headers; | 235 BalsaHeaders headers; |
| 236 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); | 236 headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1"); |
| 237 QuicSpdyClientStream* stream = CreateReliableClientStream(); | 237 QuicSpdyClientStream* stream = CreateReliableClientStream(); |
| 238 DCHECK(stream != NULL); | 238 DCHECK(stream != nullptr); |
| 239 stream->SendRequest(headers, "", true); | 239 stream->SendRequest(headers, "", true); |
| 240 stream->set_visitor(this); | 240 stream->set_visitor(this); |
| 241 } | 241 } |
| 242 | 242 |
| 243 while (WaitForEvents()) {} | 243 while (WaitForEvents()) {} |
| 244 } | 244 } |
| 245 | 245 |
| 246 QuicSpdyClientStream* QuicClient::CreateReliableClientStream() { | 246 QuicSpdyClientStream* QuicClient::CreateReliableClientStream() { |
| 247 if (!connected()) { | 247 if (!connected()) { |
| 248 return NULL; | 248 return nullptr; |
| 249 } | 249 } |
| 250 | 250 |
| 251 return session_->CreateOutgoingDataStream(); | 251 return session_->CreateOutgoingDataStream(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void QuicClient::WaitForStreamToClose(QuicStreamId id) { | 254 void QuicClient::WaitForStreamToClose(QuicStreamId id) { |
| 255 DCHECK(connected()); | 255 DCHECK(connected()); |
| 256 | 256 |
| 257 while (connected() && !session_->IsClosedStream(id)) { | 257 while (connected() && !session_->IsClosedStream(id)) { |
| 258 epoll_server_->WaitForEventsAndExecuteCallbacks(); | 258 epoll_server_->WaitForEventsAndExecuteCallbacks(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 286 session_->connection()->OnCanWrite(); | 286 session_->connection()->OnCanWrite(); |
| 287 } | 287 } |
| 288 if (event->in_events & EPOLLERR) { | 288 if (event->in_events & EPOLLERR) { |
| 289 DVLOG(1) << "Epollerr"; | 289 DVLOG(1) << "Epollerr"; |
| 290 } | 290 } |
| 291 } | 291 } |
| 292 | 292 |
| 293 void QuicClient::OnClose(QuicDataStream* stream) { | 293 void QuicClient::OnClose(QuicDataStream* stream) { |
| 294 QuicSpdyClientStream* client_stream = | 294 QuicSpdyClientStream* client_stream = |
| 295 static_cast<QuicSpdyClientStream*>(stream); | 295 static_cast<QuicSpdyClientStream*>(stream); |
| 296 if (response_listener_.get() != NULL) { | 296 if (response_listener_.get() != nullptr) { |
| 297 response_listener_->OnCompleteResponse( | 297 response_listener_->OnCompleteResponse( |
| 298 stream->id(), client_stream->headers(), client_stream->data()); | 298 stream->id(), client_stream->headers(), client_stream->data()); |
| 299 } | 299 } |
| 300 | 300 |
| 301 if (!print_response_) { | 301 if (!print_response_) { |
| 302 return; | 302 return; |
| 303 } | 303 } |
| 304 | 304 |
| 305 const BalsaHeaders& headers = client_stream->headers(); | 305 const BalsaHeaders& headers = client_stream->headers(); |
| 306 printf("%s\n", headers.first_line().as_string().c_str()); | 306 printf("%s\n", headers.first_line().as_string().c_str()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 328 | 328 |
| 329 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { | 329 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { |
| 330 return new QuicDefaultPacketWriter(fd_); | 330 return new QuicDefaultPacketWriter(fd_); |
| 331 } | 331 } |
| 332 | 332 |
| 333 int QuicClient::ReadPacket(char* buffer, | 333 int QuicClient::ReadPacket(char* buffer, |
| 334 int buffer_len, | 334 int buffer_len, |
| 335 IPEndPoint* server_address, | 335 IPEndPoint* server_address, |
| 336 IPAddressNumber* client_ip) { | 336 IPAddressNumber* client_ip) { |
| 337 return QuicSocketUtils::ReadPacket( | 337 return QuicSocketUtils::ReadPacket( |
| 338 fd_, buffer, buffer_len, overflow_supported_ ? &packets_dropped_ : NULL, | 338 fd_, buffer, buffer_len, |
| 339 client_ip, server_address); | 339 overflow_supported_ ? &packets_dropped_ : nullptr, client_ip, |
| 340 server_address); |
| 340 } | 341 } |
| 341 | 342 |
| 342 bool QuicClient::ReadAndProcessPacket() { | 343 bool QuicClient::ReadAndProcessPacket() { |
| 343 // Allocate some extra space so we can send an error if the server goes over | 344 // Allocate some extra space so we can send an error if the server goes over |
| 344 // the limit. | 345 // the limit. |
| 345 char buf[2 * kMaxPacketSize]; | 346 char buf[2 * kMaxPacketSize]; |
| 346 | 347 |
| 347 IPEndPoint server_address; | 348 IPEndPoint server_address; |
| 348 IPAddressNumber client_ip; | 349 IPAddressNumber client_ip; |
| 349 | 350 |
| 350 int bytes_read = ReadPacket(buf, arraysize(buf), &server_address, &client_ip); | 351 int bytes_read = ReadPacket(buf, arraysize(buf), &server_address, &client_ip); |
| 351 | 352 |
| 352 if (bytes_read < 0) { | 353 if (bytes_read < 0) { |
| 353 return false; | 354 return false; |
| 354 } | 355 } |
| 355 | 356 |
| 356 QuicEncryptedPacket packet(buf, bytes_read, false); | 357 QuicEncryptedPacket packet(buf, bytes_read, false); |
| 357 | 358 |
| 358 IPEndPoint client_address(client_ip, client_address_.port()); | 359 IPEndPoint client_address(client_ip, client_address_.port()); |
| 359 session_->connection()->ProcessUdpPacket( | 360 session_->connection()->ProcessUdpPacket( |
| 360 client_address, server_address, packet); | 361 client_address, server_address, packet); |
| 361 return true; | 362 return true; |
| 362 } | 363 } |
| 363 | 364 |
| 364 } // namespace tools | 365 } // namespace tools |
| 365 } // namespace net | 366 } // namespace net |
| OLD | NEW |