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