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

Side by Side Diff: webrtc/p2p/base/tcpport.cc

Issue 2936553003: Adding PortAllocator option to support cases where sockets can't be bound. (Closed)
Patch Set: Created 3 years, 6 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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 min_port, 89 min_port,
90 max_port, 90 max_port,
91 username, 91 username,
92 password), 92 password),
93 incoming_only_(false), 93 incoming_only_(false),
94 allow_listen_(allow_listen), 94 allow_listen_(allow_listen),
95 socket_(NULL), 95 socket_(NULL),
96 error_(0) { 96 error_(0) {
97 // TODO(mallinath) - Set preference value as per RFC 6544. 97 // TODO(mallinath) - Set preference value as per RFC 6544.
98 // http://b/issue?id=7141794 98 // http://b/issue?id=7141794
99 }
100
101 bool TCPPort::Init() {
102 if (allow_listen_) { 99 if (allow_listen_) {
103 // Treat failure to create or bind a TCP socket as fatal. This 100 TryCreateServerSocket();
104 // should never happen.
Taylor Brandstetter 2017/06/13 03:41:30 "this should never happen" - juberti, Oct 13, 2013
105 socket_ = socket_factory()->CreateServerTcpSocket(
106 rtc::SocketAddress(ip(), 0), min_port(), max_port(),
107 false /* ssl */);
108 if (!socket_) {
109 LOG_J(LS_ERROR, this) << "TCP socket creation failed.";
110 return false;
111 }
112 socket_->SignalNewConnection.connect(this, &TCPPort::OnNewConnection);
113 socket_->SignalAddressReady.connect(this, &TCPPort::OnAddressReady);
114 } 101 }
115 return true;
116 } 102 }
117 103
118 TCPPort::~TCPPort() { 104 TCPPort::~TCPPort() {
119 delete socket_; 105 delete socket_;
120 std::list<Incoming>::iterator it; 106 std::list<Incoming>::iterator it;
121 for (it = incoming_.begin(); it != incoming_.end(); ++it) 107 for (it = incoming_.begin(); it != incoming_.end(); ++it)
122 delete it->socket; 108 delete it->socket;
123 incoming_.clear(); 109 incoming_.clear();
124 } 110 }
125 111
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 incoming.socket = new_socket; 253 incoming.socket = new_socket;
268 incoming.socket->SignalReadPacket.connect(this, &TCPPort::OnReadPacket); 254 incoming.socket->SignalReadPacket.connect(this, &TCPPort::OnReadPacket);
269 incoming.socket->SignalReadyToSend.connect(this, &TCPPort::OnReadyToSend); 255 incoming.socket->SignalReadyToSend.connect(this, &TCPPort::OnReadyToSend);
270 incoming.socket->SignalSentPacket.connect(this, &TCPPort::OnSentPacket); 256 incoming.socket->SignalSentPacket.connect(this, &TCPPort::OnSentPacket);
271 257
272 LOG_J(LS_VERBOSE, this) << "Accepted connection from " 258 LOG_J(LS_VERBOSE, this) << "Accepted connection from "
273 << incoming.addr.ToSensitiveString(); 259 << incoming.addr.ToSensitiveString();
274 incoming_.push_back(incoming); 260 incoming_.push_back(incoming);
275 } 261 }
276 262
263 void TCPPort::TryCreateServerSocket() {
264 // Treat failure to create or bind a TCP socket as fatal. This
265 // should never happen.
266 socket_ = socket_factory()->CreateServerTcpSocket(
267 rtc::SocketAddress(ip(), 0), min_port(), max_port(), false /* ssl */);
268 if (!socket_) {
269 LOG_J(LS_WARNING, this)
270 << "TCP server socket creation failed; continuing anyway.";
271 return;
272 }
273 socket_->SignalNewConnection.connect(this, &TCPPort::OnNewConnection);
274 socket_->SignalAddressReady.connect(this, &TCPPort::OnAddressReady);
275 }
276
277 rtc::AsyncPacketSocket* TCPPort::GetIncoming( 277 rtc::AsyncPacketSocket* TCPPort::GetIncoming(
278 const rtc::SocketAddress& addr, bool remove) { 278 const rtc::SocketAddress& addr, bool remove) {
279 rtc::AsyncPacketSocket* socket = NULL; 279 rtc::AsyncPacketSocket* socket = NULL;
280 for (std::list<Incoming>::iterator it = incoming_.begin(); 280 for (std::list<Incoming>::iterator it = incoming_.begin();
281 it != incoming_.end(); ++it) { 281 it != incoming_.end(); ++it) {
282 if (it->addr == addr) { 282 if (it->addr == addr) {
283 socket = it->socket; 283 socket = it->socket;
284 if (remove) 284 if (remove)
285 incoming_.erase(it); 285 incoming_.erase(it);
286 break; 286 break;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { 521 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) {
522 if (outgoing_) { 522 if (outgoing_) {
523 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); 523 socket->SignalConnect.connect(this, &TCPConnection::OnConnect);
524 } 524 }
525 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); 525 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket);
526 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); 526 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend);
527 socket->SignalClose.connect(this, &TCPConnection::OnClose); 527 socket->SignalClose.connect(this, &TCPConnection::OnClose);
528 } 528 }
529 529
530 } // namespace cricket 530 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698