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 27 matching lines...) Expand all Loading... |
38 const std::string& password, | 38 const std::string& password, |
39 bool allow_listen) { | 39 bool allow_listen) { |
40 TCPPort* port = new TCPPort(thread, factory, network, ip, min_port, | 40 TCPPort* port = new TCPPort(thread, factory, network, ip, min_port, |
41 max_port, username, password, allow_listen); | 41 max_port, username, password, allow_listen); |
42 if (!port->Init()) { | 42 if (!port->Init()) { |
43 delete port; | 43 delete port; |
44 port = NULL; | 44 port = NULL; |
45 } | 45 } |
46 return port; | 46 return port; |
47 } | 47 } |
48 virtual ~TCPPort(); | 48 ~TCPPort() override; |
49 | 49 |
50 virtual Connection* CreateConnection(const Candidate& address, | 50 Connection* CreateConnection(const Candidate& address, |
51 CandidateOrigin origin); | 51 CandidateOrigin origin) override; |
52 | 52 |
53 virtual void PrepareAddress(); | 53 void PrepareAddress() override; |
54 | 54 |
55 virtual int GetOption(rtc::Socket::Option opt, int* value); | 55 int GetOption(rtc::Socket::Option opt, int* value) override; |
56 virtual int SetOption(rtc::Socket::Option opt, int value); | 56 int SetOption(rtc::Socket::Option opt, int value) override; |
57 virtual int GetError(); | 57 int GetError() override; |
58 virtual bool SupportsProtocol(const std::string& protocol) const { | 58 bool SupportsProtocol(const std::string& protocol) const override { |
59 return protocol == TCP_PROTOCOL_NAME || protocol == SSLTCP_PROTOCOL_NAME; | 59 return protocol == TCP_PROTOCOL_NAME || protocol == SSLTCP_PROTOCOL_NAME; |
60 } | 60 } |
61 | 61 |
62 protected: | 62 protected: |
63 TCPPort(rtc::Thread* thread, | 63 TCPPort(rtc::Thread* thread, |
64 rtc::PacketSocketFactory* factory, | 64 rtc::PacketSocketFactory* factory, |
65 rtc::Network* network, | 65 rtc::Network* network, |
66 const rtc::IPAddress& ip, | 66 const rtc::IPAddress& ip, |
67 uint16_t min_port, | 67 uint16_t min_port, |
68 uint16_t max_port, | 68 uint16_t max_port, |
69 const std::string& username, | 69 const std::string& username, |
70 const std::string& password, | 70 const std::string& password, |
71 bool allow_listen); | 71 bool allow_listen); |
72 bool Init(); | 72 bool Init(); |
73 | 73 |
74 // Handles sending using the local TCP socket. | 74 // Handles sending using the local TCP socket. |
75 virtual int SendTo(const void* data, size_t size, | 75 int SendTo(const void* data, |
76 const rtc::SocketAddress& addr, | 76 size_t size, |
77 const rtc::PacketOptions& options, | 77 const rtc::SocketAddress& addr, |
78 bool payload); | 78 const rtc::PacketOptions& options, |
| 79 bool payload) override; |
79 | 80 |
80 // Accepts incoming TCP connection. | 81 // Accepts incoming TCP connection. |
81 void OnNewConnection(rtc::AsyncPacketSocket* socket, | 82 void OnNewConnection(rtc::AsyncPacketSocket* socket, |
82 rtc::AsyncPacketSocket* new_socket); | 83 rtc::AsyncPacketSocket* new_socket); |
83 | 84 |
84 private: | 85 private: |
85 struct Incoming { | 86 struct Incoming { |
86 rtc::SocketAddress addr; | 87 rtc::SocketAddress addr; |
87 rtc::AsyncPacketSocket* socket; | 88 rtc::AsyncPacketSocket* socket; |
88 }; | 89 }; |
89 | 90 |
90 rtc::AsyncPacketSocket* GetIncoming( | 91 rtc::AsyncPacketSocket* GetIncoming( |
91 const rtc::SocketAddress& addr, bool remove = false); | 92 const rtc::SocketAddress& addr, bool remove = false); |
92 | 93 |
93 // Receives packet signal from the local TCP Socket. | 94 // Receives packet signal from the local TCP Socket. |
94 void OnReadPacket(rtc::AsyncPacketSocket* socket, | 95 void OnReadPacket(rtc::AsyncPacketSocket* socket, |
95 const char* data, size_t size, | 96 const char* data, size_t size, |
96 const rtc::SocketAddress& remote_addr, | 97 const rtc::SocketAddress& remote_addr, |
97 const rtc::PacketTime& packet_time); | 98 const rtc::PacketTime& packet_time); |
98 | 99 |
| 100 void OnSentPacket(rtc::AsyncPacketSocket* socket, |
| 101 const rtc::SentPacket& sent_packet) override; |
| 102 |
99 void OnReadyToSend(rtc::AsyncPacketSocket* socket); | 103 void OnReadyToSend(rtc::AsyncPacketSocket* socket); |
100 | 104 |
101 void OnAddressReady(rtc::AsyncPacketSocket* socket, | 105 void OnAddressReady(rtc::AsyncPacketSocket* socket, |
102 const rtc::SocketAddress& address); | 106 const rtc::SocketAddress& address); |
103 | 107 |
104 // TODO: Is this still needed? | 108 // TODO: Is this still needed? |
105 bool incoming_only_; | 109 bool incoming_only_; |
106 bool allow_listen_; | 110 bool allow_listen_; |
107 rtc::AsyncPacketSocket* socket_; | 111 rtc::AsyncPacketSocket* socket_; |
108 int error_; | 112 int error_; |
109 std::list<Incoming> incoming_; | 113 std::list<Incoming> incoming_; |
110 | 114 |
111 friend class TCPConnection; | 115 friend class TCPConnection; |
112 }; | 116 }; |
113 | 117 |
114 class TCPConnection : public Connection { | 118 class TCPConnection : public Connection { |
115 public: | 119 public: |
116 // Connection is outgoing unless socket is specified | 120 // Connection is outgoing unless socket is specified |
117 TCPConnection(TCPPort* port, const Candidate& candidate, | 121 TCPConnection(TCPPort* port, const Candidate& candidate, |
118 rtc::AsyncPacketSocket* socket = 0); | 122 rtc::AsyncPacketSocket* socket = 0); |
119 virtual ~TCPConnection(); | 123 ~TCPConnection() override; |
120 | 124 |
121 virtual int Send(const void* data, size_t size, | 125 int Send(const void* data, |
122 const rtc::PacketOptions& options); | 126 size_t size, |
123 virtual int GetError(); | 127 const rtc::PacketOptions& options) override; |
| 128 int GetError() override; |
124 | 129 |
125 rtc::AsyncPacketSocket* socket() { return socket_.get(); } | 130 rtc::AsyncPacketSocket* socket() { return socket_.get(); } |
126 | 131 |
127 void OnMessage(rtc::Message* pmsg); | 132 void OnMessage(rtc::Message* pmsg) override; |
128 | 133 |
129 // Allow test cases to overwrite the default timeout period. | 134 // Allow test cases to overwrite the default timeout period. |
130 int reconnection_timeout() const { return reconnection_timeout_; } | 135 int reconnection_timeout() const { return reconnection_timeout_; } |
131 void set_reconnection_timeout(int timeout_in_ms) { | 136 void set_reconnection_timeout(int timeout_in_ms) { |
132 reconnection_timeout_ = timeout_in_ms; | 137 reconnection_timeout_ = timeout_in_ms; |
133 } | 138 } |
134 | 139 |
135 protected: | 140 protected: |
136 enum { | 141 enum { |
137 MSG_TCPCONNECTION_DELAYED_ONCLOSE = Connection::MSG_FIRST_AVAILABLE, | 142 MSG_TCPCONNECTION_DELAYED_ONCLOSE = Connection::MSG_FIRST_AVAILABLE, |
138 }; | 143 }; |
139 | 144 |
140 // Set waiting_for_stun_binding_complete_ to false to allow data packets in | 145 // Set waiting_for_stun_binding_complete_ to false to allow data packets in |
141 // addition to what Port::OnConnectionRequestResponse does. | 146 // addition to what Port::OnConnectionRequestResponse does. |
142 virtual void OnConnectionRequestResponse(ConnectionRequest* req, | 147 void OnConnectionRequestResponse(ConnectionRequest* req, |
143 StunMessage* response); | 148 StunMessage* response) override; |
144 | 149 |
145 private: | 150 private: |
146 // Helper function to handle the case when Ping or Send fails with error | 151 // Helper function to handle the case when Ping or Send fails with error |
147 // related to socket close. | 152 // related to socket close. |
148 void MaybeReconnect(); | 153 void MaybeReconnect(); |
149 | 154 |
150 void CreateOutgoingTcpSocket(); | 155 void CreateOutgoingTcpSocket(); |
151 | 156 |
152 void ConnectSocketSignals(rtc::AsyncPacketSocket* socket); | 157 void ConnectSocketSignals(rtc::AsyncPacketSocket* socket); |
153 | 158 |
(...skipping 22 matching lines...) Expand all Loading... |
176 | 181 |
177 // Allow test case to overwrite the default timeout period. | 182 // Allow test case to overwrite the default timeout period. |
178 int reconnection_timeout_; | 183 int reconnection_timeout_; |
179 | 184 |
180 friend class TCPPort; | 185 friend class TCPPort; |
181 }; | 186 }; |
182 | 187 |
183 } // namespace cricket | 188 } // namespace cricket |
184 | 189 |
185 #endif // WEBRTC_P2P_BASE_TCPPORT_H_ | 190 #endif // WEBRTC_P2P_BASE_TCPPORT_H_ |
OLD | NEW |