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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 | 57 |
58 QuicClient::~QuicClient() { | 58 QuicClient::~QuicClient() { |
59 if (connected()) { | 59 if (connected()) { |
60 session()->connection() | 60 session()->connection() |
61 ->SendConnectionClosePacket(QUIC_PEER_GOING_AWAY, std::string()); | 61 ->SendConnectionClosePacket(QUIC_PEER_GOING_AWAY, std::string()); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 bool QuicClient::Initialize() { | 65 bool QuicClient::Initialize() { |
| 66 DCHECK(!initialized_); |
| 67 |
66 epoll_server_.set_timeout_in_us(50 * 1000); | 68 epoll_server_.set_timeout_in_us(50 * 1000); |
67 crypto_config_.SetDefaults(); | 69 crypto_config_.SetDefaults(); |
68 int address_family = server_address_.GetSockAddrFamily(); | 70 int address_family = server_address_.GetSockAddrFamily(); |
69 | 71 |
70 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); | 72 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); |
71 if (fd_ < 0) { | 73 if (fd_ < 0) { |
72 LOG(ERROR) << "CreateSocket() failed: " << strerror(errno); | 74 LOG(ERROR) << "CreateSocket() failed: " << strerror(errno); |
73 return false; | 75 return false; |
74 } | 76 } |
75 | 77 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 session_->connection()->connected(); | 162 session_->connection()->connected(); |
161 } | 163 } |
162 | 164 |
163 void QuicClient::Disconnect() { | 165 void QuicClient::Disconnect() { |
164 DCHECK(connected()); | 166 DCHECK(connected()); |
165 | 167 |
166 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); | 168 session()->connection()->SendConnectionClose(QUIC_PEER_GOING_AWAY); |
167 epoll_server_.UnregisterFD(fd_); | 169 epoll_server_.UnregisterFD(fd_); |
168 close(fd_); | 170 close(fd_); |
169 fd_ = -1; | 171 fd_ = -1; |
| 172 initialized_ = false; |
170 } | 173 } |
171 | 174 |
172 void QuicClient::SendRequestsAndWaitForResponse(int argc, char *argv[]) { | 175 void QuicClient::SendRequestsAndWaitForResponse(int argc, char *argv[]) { |
173 for (int i = 1; i < argc; ++i) { | 176 for (int i = 1; i < argc; ++i) { |
174 BalsaHeaders headers; | 177 BalsaHeaders headers; |
175 headers.SetRequestFirstlineFromStringPieces("GET", argv[i], "HTTP/1.1"); | 178 headers.SetRequestFirstlineFromStringPieces("GET", argv[i], "HTTP/1.1"); |
176 CreateReliableClientStream()->SendRequest(headers, "", true); | 179 CreateReliableClientStream()->SendRequest(headers, "", true); |
177 } | 180 } |
178 | 181 |
179 while (WaitForEvents()) { } | 182 while (WaitForEvents()) { } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 } | 261 } |
259 | 262 |
260 IPEndPoint client_address(client_ip, client_address_.port()); | 263 IPEndPoint client_address(client_ip, client_address_.port()); |
261 session_->connection()->ProcessUdpPacket( | 264 session_->connection()->ProcessUdpPacket( |
262 client_address, server_address, packet); | 265 client_address, server_address, packet); |
263 return true; | 266 return true; |
264 } | 267 } |
265 | 268 |
266 } // namespace tools | 269 } // namespace tools |
267 } // namespace net | 270 } // namespace net |
OLD | NEW |