Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: net/tools/quic/quic_client.cc

Issue 1752823002: n/a (QUIC toy client/server changes) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@115400573
Patch Set: Revert to Patch Set 1 Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/quic_client.h ('k') | net/tools/quic/quic_client_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 config()->SetInitialStreamFlowControlWindowToSend(kStreamMaxRecvWindowSize); 102 config()->SetInitialStreamFlowControlWindowToSend(kStreamMaxRecvWindowSize);
103 } 103 }
104 if (config()->GetInitialSessionFlowControlWindowToSend() == 104 if (config()->GetInitialSessionFlowControlWindowToSend() ==
105 kMinimumFlowControlSendWindow) { 105 kMinimumFlowControlSendWindow) {
106 config()->SetInitialSessionFlowControlWindowToSend( 106 config()->SetInitialSessionFlowControlWindowToSend(
107 kSessionMaxRecvWindowSize); 107 kSessionMaxRecvWindowSize);
108 } 108 }
109 109
110 epoll_server_->set_timeout_in_us(50 * 1000); 110 epoll_server_->set_timeout_in_us(50 * 1000);
111 111
112 if (!CreateUDPSocket()) { 112 if (!CreateUDPSocketAndBind()) {
113 return false; 113 return false;
114 } 114 }
115 115
116 epoll_server_->RegisterFD(GetLatestFD(), this, kEpollFlags); 116 epoll_server_->RegisterFD(GetLatestFD(), this, kEpollFlags);
117 initialized_ = true; 117 initialized_ = true;
118 return true; 118 return true;
119 } 119 }
120 120
121 QuicClient::QuicDataToResend::QuicDataToResend(BalsaHeaders* headers, 121 QuicClient::QuicDataToResend::QuicDataToResend(BalsaHeaders* headers,
122 StringPiece body, 122 StringPiece body,
123 bool fin) 123 bool fin)
124 : headers_(headers), body_(body), fin_(fin) {} 124 : headers_(headers), body_(body), fin_(fin) {}
125 125
126 QuicClient::QuicDataToResend::~QuicDataToResend() { 126 QuicClient::QuicDataToResend::~QuicDataToResend() {
127 if (headers_) { 127 if (headers_) {
128 delete headers_; 128 delete headers_;
129 } 129 }
130 } 130 }
131 131
132 bool QuicClient::CreateUDPSocket() { 132 bool QuicClient::CreateUDPSocketAndBind() {
133 int address_family = server_address_.GetSockAddrFamily(); 133 int fd =
134 int fd = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); 134 QuicSocketUtils::CreateUDPSocket(server_address_, &overflow_supported_);
135 if (fd < 0) { 135 if (fd < 0) {
136 LOG(ERROR) << "CreateSocket() failed: " << strerror(errno);
137 return false;
138 }
139
140 int get_overflow = 1;
141 int rc = setsockopt(fd, SOL_SOCKET, SO_RXQ_OVFL, &get_overflow,
142 sizeof(get_overflow));
143 if (rc < 0) {
144 DLOG(WARNING) << "Socket overflow detection not supported";
145 } else {
146 overflow_supported_ = true;
147 }
148
149 if (!QuicSocketUtils::SetReceiveBufferSize(fd, kDefaultSocketReceiveBuffer)) {
150 return false;
151 }
152
153 if (!QuicSocketUtils::SetSendBufferSize(fd, kDefaultSocketReceiveBuffer)) {
154 return false;
155 }
156
157 rc = QuicSocketUtils::SetGetAddressInfo(fd, address_family);
158 if (rc < 0) {
159 LOG(ERROR) << "IP detection not supported" << strerror(errno);
160 return false; 136 return false;
161 } 137 }
162 138
163 IPEndPoint client_address; 139 IPEndPoint client_address;
164 if (bind_to_address_.size() != 0) { 140 if (bind_to_address_.size() != 0) {
165 client_address = IPEndPoint(bind_to_address_, local_port_); 141 client_address = IPEndPoint(bind_to_address_, local_port_);
166 } else if (address_family == AF_INET) { 142 } else if (server_address_.GetSockAddrFamily() == AF_INET) {
167 client_address = IPEndPoint(IPAddress(0, 0, 0, 0), local_port_); 143 client_address = IPEndPoint(IPAddress(0, 0, 0, 0), local_port_);
168 } else { 144 } else {
169 IPAddress any6; 145 IPAddress any6;
170 CHECK(any6.AssignFromIPLiteral("::")); 146 CHECK(any6.AssignFromIPLiteral("::"));
171 client_address = IPEndPoint(any6, local_port_); 147 client_address = IPEndPoint(any6, local_port_);
172 } 148 }
173 149
174 sockaddr_storage raw_addr; 150 sockaddr_storage raw_addr;
175 socklen_t raw_addr_len = sizeof(raw_addr); 151 socklen_t raw_addr_len = sizeof(raw_addr);
176 CHECK(client_address.ToSockAddr(reinterpret_cast<sockaddr*>(&raw_addr), 152 CHECK(client_address.ToSockAddr(reinterpret_cast<sockaddr*>(&raw_addr),
177 &raw_addr_len)); 153 &raw_addr_len));
178 rc = bind(fd, reinterpret_cast<const sockaddr*>(&raw_addr), sizeof(raw_addr)); 154 int rc =
155 bind(fd, reinterpret_cast<const sockaddr*>(&raw_addr), sizeof(raw_addr));
179 if (rc < 0) { 156 if (rc < 0) {
180 LOG(ERROR) << "Bind failed: " << strerror(errno); 157 LOG(ERROR) << "Bind failed: " << strerror(errno);
181 return false; 158 return false;
182 } 159 }
183 160
184 SockaddrStorage storage; 161 SockaddrStorage storage;
185 if (getsockname(fd, storage.addr, &storage.addr_len) != 0 || 162 if (getsockname(fd, storage.addr, &storage.addr_len) != 0 ||
186 !client_address.FromSockAddr(storage.addr, storage.addr_len)) { 163 !client_address.FromSockAddr(storage.addr, storage.addr_len)) {
187 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno); 164 LOG(ERROR) << "Unable to get self address. Error: " << strerror(errno);
188 } 165 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 360 }
384 361
385 bool QuicClient::MigrateSocket(const IPAddress& new_host) { 362 bool QuicClient::MigrateSocket(const IPAddress& new_host) {
386 if (!connected()) { 363 if (!connected()) {
387 return false; 364 return false;
388 } 365 }
389 366
390 CleanUpUDPSocket(GetLatestFD()); 367 CleanUpUDPSocket(GetLatestFD());
391 368
392 bind_to_address_ = new_host; 369 bind_to_address_ = new_host;
393 if (!CreateUDPSocket()) { 370 if (!CreateUDPSocketAndBind()) {
394 return false; 371 return false;
395 } 372 }
396 373
397 epoll_server_->RegisterFD(GetLatestFD(), this, kEpollFlags); 374 epoll_server_->RegisterFD(GetLatestFD(), this, kEpollFlags);
398 session()->connection()->SetSelfAddress(GetLatestClientAddress()); 375 session()->connection()->SetSelfAddress(GetLatestClientAddress());
399 376
400 QuicPacketWriter* writer = CreateQuicPacketWriter(); 377 QuicPacketWriter* writer = CreateQuicPacketWriter();
401 set_writer(writer); 378 set_writer(writer);
402 session()->connection()->SetQuicPacketWriter(writer, false); 379 session()->connection()->SetQuicPacketWriter(writer, false);
403 380
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 return fd_address_map_.back().first; 525 return fd_address_map_.back().first;
549 } 526 }
550 527
551 void QuicClient::ProcessPacket(const IPEndPoint& self_address, 528 void QuicClient::ProcessPacket(const IPEndPoint& self_address,
552 const IPEndPoint& peer_address, 529 const IPEndPoint& peer_address,
553 const QuicEncryptedPacket& packet) { 530 const QuicEncryptedPacket& packet) {
554 session()->connection()->ProcessUdpPacket(self_address, peer_address, packet); 531 session()->connection()->ProcessUdpPacket(self_address, peer_address, packet);
555 } 532 }
556 533
557 } // namespace net 534 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_client.h ('k') | net/tools/quic/quic_client_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698