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 #include "webrtc/base/testclient.h" | 11 #include "webrtc/base/testclient.h" |
12 #include "webrtc/base/thread.h" | 12 #include "webrtc/base/thread.h" |
13 #include "webrtc/base/timeutils.h" | 13 #include "webrtc/base/timeutils.h" |
14 | 14 |
15 namespace rtc { | 15 namespace rtc { |
16 | 16 |
17 // DESIGN: Each packet received is put it into a list of packets. | 17 // DESIGN: Each packet received is put it into a list of packets. |
18 // Callers can retrieve received packets from any thread by calling | 18 // Callers can retrieve received packets from any thread by calling |
19 // NextPacket. | 19 // NextPacket. |
20 | 20 |
21 TestClient::TestClient(AsyncPacketSocket* socket) | 21 TestClient::TestClient(AsyncPacketSocket* socket) |
22 : socket_(socket), ready_to_send_(false), prev_packet_timestamp_(-1) { | 22 : socket_(socket), prev_packet_timestamp_(-1) { |
23 packets_ = new std::vector<Packet*>(); | 23 packets_ = new std::vector<Packet*>(); |
24 socket_->SignalReadPacket.connect(this, &TestClient::OnPacket); | 24 socket_->SignalReadPacket.connect(this, &TestClient::OnPacket); |
25 socket_->SignalReadyToSend.connect(this, &TestClient::OnReadyToSend); | 25 socket_->SignalReadyToSend.connect(this, &TestClient::OnReadyToSend); |
26 } | 26 } |
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_; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 123 } |
124 | 124 |
125 int TestClient::GetError() { | 125 int TestClient::GetError() { |
126 return socket_->GetError(); | 126 return socket_->GetError(); |
127 } | 127 } |
128 | 128 |
129 int TestClient::SetOption(Socket::Option opt, int value) { | 129 int TestClient::SetOption(Socket::Option opt, int value) { |
130 return socket_->SetOption(opt, value); | 130 return socket_->SetOption(opt, value); |
131 } | 131 } |
132 | 132 |
133 bool TestClient::ready_to_send() const { | |
134 return ready_to_send_; | |
135 } | |
136 | |
137 void TestClient::OnPacket(AsyncPacketSocket* socket, const char* buf, | 133 void TestClient::OnPacket(AsyncPacketSocket* socket, const char* buf, |
138 size_t size, const SocketAddress& remote_addr, | 134 size_t size, const SocketAddress& remote_addr, |
139 const PacketTime& packet_time) { | 135 const PacketTime& packet_time) { |
140 CritScope cs(&crit_); | 136 CritScope cs(&crit_); |
141 packets_->push_back(new Packet(remote_addr, buf, size, packet_time)); | 137 packets_->push_back(new Packet(remote_addr, buf, size, packet_time)); |
142 } | 138 } |
143 | 139 |
144 void TestClient::OnReadyToSend(AsyncPacketSocket* socket) { | 140 void TestClient::OnReadyToSend(AsyncPacketSocket* socket) { |
145 ready_to_send_ = true; | 141 ++ready_to_send_count_; |
146 } | 142 } |
147 | 143 |
148 TestClient::Packet::Packet(const SocketAddress& a, | 144 TestClient::Packet::Packet(const SocketAddress& a, |
149 const char* b, | 145 const char* b, |
150 size_t s, | 146 size_t s, |
151 const PacketTime& packet_time) | 147 const PacketTime& packet_time) |
152 : addr(a), buf(0), size(s), packet_time(packet_time) { | 148 : addr(a), buf(0), size(s), packet_time(packet_time) { |
153 buf = new char[size]; | 149 buf = new char[size]; |
154 memcpy(buf, b, size); | 150 memcpy(buf, b, size); |
155 } | 151 } |
156 | 152 |
157 TestClient::Packet::Packet(const Packet& p) | 153 TestClient::Packet::Packet(const Packet& p) |
158 : addr(p.addr), buf(0), size(p.size), packet_time(p.packet_time) { | 154 : addr(p.addr), buf(0), size(p.size), packet_time(p.packet_time) { |
159 buf = new char[size]; | 155 buf = new char[size]; |
160 memcpy(buf, p.buf, size); | 156 memcpy(buf, p.buf, size); |
161 } | 157 } |
162 | 158 |
163 TestClient::Packet::~Packet() { | 159 TestClient::Packet::~Packet() { |
164 delete[] buf; | 160 delete[] buf; |
165 } | 161 } |
166 | 162 |
167 } // namespace rtc | 163 } // namespace rtc |
OLD | NEW |