OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #ifndef WEBRTC_P2P_BASE_UDPTRANSPORTCHANNEL_H_ |
| 12 #define WEBRTC_P2P_BASE_UDPTRANSPORTCHANNEL_H_ |
| 13 |
| 14 #include <memory> |
| 15 #include <string> |
| 16 |
| 17 #include "webrtc/base/optional.h" |
| 18 #include "webrtc/base/thread_checker.h" |
| 19 #include "webrtc/p2p/base/packettransportinterface.h" |
| 20 |
| 21 namespace rtc { |
| 22 class AsyncPacketSocket; |
| 23 class PhysicalSocketServer; |
| 24 class SocketAddress; |
| 25 class SocketServer; |
| 26 class Thread; |
| 27 } |
| 28 |
| 29 namespace cricket { |
| 30 |
| 31 enum UdpTransportState { |
| 32 UDPTRANSPORT_STATE_INIT, |
| 33 UDPTRANSPORT_STATE_CONNECTING, |
| 34 UDPTRANSPORT_STATE_COMPLETED, |
| 35 UDPTRANSPORT_STATE_FAILED |
| 36 }; |
| 37 |
| 38 class UdpTransportChannel : public rtc::PacketTransportInterface { |
| 39 public: |
| 40 UdpTransportChannel(const std::string& transport_name, int component); |
| 41 UdpTransportChannel(const std::string& transport_name, |
| 42 int component, |
| 43 rtc::SocketServer* ss); |
| 44 ~UdpTransportChannel(); |
| 45 |
| 46 const std::string debug_name() const override { return debug_name_; } |
| 47 |
| 48 bool receiving() const override { |
| 49 // TODO(johan): Implement method and signal. |
| 50 return true; |
| 51 } |
| 52 |
| 53 bool writable() const override; |
| 54 |
| 55 int SendPacket(const char* data, |
| 56 size_t len, |
| 57 const rtc::PacketOptions& options, |
| 58 int flags) override; |
| 59 |
| 60 int SetOption(rtc::Socket::Option opt, int value) override { return 0; } |
| 61 |
| 62 int GetError() override { return send_error_; } |
| 63 |
| 64 UdpTransportState GetState() const { |
| 65 RTC_DCHECK_RUN_ON(&network_thread_checker_); |
| 66 return state_; |
| 67 } |
| 68 |
| 69 // Check GetState() for resulting state. |
| 70 void CreateSocket(); |
| 71 |
| 72 void SetRemoteParameters(const rtc::SocketAddress& remote); |
| 73 |
| 74 // Returns default value, if local candidate is not set. |
| 75 // Consider checking GetState() before calling local_parameters(). |
| 76 const rtc::SocketAddress& local_parameters(); |
| 77 |
| 78 private: |
| 79 void OnSocketReadPacket(rtc::AsyncPacketSocket* socket, |
| 80 const char* data, |
| 81 size_t len, |
| 82 const rtc::SocketAddress& remote_addr, |
| 83 const rtc::PacketTime& packet_time); |
| 84 void OnSocketSentPacket(rtc::AsyncPacketSocket* socket, |
| 85 const rtc::SentPacket& packet); |
| 86 void SetTransportChannelState( |
| 87 UdpTransportState state); // Set State and Signal. |
| 88 UdpTransportState state_ = UDPTRANSPORT_STATE_INIT; |
| 89 bool IsLocalConsistent(); |
| 90 void UpdateState(); |
| 91 void UpdateDebugName(); |
| 92 int send_error_ = 0; |
| 93 std::string transport_name_; |
| 94 std::string debug_name_; |
| 95 int component_; |
| 96 std::unique_ptr<rtc::AsyncPacketSocket> socket_; |
| 97 rtc::Optional<rtc::SocketAddress> local_parameters_; |
| 98 rtc::Optional<rtc::SocketAddress> remote_parameters_; |
| 99 rtc::SocketServer* socket_server_; |
| 100 rtc::ThreadChecker network_thread_checker_; |
| 101 }; |
| 102 } // namespace cricket |
| 103 |
| 104 #endif // WEBRTC_P2P_BASE_UDPTRANSPORTCHANNEL_H_ |
OLD | NEW |