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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 TestClient::~TestClient() { | 28 TestClient::~TestClient() { |
29 delete socket_; | 29 delete socket_; |
30 for (unsigned i = 0; i < packets_->size(); i++) | 30 for (unsigned i = 0; i < packets_->size(); i++) |
31 delete (*packets_)[i]; | 31 delete (*packets_)[i]; |
32 delete packets_; | 32 delete packets_; |
33 } | 33 } |
34 | 34 |
35 bool TestClient::CheckConnState(AsyncPacketSocket::State state) { | 35 bool TestClient::CheckConnState(AsyncPacketSocket::State state) { |
36 // Wait for our timeout value until the socket reaches the desired state. | 36 // Wait for our timeout value until the socket reaches the desired state. |
37 uint32_t end = TimeAfter(kTimeoutMs); | 37 int64_t end = TimeAfter(kTimeoutMs); |
38 while (socket_->GetState() != state && TimeUntil(end) > 0) | 38 while (socket_->GetState() != state && TimeUntil(end) > 0) { |
39 Thread::Current()->ProcessMessages(1); | 39 Thread::Current()->ProcessMessages(1); |
| 40 } |
40 return (socket_->GetState() == state); | 41 return (socket_->GetState() == state); |
41 } | 42 } |
42 | 43 |
43 int TestClient::Send(const char* buf, size_t size) { | 44 int TestClient::Send(const char* buf, size_t size) { |
44 rtc::PacketOptions options; | 45 rtc::PacketOptions options; |
45 return socket_->Send(buf, size, options); | 46 return socket_->Send(buf, size, options); |
46 } | 47 } |
47 | 48 |
48 int TestClient::SendTo(const char* buf, size_t size, | 49 int TestClient::SendTo(const char* buf, size_t size, |
49 const SocketAddress& dest) { | 50 const SocketAddress& dest) { |
50 rtc::PacketOptions options; | 51 rtc::PacketOptions options; |
51 return socket_->SendTo(buf, size, dest, options); | 52 return socket_->SendTo(buf, size, dest, options); |
52 } | 53 } |
53 | 54 |
54 TestClient::Packet* TestClient::NextPacket(int timeout_ms) { | 55 TestClient::Packet* TestClient::NextPacket(int timeout_ms) { |
55 // If no packets are currently available, we go into a get/dispatch loop for | 56 // If no packets are currently available, we go into a get/dispatch loop for |
56 // at most timeout_ms. If, during the loop, a packet arrives, then we can | 57 // at most timeout_ms. If, during the loop, a packet arrives, then we can |
57 // stop early and return it. | 58 // stop early and return it. |
58 | 59 |
59 // Note that the case where no packet arrives is important. We often want to | 60 // Note that the case where no packet arrives is important. We often want to |
60 // test that a packet does not arrive. | 61 // test that a packet does not arrive. |
61 | 62 |
62 // Note also that we only try to pump our current thread's message queue. | 63 // Note also that we only try to pump our current thread's message queue. |
63 // Pumping another thread's queue could lead to messages being dispatched from | 64 // Pumping another thread's queue could lead to messages being dispatched from |
64 // the wrong thread to non-thread-safe objects. | 65 // the wrong thread to non-thread-safe objects. |
65 | 66 |
66 uint32_t end = TimeAfter(timeout_ms); | 67 int64_t end = TimeAfter(timeout_ms); |
67 while (TimeUntil(end) > 0) { | 68 while (TimeUntil(end) > 0) { |
68 { | 69 { |
69 CritScope cs(&crit_); | 70 CritScope cs(&crit_); |
70 if (packets_->size() != 0) { | 71 if (packets_->size() != 0) { |
71 break; | 72 break; |
72 } | 73 } |
73 } | 74 } |
74 Thread::Current()->ProcessMessages(1); | 75 Thread::Current()->ProcessMessages(1); |
75 } | 76 } |
76 | 77 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 : addr(p.addr), buf(0), size(p.size) { | 140 : addr(p.addr), buf(0), size(p.size) { |
140 buf = new char[size]; | 141 buf = new char[size]; |
141 memcpy(buf, p.buf, size); | 142 memcpy(buf, p.buf, size); |
142 } | 143 } |
143 | 144 |
144 TestClient::Packet::~Packet() { | 145 TestClient::Packet::~Packet() { |
145 delete[] buf; | 146 delete[] buf; |
146 } | 147 } |
147 | 148 |
148 } // namespace rtc | 149 } // namespace rtc |
OLD | NEW |