OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2017 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 |
11 #ifndef WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ | 11 #ifndef WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ |
12 #define WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ | 12 #define WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "webrtc/api/ortc/packettransportinterface.h" | 16 #include "webrtc/api/ortc/packettransportinterface.h" |
17 #include "webrtc/base/asyncinvoker.h" | 17 #include "webrtc/base/asyncinvoker.h" |
18 #include "webrtc/base/copyonwritebuffer.h" | 18 #include "webrtc/base/copyonwritebuffer.h" |
19 #include "webrtc/p2p/base/packettransportinternal.h" | 19 #include "webrtc/p2p/base/packettransportinternal.h" |
20 | 20 |
21 namespace rtc { | 21 namespace rtc { |
22 | 22 |
23 // Used to simulate a packet-based transport. | 23 // Used to simulate a packet-based transport. |
24 class FakePacketTransport : public PacketTransportInternal, | 24 class FakePacketTransport : public PacketTransportInternal { |
25 public webrtc::PacketTransportInterface { | |
26 public: | 25 public: |
27 explicit FakePacketTransport(const std::string& debug_name) | 26 explicit FakePacketTransport(const std::string& debug_name) |
28 : debug_name_(debug_name) {} | 27 : debug_name_(debug_name) {} |
29 ~FakePacketTransport() override { | 28 ~FakePacketTransport() override { |
30 if (dest_ && dest_->dest_ == this) { | 29 if (dest_ && dest_->dest_ == this) { |
31 dest_->dest_ = nullptr; | 30 dest_->dest_ = nullptr; |
32 } | 31 } |
33 } | 32 } |
34 | 33 |
35 // If async, will send packets by "Post"-ing to message queue instead of | 34 // If async, will send packets by "Post"-ing to message queue instead of |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 SendPacketInternal(packet); | 79 SendPacketInternal(packet); |
81 } | 80 } |
82 SentPacket sent_packet(options.packet_id, TimeMillis()); | 81 SentPacket sent_packet(options.packet_id, TimeMillis()); |
83 SignalSentPacket(this, sent_packet); | 82 SignalSentPacket(this, sent_packet); |
84 return static_cast<int>(len); | 83 return static_cast<int>(len); |
85 } | 84 } |
86 int SetOption(Socket::Option opt, int value) override { return true; } | 85 int SetOption(Socket::Option opt, int value) override { return true; } |
87 bool GetOption(Socket::Option opt, int* value) override { return true; } | 86 bool GetOption(Socket::Option opt, int* value) override { return true; } |
88 int GetError() override { return 0; } | 87 int GetError() override { return 0; } |
89 | 88 |
90 protected: | |
91 PacketTransportInternal* GetInternal() override { return this; } | |
92 | |
93 private: | 89 private: |
94 void set_writable(bool writable) { | 90 void set_writable(bool writable) { |
95 if (writable_ == writable) { | 91 if (writable_ == writable) { |
96 return; | 92 return; |
97 } | 93 } |
98 writable_ = writable; | 94 writable_ = writable; |
99 if (writable_) { | 95 if (writable_) { |
100 SignalReadyToSend(this); | 96 SignalReadyToSend(this); |
101 } | 97 } |
102 SignalWritableState(this); | 98 SignalWritableState(this); |
(...skipping 19 matching lines...) Expand all Loading... |
122 FakePacketTransport* dest_ = nullptr; | 118 FakePacketTransport* dest_ = nullptr; |
123 bool async_ = false; | 119 bool async_ = false; |
124 int async_delay_ms_ = 0; | 120 int async_delay_ms_ = 0; |
125 bool writable_ = false; | 121 bool writable_ = false; |
126 bool receiving_ = false; | 122 bool receiving_ = false; |
127 }; | 123 }; |
128 | 124 |
129 } // namespace rtc | 125 } // namespace rtc |
130 | 126 |
131 #endif // WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ | 127 #endif // WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ |
OLD | NEW |