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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 local_addr_ = addr; | 149 local_addr_ = addr; |
150 int result = server_->Bind(this, &local_addr_); | 150 int result = server_->Bind(this, &local_addr_); |
151 if (result != 0) { | 151 if (result != 0) { |
152 local_addr_.Clear(); | 152 local_addr_.Clear(); |
153 error_ = EADDRINUSE; | 153 error_ = EADDRINUSE; |
154 } else { | 154 } else { |
155 bound_ = true; | 155 bound_ = true; |
156 was_any_ = addr.IsAnyIP(); | 156 was_any_ = addr.IsAnyIP(); |
157 // Post a message here such that test case could have chance to | 157 // Post a message here such that test case could have chance to |
158 // process the local address. (i.e. SetAlternativeLocalAddress). | 158 // process the local address. (i.e. SetAlternativeLocalAddress). |
159 server_->msg_queue_->Post(this, MSG_ID_ADDRESS_BOUND); | 159 server_->msg_queue_->Post(RTC_FROM_HERE, this, MSG_ID_ADDRESS_BOUND); |
160 } | 160 } |
161 return result; | 161 return result; |
162 } | 162 } |
163 | 163 |
164 int VirtualSocket::Connect(const SocketAddress& addr) { | 164 int VirtualSocket::Connect(const SocketAddress& addr) { |
165 return InitiateConnect(addr, true); | 165 return InitiateConnect(addr, true); |
166 } | 166 } |
167 | 167 |
168 int VirtualSocket::Close() { | 168 int VirtualSocket::Close() { |
169 if (!local_addr_.IsNil() && bound_) { | 169 if (!local_addr_.IsNil() && bound_) { |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 bool use_delay) { | 753 bool use_delay) { |
754 uint32_t delay = use_delay ? GetRandomTransitDelay() : 0; | 754 uint32_t delay = use_delay ? GetRandomTransitDelay() : 0; |
755 VirtualSocket* remote = LookupBinding(remote_addr); | 755 VirtualSocket* remote = LookupBinding(remote_addr); |
756 if (!CanInteractWith(socket, remote)) { | 756 if (!CanInteractWith(socket, remote)) { |
757 LOG(LS_INFO) << "Address family mismatch between " | 757 LOG(LS_INFO) << "Address family mismatch between " |
758 << socket->GetLocalAddress() << " and " << remote_addr; | 758 << socket->GetLocalAddress() << " and " << remote_addr; |
759 return -1; | 759 return -1; |
760 } | 760 } |
761 if (remote != NULL) { | 761 if (remote != NULL) { |
762 SocketAddress addr = socket->GetLocalAddress(); | 762 SocketAddress addr = socket->GetLocalAddress(); |
763 msg_queue_->PostDelayed(delay, remote, MSG_ID_CONNECT, | 763 msg_queue_->PostDelayed(RTC_FROM_HERE, delay, remote, MSG_ID_CONNECT, |
764 new MessageAddress(addr)); | 764 new MessageAddress(addr)); |
765 } else { | 765 } else { |
766 LOG(LS_INFO) << "No one listening at " << remote_addr; | 766 LOG(LS_INFO) << "No one listening at " << remote_addr; |
767 msg_queue_->PostDelayed(delay, socket, MSG_ID_DISCONNECT); | 767 msg_queue_->PostDelayed(RTC_FROM_HERE, delay, socket, MSG_ID_DISCONNECT); |
768 } | 768 } |
769 return 0; | 769 return 0; |
770 } | 770 } |
771 | 771 |
772 bool VirtualSocketServer::Disconnect(VirtualSocket* socket) { | 772 bool VirtualSocketServer::Disconnect(VirtualSocket* socket) { |
773 if (socket) { | 773 if (socket) { |
774 // Remove the mapping. | 774 // Remove the mapping. |
775 msg_queue_->Post(socket, MSG_ID_DISCONNECT); | 775 msg_queue_->Post(RTC_FROM_HERE, socket, MSG_ID_DISCONNECT); |
776 return true; | 776 return true; |
777 } | 777 } |
778 return false; | 778 return false; |
779 } | 779 } |
780 | 780 |
781 int VirtualSocketServer::SendUdp(VirtualSocket* socket, | 781 int VirtualSocketServer::SendUdp(VirtualSocket* socket, |
782 const char* data, size_t data_size, | 782 const char* data, size_t data_size, |
783 const SocketAddress& remote_addr) { | 783 const SocketAddress& remote_addr) { |
784 // See if we want to drop this packet. | 784 // See if we want to drop this packet. |
785 if (Random() < drop_prob_) { | 785 if (Random() < drop_prob_) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 // Post the packet as a message to be delivered (on our own thread) | 913 // Post the packet as a message to be delivered (on our own thread) |
914 Packet* p = new Packet(data, data_size, sender_addr); | 914 Packet* p = new Packet(data, data_size, sender_addr); |
915 | 915 |
916 int64_t ts = TimeAfter(send_delay + transit_delay); | 916 int64_t ts = TimeAfter(send_delay + transit_delay); |
917 if (ordered) { | 917 if (ordered) { |
918 // Ensure that new packets arrive after previous ones | 918 // Ensure that new packets arrive after previous ones |
919 // TODO: consider ordering on a per-socket basis, since this | 919 // TODO: consider ordering on a per-socket basis, since this |
920 // introduces artificial delay. | 920 // introduces artificial delay. |
921 ts = std::max(ts, network_delay_); | 921 ts = std::max(ts, network_delay_); |
922 } | 922 } |
923 msg_queue_->PostAt(ts, recipient, MSG_ID_PACKET, p); | 923 msg_queue_->PostAt(RTC_FROM_HERE, ts, recipient, MSG_ID_PACKET, p); |
924 network_delay_ = std::max(ts, network_delay_); | 924 network_delay_ = std::max(ts, network_delay_); |
925 } | 925 } |
926 | 926 |
927 void VirtualSocketServer::PurgeNetworkPackets(VirtualSocket* socket, | 927 void VirtualSocketServer::PurgeNetworkPackets(VirtualSocket* socket, |
928 int64_t cur_time) { | 928 int64_t cur_time) { |
929 while (!socket->network_.empty() && | 929 while (!socket->network_.empty() && |
930 (socket->network_.front().done_time <= cur_time)) { | 930 (socket->network_.front().done_time <= cur_time)) { |
931 ASSERT(socket->network_size_ >= socket->network_.front().size); | 931 ASSERT(socket->network_size_ >= socket->network_.front().size); |
932 socket->network_size_ -= socket->network_.front().size; | 932 socket->network_size_ -= socket->network_.front().size; |
933 socket->network_.pop_front(); | 933 socket->network_.pop_front(); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 void VirtualSocketServer::SetDefaultRoute(const IPAddress& from_addr) { | 1141 void VirtualSocketServer::SetDefaultRoute(const IPAddress& from_addr) { |
1142 RTC_DCHECK(!IPIsAny(from_addr)); | 1142 RTC_DCHECK(!IPIsAny(from_addr)); |
1143 if (from_addr.family() == AF_INET) { | 1143 if (from_addr.family() == AF_INET) { |
1144 default_route_v4_ = from_addr; | 1144 default_route_v4_ = from_addr; |
1145 } else if (from_addr.family() == AF_INET6) { | 1145 } else if (from_addr.family() == AF_INET6) { |
1146 default_route_v6_ = from_addr; | 1146 default_route_v6_ = from_addr; |
1147 } | 1147 } |
1148 } | 1148 } |
1149 | 1149 |
1150 } // namespace rtc | 1150 } // namespace rtc |
OLD | NEW |