OLD | NEW |
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 Loading... |
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. | |
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 Loading... |
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 socket_ = socket_factory()->CreateServerTcpSocket( |
| 265 rtc::SocketAddress(ip(), 0), min_port(), max_port(), false /* ssl */); |
| 266 if (!socket_) { |
| 267 LOG_J(LS_WARNING, this) |
| 268 << "TCP server socket creation failed; continuing anyway."; |
| 269 return; |
| 270 } |
| 271 socket_->SignalNewConnection.connect(this, &TCPPort::OnNewConnection); |
| 272 socket_->SignalAddressReady.connect(this, &TCPPort::OnAddressReady); |
| 273 } |
| 274 |
277 rtc::AsyncPacketSocket* TCPPort::GetIncoming( | 275 rtc::AsyncPacketSocket* TCPPort::GetIncoming( |
278 const rtc::SocketAddress& addr, bool remove) { | 276 const rtc::SocketAddress& addr, bool remove) { |
279 rtc::AsyncPacketSocket* socket = NULL; | 277 rtc::AsyncPacketSocket* socket = NULL; |
280 for (std::list<Incoming>::iterator it = incoming_.begin(); | 278 for (std::list<Incoming>::iterator it = incoming_.begin(); |
281 it != incoming_.end(); ++it) { | 279 it != incoming_.end(); ++it) { |
282 if (it->addr == addr) { | 280 if (it->addr == addr) { |
283 socket = it->socket; | 281 socket = it->socket; |
284 if (remove) | 282 if (remove) |
285 incoming_.erase(it); | 283 incoming_.erase(it); |
286 break; | 284 break; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { | 519 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { |
522 if (outgoing_) { | 520 if (outgoing_) { |
523 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); | 521 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); |
524 } | 522 } |
525 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); | 523 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); |
526 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); | 524 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); |
527 socket->SignalClose.connect(this, &TCPConnection::OnClose); | 525 socket->SignalClose.connect(this, &TCPConnection::OnClose); |
528 } | 526 } |
529 | 527 |
530 } // namespace cricket | 528 } // namespace cricket |
OLD | NEW |