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 21 matching lines...) Expand all Loading... |
32 public: | 32 public: |
33 static TCPPort* Create(rtc::Thread* thread, | 33 static TCPPort* Create(rtc::Thread* thread, |
34 rtc::PacketSocketFactory* factory, | 34 rtc::PacketSocketFactory* factory, |
35 rtc::Network* network, | 35 rtc::Network* network, |
36 const rtc::IPAddress& ip, | 36 const rtc::IPAddress& ip, |
37 uint16_t min_port, | 37 uint16_t min_port, |
38 uint16_t max_port, | 38 uint16_t max_port, |
39 const std::string& username, | 39 const std::string& username, |
40 const std::string& password, | 40 const std::string& password, |
41 bool allow_listen) { | 41 bool allow_listen) { |
42 TCPPort* port = new TCPPort(thread, factory, network, ip, min_port, | 42 return new TCPPort(thread, factory, network, ip, min_port, max_port, |
43 max_port, username, password, allow_listen); | 43 username, password, allow_listen); |
44 if (!port->Init()) { | |
45 delete port; | |
46 port = NULL; | |
47 } | |
48 return port; | |
49 } | 44 } |
50 ~TCPPort() override; | 45 ~TCPPort() override; |
51 | 46 |
52 Connection* CreateConnection(const Candidate& address, | 47 Connection* CreateConnection(const Candidate& address, |
53 CandidateOrigin origin) override; | 48 CandidateOrigin origin) override; |
54 | 49 |
55 void PrepareAddress() override; | 50 void PrepareAddress() override; |
56 | 51 |
57 int GetOption(rtc::Socket::Option opt, int* value) override; | 52 int GetOption(rtc::Socket::Option opt, int* value) override; |
58 int SetOption(rtc::Socket::Option opt, int value) override; | 53 int SetOption(rtc::Socket::Option opt, int value) override; |
59 int GetError() override; | 54 int GetError() override; |
60 bool SupportsProtocol(const std::string& protocol) const override { | 55 bool SupportsProtocol(const std::string& protocol) const override { |
61 return protocol == TCP_PROTOCOL_NAME || protocol == SSLTCP_PROTOCOL_NAME; | 56 return protocol == TCP_PROTOCOL_NAME || protocol == SSLTCP_PROTOCOL_NAME; |
62 } | 57 } |
63 | 58 |
64 ProtocolType GetProtocol() const override { return PROTO_TCP; } | 59 ProtocolType GetProtocol() const override { return PROTO_TCP; } |
65 | 60 |
66 protected: | 61 protected: |
67 TCPPort(rtc::Thread* thread, | 62 TCPPort(rtc::Thread* thread, |
68 rtc::PacketSocketFactory* factory, | 63 rtc::PacketSocketFactory* factory, |
69 rtc::Network* network, | 64 rtc::Network* network, |
70 const rtc::IPAddress& ip, | 65 const rtc::IPAddress& ip, |
71 uint16_t min_port, | 66 uint16_t min_port, |
72 uint16_t max_port, | 67 uint16_t max_port, |
73 const std::string& username, | 68 const std::string& username, |
74 const std::string& password, | 69 const std::string& password, |
75 bool allow_listen); | 70 bool allow_listen); |
76 bool Init(); | |
77 | 71 |
78 // Handles sending using the local TCP socket. | 72 // Handles sending using the local TCP socket. |
79 int SendTo(const void* data, | 73 int SendTo(const void* data, |
80 size_t size, | 74 size_t size, |
81 const rtc::SocketAddress& addr, | 75 const rtc::SocketAddress& addr, |
82 const rtc::PacketOptions& options, | 76 const rtc::PacketOptions& options, |
83 bool payload) override; | 77 bool payload) override; |
84 | 78 |
85 // Accepts incoming TCP connection. | 79 // Accepts incoming TCP connection. |
86 void OnNewConnection(rtc::AsyncPacketSocket* socket, | 80 void OnNewConnection(rtc::AsyncPacketSocket* socket, |
87 rtc::AsyncPacketSocket* new_socket); | 81 rtc::AsyncPacketSocket* new_socket); |
88 | 82 |
89 private: | 83 private: |
90 struct Incoming { | 84 struct Incoming { |
91 rtc::SocketAddress addr; | 85 rtc::SocketAddress addr; |
92 rtc::AsyncPacketSocket* socket; | 86 rtc::AsyncPacketSocket* socket; |
93 }; | 87 }; |
94 | 88 |
| 89 void TryCreateServerSocket(); |
| 90 |
95 rtc::AsyncPacketSocket* GetIncoming( | 91 rtc::AsyncPacketSocket* GetIncoming( |
96 const rtc::SocketAddress& addr, bool remove = false); | 92 const rtc::SocketAddress& addr, bool remove = false); |
97 | 93 |
98 // Receives packet signal from the local TCP Socket. | 94 // Receives packet signal from the local TCP Socket. |
99 void OnReadPacket(rtc::AsyncPacketSocket* socket, | 95 void OnReadPacket(rtc::AsyncPacketSocket* socket, |
100 const char* data, size_t size, | 96 const char* data, size_t size, |
101 const rtc::SocketAddress& remote_addr, | 97 const rtc::SocketAddress& remote_addr, |
102 const rtc::PacketTime& packet_time); | 98 const rtc::PacketTime& packet_time); |
103 | 99 |
104 void OnSentPacket(rtc::AsyncPacketSocket* socket, | 100 void OnSentPacket(rtc::AsyncPacketSocket* socket, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 181 |
186 // Allow test case to overwrite the default timeout period. | 182 // Allow test case to overwrite the default timeout period. |
187 int reconnection_timeout_; | 183 int reconnection_timeout_; |
188 | 184 |
189 friend class TCPPort; | 185 friend class TCPPort; |
190 }; | 186 }; |
191 | 187 |
192 } // namespace cricket | 188 } // namespace cricket |
193 | 189 |
194 #endif // WEBRTC_P2P_BASE_TCPPORT_H_ | 190 #endif // WEBRTC_P2P_BASE_TCPPORT_H_ |
OLD | NEW |