/* * Copyright 2004 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// Communicates using a local TCP port. // // This class is designed to allow subclasses to take advantage of the // connection management provided by this class. A subclass should take of all // packet sending and preparation, but when a packet is received, it should // call this TCPPort::OnReadPacket (3 arg) to dispatch to a connection. class TCPPort : public Port { public: static std::unique_ptr<TCPPort> Create(const PortParametersRef& args,
uint16_t min_port,
uint16_t max_port, bool allow_listen) { // Using `new` to access a non-public constructor. return absl::WrapUnique( new TCPPort(args, min_port, max_port, allow_listen));
}
[[deprecated("Pass arguments using PortParametersRef")]] static std::
unique_ptr<TCPPort>
Create(webrtc::TaskQueueBase* thread,
rtc::PacketSocketFactory* factory, const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
absl::string_view username,
absl::string_view password, bool allow_listen, const webrtc::FieldTrialsView* field_trials = nullptr) { return Create({.network_thread = thread,
.socket_factory = factory,
.network = network,
.ice_username_fragment = username,
.ice_password = password,
.field_trials = field_trials},
min_port, max_port, allow_listen);
}
~TCPPort() override;
// Options apply to accepted sockets. // TODO(bugs.webrtc.org/13065): Apply also to outgoing and existing // connections. int GetOption(rtc::Socket::Option opt, int* value) override; int SetOption(rtc::Socket::Option opt, int value) override; int GetError() override; bool SupportsProtocol(absl::string_view protocol) const override;
ProtocolType GetProtocol() const override;
bool allow_listen_;
std::unique_ptr<rtc::AsyncListenSocket> listen_socket_; // Options to be applied to accepted sockets. // TODO(bugs.webrtc:13065): Configure connect/accept in the same way, but // currently, setting OPT_NODELAY for client sockets is done (unconditionally) // by BasicPacketSocketFactory::CreateClientTcpSocket.
webrtc::flat_map<rtc::Socket::Option, int> socket_options_;
int error_;
std::list<Incoming> incoming_;
friendclass TCPConnection;
};
class TCPConnection : public Connection, public sigslot::has_slots<> { public: // Connection is outgoing unless socket is specified
TCPConnection(rtc::WeakPtr<Port> tcp_port, const Candidate& candidate,
rtc::AsyncPacketSocket* socket = nullptr);
~TCPConnection() override;
int Send(constvoid* data,
size_t size, const rtc::PacketOptions& options) override; int GetError() override;
// Allow test cases to overwrite the default timeout period. int reconnection_timeout() const { return reconnection_timeout_; } void set_reconnection_timeout(int timeout_in_ms) {
reconnection_timeout_ = timeout_in_ms;
}
protected: // Set waiting_for_stun_binding_complete_ to false to allow data packets in // addition to what Port::OnConnectionRequestResponse does. void OnConnectionRequestResponse(StunRequest* req,
StunMessage* response) override;
private: friendclass TCPPort; // For `MaybeReconnect()`.
// Helper function to handle the case when Ping or Send fails with error // related to socket close. void MaybeReconnect();
std::unique_ptr<rtc::AsyncPacketSocket> socket_; int error_; constbool outgoing_;
// Guard against multiple outgoing tcp connection during a reconnect. bool connection_pending_;
// Guard against data packets sent when we reconnect a TCP connection. During // reconnecting, when a new tcp connection has being made, we can't send data // packets out until the STUN binding is completed (i.e. the write state is // set to WRITABLE again by Connection::OnConnectionRequestResponse). IPC // socket, when receiving data packets before that, will trigger OnError which // will terminate the newly created connection. bool pretending_to_be_writable_;
// Allow test case to overwrite the default timeout period. int reconnection_timeout_;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.