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

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

Issue 467963002: Refactoring: Create per-connection packet writers in QuicDispatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation Created 6 years, 4 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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 if (!CreateUDPSocket()) { 91 if (!CreateUDPSocket()) {
92 return false; 92 return false;
93 } 93 }
94 94
95 epoll_server_->RegisterFD(fd_, this, kEpollFlags); 95 epoll_server_->RegisterFD(fd_, this, kEpollFlags);
96 initialized_ = true; 96 initialized_ = true;
97 return true; 97 return true;
98 } 98 }
99 99
100 QuicClient::DummyPacketWriterFactory::DummyPacketWriterFactory(
101 QuicPacketWriter* writer)
102 : writer_(writer) {}
103
104 QuicClient::DummyPacketWriterFactory::~DummyPacketWriterFactory() {}
105
106 QuicPacketWriter* QuicClient::DummyPacketWriterFactory::Create(
107 QuicConnection* /*connection*/) const {
108 return writer_;
109 }
110
111
100 bool QuicClient::CreateUDPSocket() { 112 bool QuicClient::CreateUDPSocket() {
101 int address_family = server_address_.GetSockAddrFamily(); 113 int address_family = server_address_.GetSockAddrFamily();
102 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP); 114 fd_ = socket(address_family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
103 if (fd_ < 0) { 115 if (fd_ < 0) {
104 LOG(ERROR) << "CreateSocket() failed: " << strerror(errno); 116 LOG(ERROR) << "CreateSocket() failed: " << strerror(errno);
105 return false; 117 return false;
106 } 118 }
107 119
108 int get_overflow = 1; 120 int get_overflow = 1;
109 int rc = setsockopt(fd_, SOL_SOCKET, SO_RXQ_OVFL, &get_overflow, 121 int rc = setsockopt(fd_, SOL_SOCKET, SO_RXQ_OVFL, &get_overflow,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 184 }
173 return session_->connection()->connected(); 185 return session_->connection()->connected();
174 } 186 }
175 187
176 bool QuicClient::StartConnect() { 188 bool QuicClient::StartConnect() {
177 DCHECK(initialized_); 189 DCHECK(initialized_);
178 DCHECK(!connected()); 190 DCHECK(!connected());
179 191
180 QuicPacketWriter* writer = CreateQuicPacketWriter(); 192 QuicPacketWriter* writer = CreateQuicPacketWriter();
181 193
194 DummyPacketWriterFactory factory(writer);
195
182 session_.reset(new QuicClientSession( 196 session_.reset(new QuicClientSession(
183 config_, 197 config_,
184 new QuicConnection(GenerateConnectionId(), 198 new QuicConnection(GenerateConnectionId(),
185 server_address_, 199 server_address_,
186 helper_.get(), 200 helper_.get(),
187 writer, 201 factory,
188 false /* owns_writer */, 202 /* owns_writer= */ false,
189 false /* is_server */, 203 /* is_server= */ false,
190 supported_versions_))); 204 supported_versions_)));
205
191 // Reset |writer_| after |session_| so that the old writer outlives the old 206 // Reset |writer_| after |session_| so that the old writer outlives the old
192 // session. 207 // session.
193 if (writer_.get() != writer) { 208 if (writer_.get() != writer) {
194 writer_.reset(writer); 209 writer_.reset(writer);
195 } 210 }
196 session_->InitializeSession(server_id_, &crypto_config_); 211 session_->InitializeSession(server_id_, &crypto_config_);
197 return session_->CryptoConnect(); 212 return session_->CryptoConnect();
198 } 213 }
199 214
200 bool QuicClient::EncryptionBeingEstablished() { 215 bool QuicClient::EncryptionBeingEstablished() {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 QuicEncryptedPacket packet(buf, bytes_read, false); 356 QuicEncryptedPacket packet(buf, bytes_read, false);
342 357
343 IPEndPoint client_address(client_ip, client_address_.port()); 358 IPEndPoint client_address(client_ip, client_address_.port());
344 session_->connection()->ProcessUdpPacket( 359 session_->connection()->ProcessUdpPacket(
345 client_address, server_address, packet); 360 client_address, server_address, packet);
346 return true; 361 return true;
347 } 362 }
348 363
349 } // namespace tools 364 } // namespace tools
350 } // namespace net 365 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698