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