| 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 |
| 11 #ifndef WEBRTC_BASE_TESTCLIENT_H_ | 11 #ifndef WEBRTC_BASE_TESTCLIENT_H_ |
| 12 #define WEBRTC_BASE_TESTCLIENT_H_ | 12 #define WEBRTC_BASE_TESTCLIENT_H_ |
| 13 | 13 |
| 14 #include <vector> | 14 #include <vector> |
| 15 #include "webrtc/base/asyncudpsocket.h" | 15 #include "webrtc/base/asyncudpsocket.h" |
| 16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
| 17 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
| 18 | 18 |
| 19 namespace rtc { | 19 namespace rtc { |
| 20 | 20 |
| 21 // A simple client that can send TCP or UDP data and check that it receives | 21 // A simple client that can send TCP or UDP data and check that it receives |
| 22 // what it expects to receive. Useful for testing server functionality. | 22 // what it expects to receive. Useful for testing server functionality. |
| 23 class TestClient : public sigslot::has_slots<> { | 23 class TestClient : public sigslot::has_slots<> { |
| 24 public: | 24 public: |
| 25 // Records the contents of a packet that was received. | 25 // Records the contents of a packet that was received. |
| 26 struct Packet { | 26 struct Packet { |
| 27 Packet(const SocketAddress& a, const char* b, size_t s); | 27 Packet(const SocketAddress& a, |
| 28 const char* b, |
| 29 size_t s, |
| 30 const PacketTime& packet_time); |
| 28 Packet(const Packet& p); | 31 Packet(const Packet& p); |
| 29 virtual ~Packet(); | 32 virtual ~Packet(); |
| 30 | 33 |
| 31 SocketAddress addr; | 34 SocketAddress addr; |
| 32 char* buf; | 35 char* buf; |
| 33 size_t size; | 36 size_t size; |
| 37 PacketTime packet_time; |
| 34 }; | 38 }; |
| 35 | 39 |
| 36 // Default timeout for NextPacket reads. | 40 // Default timeout for NextPacket reads. |
| 37 static const int kTimeoutMs = 5000; | 41 static const int kTimeoutMs = 5000; |
| 38 | 42 |
| 39 // Creates a client that will send and receive with the given socket and | 43 // Creates a client that will send and receive with the given socket and |
| 40 // will post itself messages with the given thread. | 44 // will post itself messages with the given thread. |
| 41 explicit TestClient(AsyncPacketSocket* socket); | 45 explicit TestClient(AsyncPacketSocket* socket); |
| 42 ~TestClient() override; | 46 ~TestClient() override; |
| 43 | 47 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 private: | 82 private: |
| 79 // Timeout for reads when no packet is expected. | 83 // Timeout for reads when no packet is expected. |
| 80 static const int kNoPacketTimeoutMs = 1000; | 84 static const int kNoPacketTimeoutMs = 1000; |
| 81 // Workaround for the fact that AsyncPacketSocket::GetConnState doesn't exist. | 85 // Workaround for the fact that AsyncPacketSocket::GetConnState doesn't exist. |
| 82 Socket::ConnState GetState(); | 86 Socket::ConnState GetState(); |
| 83 // Slot for packets read on the socket. | 87 // Slot for packets read on the socket. |
| 84 void OnPacket(AsyncPacketSocket* socket, const char* buf, size_t len, | 88 void OnPacket(AsyncPacketSocket* socket, const char* buf, size_t len, |
| 85 const SocketAddress& remote_addr, | 89 const SocketAddress& remote_addr, |
| 86 const PacketTime& packet_time); | 90 const PacketTime& packet_time); |
| 87 void OnReadyToSend(AsyncPacketSocket* socket); | 91 void OnReadyToSend(AsyncPacketSocket* socket); |
| 92 bool CheckTimestamp(int64_t packet_timestamp); |
| 88 | 93 |
| 89 CriticalSection crit_; | 94 CriticalSection crit_; |
| 90 AsyncPacketSocket* socket_; | 95 AsyncPacketSocket* socket_; |
| 91 std::vector<Packet*>* packets_; | 96 std::vector<Packet*>* packets_; |
| 92 bool ready_to_send_; | 97 bool ready_to_send_; |
| 98 int64_t prev_packet_timestamp_; |
| 99 int64_t prev_time_us_; |
| 93 RTC_DISALLOW_COPY_AND_ASSIGN(TestClient); | 100 RTC_DISALLOW_COPY_AND_ASSIGN(TestClient); |
| 94 }; | 101 }; |
| 95 | 102 |
| 96 } // namespace rtc | 103 } // namespace rtc |
| 97 | 104 |
| 98 #endif // WEBRTC_BASE_TESTCLIENT_H_ | 105 #endif // WEBRTC_BASE_TESTCLIENT_H_ |
| OLD | NEW |