Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: webrtc/base/virtualsocketserver.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/virtualsocketserver.h ('k') | webrtc/base/win32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 const in_addr kInitialNextIPv4 = { {0x01, 0, 0, 0} }; 30 const in_addr kInitialNextIPv4 = { {0x01, 0, 0, 0} };
31 #else 31 #else
32 // This value is entirely arbitrary, hence the lack of concern about endianness. 32 // This value is entirely arbitrary, hence the lack of concern about endianness.
33 const in_addr kInitialNextIPv4 = { 0x01000000 }; 33 const in_addr kInitialNextIPv4 = { 0x01000000 };
34 #endif 34 #endif
35 // Starts at ::2 so as to not cause confusion with ::1. 35 // Starts at ::2 so as to not cause confusion with ::1.
36 const in6_addr kInitialNextIPv6 = { { { 36 const in6_addr kInitialNextIPv6 = { { {
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2
38 } } }; 38 } } };
39 39
40 const uint16 kFirstEphemeralPort = 49152; 40 const uint16_t kFirstEphemeralPort = 49152;
41 const uint16 kLastEphemeralPort = 65535; 41 const uint16_t kLastEphemeralPort = 65535;
42 const uint16 kEphemeralPortCount = kLastEphemeralPort - kFirstEphemeralPort + 1; 42 const uint16_t kEphemeralPortCount =
43 const uint32 kDefaultNetworkCapacity = 64 * 1024; 43 kLastEphemeralPort - kFirstEphemeralPort + 1;
44 const uint32 kDefaultTcpBufferSize = 32 * 1024; 44 const uint32_t kDefaultNetworkCapacity = 64 * 1024;
45 const uint32_t kDefaultTcpBufferSize = 32 * 1024;
45 46
46 const uint32 UDP_HEADER_SIZE = 28; // IP + UDP headers 47 const uint32_t UDP_HEADER_SIZE = 28; // IP + UDP headers
47 const uint32 TCP_HEADER_SIZE = 40; // IP + TCP headers 48 const uint32_t TCP_HEADER_SIZE = 40; // IP + TCP headers
48 const uint32 TCP_MSS = 1400; // Maximum segment size 49 const uint32_t TCP_MSS = 1400; // Maximum segment size
49 50
50 // Note: The current algorithm doesn't work for sample sizes smaller than this. 51 // Note: The current algorithm doesn't work for sample sizes smaller than this.
51 const int NUM_SAMPLES = 1000; 52 const int NUM_SAMPLES = 1000;
52 53
53 enum { 54 enum {
54 MSG_ID_PACKET, 55 MSG_ID_PACKET,
55 MSG_ID_ADDRESS_BOUND, 56 MSG_ID_ADDRESS_BOUND,
56 MSG_ID_CONNECT, 57 MSG_ID_CONNECT,
57 MSG_ID_DISCONNECT, 58 MSG_ID_DISCONNECT,
58 }; 59 };
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 369 }
369 *value = it->second; 370 *value = it->second;
370 return 0; // 0 is success to emulate getsockopt() 371 return 0; // 0 is success to emulate getsockopt()
371 } 372 }
372 373
373 int VirtualSocket::SetOption(Option opt, int value) { 374 int VirtualSocket::SetOption(Option opt, int value) {
374 options_map_[opt] = value; 375 options_map_[opt] = value;
375 return 0; // 0 is success to emulate setsockopt() 376 return 0; // 0 is success to emulate setsockopt()
376 } 377 }
377 378
378 int VirtualSocket::EstimateMTU(uint16* mtu) { 379 int VirtualSocket::EstimateMTU(uint16_t* mtu) {
379 if (CS_CONNECTED != state_) 380 if (CS_CONNECTED != state_)
380 return ENOTCONN; 381 return ENOTCONN;
381 else 382 else
382 return 65536; 383 return 65536;
383 } 384 }
384 385
385 void VirtualSocket::OnMessage(Message* pmsg) { 386 void VirtualSocket::OnMessage(Message* pmsg) {
386 if (pmsg->message_id == MSG_ID_PACKET) { 387 if (pmsg->message_id == MSG_ID_PACKET) {
387 // ASSERT(!local_addr_.IsAny()); 388 // ASSERT(!local_addr_.IsAny());
388 ASSERT(NULL != pmsg->pdata); 389 ASSERT(NULL != pmsg->pdata);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 526 }
526 527
527 IPAddress VirtualSocketServer::GetNextIP(int family) { 528 IPAddress VirtualSocketServer::GetNextIP(int family) {
528 if (family == AF_INET) { 529 if (family == AF_INET) {
529 IPAddress next_ip(next_ipv4_); 530 IPAddress next_ip(next_ipv4_);
530 next_ipv4_.s_addr = 531 next_ipv4_.s_addr =
531 HostToNetwork32(NetworkToHost32(next_ipv4_.s_addr) + 1); 532 HostToNetwork32(NetworkToHost32(next_ipv4_.s_addr) + 1);
532 return next_ip; 533 return next_ip;
533 } else if (family == AF_INET6) { 534 } else if (family == AF_INET6) {
534 IPAddress next_ip(next_ipv6_); 535 IPAddress next_ip(next_ipv6_);
535 uint32* as_ints = reinterpret_cast<uint32*>(&next_ipv6_.s6_addr); 536 uint32_t* as_ints = reinterpret_cast<uint32_t*>(&next_ipv6_.s6_addr);
536 as_ints[3] += 1; 537 as_ints[3] += 1;
537 return next_ip; 538 return next_ip;
538 } 539 }
539 return IPAddress(); 540 return IPAddress();
540 } 541 }
541 542
542 uint16 VirtualSocketServer::GetNextPort() { 543 uint16_t VirtualSocketServer::GetNextPort() {
543 uint16 port = next_port_; 544 uint16_t port = next_port_;
544 if (next_port_ < kLastEphemeralPort) { 545 if (next_port_ < kLastEphemeralPort) {
545 ++next_port_; 546 ++next_port_;
546 } else { 547 } else {
547 next_port_ = kFirstEphemeralPort; 548 next_port_ = kFirstEphemeralPort;
548 } 549 }
549 return port; 550 return port;
550 } 551 }
551 552
552 Socket* VirtualSocketServer::CreateSocket(int type) { 553 Socket* VirtualSocketServer::CreateSocket(int type) {
553 return CreateSocket(AF_INET, type); 554 return CreateSocket(AF_INET, type);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 while (!msg_queue_->empty()) { 596 while (!msg_queue_->empty()) {
596 Message msg; 597 Message msg;
597 if (msg_queue_->Get(&msg, Thread::kForever)) { 598 if (msg_queue_->Get(&msg, Thread::kForever)) {
598 msg_queue_->Dispatch(&msg); 599 msg_queue_->Dispatch(&msg);
599 } 600 }
600 } 601 }
601 stop_on_idle_ = false; 602 stop_on_idle_ = false;
602 return !msg_queue_->IsQuitting(); 603 return !msg_queue_->IsQuitting();
603 } 604 }
604 605
605 void VirtualSocketServer::SetNextPortForTesting(uint16 port) { 606 void VirtualSocketServer::SetNextPortForTesting(uint16_t port) {
606 next_port_ = port; 607 next_port_ = port;
607 } 608 }
608 609
609 bool VirtualSocketServer::CloseTcpConnections( 610 bool VirtualSocketServer::CloseTcpConnections(
610 const SocketAddress& addr_local, 611 const SocketAddress& addr_local,
611 const SocketAddress& addr_remote) { 612 const SocketAddress& addr_remote) {
612 VirtualSocket* socket = LookupConnection(addr_local, addr_remote); 613 VirtualSocket* socket = LookupConnection(addr_local, addr_remote);
613 if (!socket) { 614 if (!socket) {
614 return false; 615 return false;
615 } 616 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 connections_->erase(address_pair); 725 connections_->erase(address_pair);
725 } 726 }
726 727
727 static double Random() { 728 static double Random() {
728 return static_cast<double>(rand()) / RAND_MAX; 729 return static_cast<double>(rand()) / RAND_MAX;
729 } 730 }
730 731
731 int VirtualSocketServer::Connect(VirtualSocket* socket, 732 int VirtualSocketServer::Connect(VirtualSocket* socket,
732 const SocketAddress& remote_addr, 733 const SocketAddress& remote_addr,
733 bool use_delay) { 734 bool use_delay) {
734 uint32 delay = use_delay ? GetRandomTransitDelay() : 0; 735 uint32_t delay = use_delay ? GetRandomTransitDelay() : 0;
735 VirtualSocket* remote = LookupBinding(remote_addr); 736 VirtualSocket* remote = LookupBinding(remote_addr);
736 if (!CanInteractWith(socket, remote)) { 737 if (!CanInteractWith(socket, remote)) {
737 LOG(LS_INFO) << "Address family mismatch between " 738 LOG(LS_INFO) << "Address family mismatch between "
738 << socket->GetLocalAddress() << " and " << remote_addr; 739 << socket->GetLocalAddress() << " and " << remote_addr;
739 return -1; 740 return -1;
740 } 741 }
741 if (remote != NULL) { 742 if (remote != NULL) {
742 SocketAddress addr = socket->GetLocalAddress(); 743 SocketAddress addr = socket->GetLocalAddress();
743 msg_queue_->PostDelayed(delay, remote, MSG_ID_CONNECT, 744 msg_queue_->PostDelayed(delay, remote, MSG_ID_CONNECT,
744 new MessageAddress(addr)); 745 new MessageAddress(addr));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 } 784 }
784 785
785 if (!CanInteractWith(socket, recipient)) { 786 if (!CanInteractWith(socket, recipient)) {
786 LOG(LS_VERBOSE) << "Incompatible address families: " 787 LOG(LS_VERBOSE) << "Incompatible address families: "
787 << socket->GetLocalAddress() << " and " << remote_addr; 788 << socket->GetLocalAddress() << " and " << remote_addr;
788 return -1; 789 return -1;
789 } 790 }
790 791
791 CritScope cs(&socket->crit_); 792 CritScope cs(&socket->crit_);
792 793
793 uint32 cur_time = Time(); 794 uint32_t cur_time = Time();
794 PurgeNetworkPackets(socket, cur_time); 795 PurgeNetworkPackets(socket, cur_time);
795 796
796 // Determine whether we have enough bandwidth to accept this packet. To do 797 // Determine whether we have enough bandwidth to accept this packet. To do
797 // this, we need to update the send queue. Once we know it's current size, 798 // this, we need to update the send queue. Once we know it's current size,
798 // we know whether we can fit this packet. 799 // we know whether we can fit this packet.
799 // 800 //
800 // NOTE: There are better algorithms for maintaining such a queue (such as 801 // NOTE: There are better algorithms for maintaining such a queue (such as
801 // "Derivative Random Drop"); however, this algorithm is a more accurate 802 // "Derivative Random Drop"); however, this algorithm is a more accurate
802 // simulation of what a normal network would do. 803 // simulation of what a normal network would do.
803 804
(...skipping 19 matching lines...) Expand all
823 // Lookup the local/remote pair in the connections table. 824 // Lookup the local/remote pair in the connections table.
824 VirtualSocket* recipient = LookupConnection(socket->local_addr_, 825 VirtualSocket* recipient = LookupConnection(socket->local_addr_,
825 socket->remote_addr_); 826 socket->remote_addr_);
826 if (!recipient) { 827 if (!recipient) {
827 LOG(LS_VERBOSE) << "Sending data to no one."; 828 LOG(LS_VERBOSE) << "Sending data to no one.";
828 return; 829 return;
829 } 830 }
830 831
831 CritScope cs(&socket->crit_); 832 CritScope cs(&socket->crit_);
832 833
833 uint32 cur_time = Time(); 834 uint32_t cur_time = Time();
834 PurgeNetworkPackets(socket, cur_time); 835 PurgeNetworkPackets(socket, cur_time);
835 836
836 while (true) { 837 while (true) {
837 size_t available = recv_buffer_capacity_ - recipient->recv_buffer_size_; 838 size_t available = recv_buffer_capacity_ - recipient->recv_buffer_size_;
838 size_t max_data_size = 839 size_t max_data_size =
839 std::min<size_t>(available, TCP_MSS - TCP_HEADER_SIZE); 840 std::min<size_t>(available, TCP_MSS - TCP_HEADER_SIZE);
840 size_t data_size = std::min(socket->send_buffer_.size(), max_data_size); 841 size_t data_size = std::min(socket->send_buffer_.size(), max_data_size);
841 if (0 == data_size) 842 if (0 == data_size)
842 break; 843 break;
843 844
(...skipping 14 matching lines...) Expand all
858 859
859 if (socket->write_enabled_ 860 if (socket->write_enabled_
860 && (socket->send_buffer_.size() < send_buffer_capacity_)) { 861 && (socket->send_buffer_.size() < send_buffer_capacity_)) {
861 socket->write_enabled_ = false; 862 socket->write_enabled_ = false;
862 socket->SignalWriteEvent(socket); 863 socket->SignalWriteEvent(socket);
863 } 864 }
864 } 865 }
865 866
866 void VirtualSocketServer::AddPacketToNetwork(VirtualSocket* sender, 867 void VirtualSocketServer::AddPacketToNetwork(VirtualSocket* sender,
867 VirtualSocket* recipient, 868 VirtualSocket* recipient,
868 uint32 cur_time, 869 uint32_t cur_time,
869 const char* data, 870 const char* data,
870 size_t data_size, 871 size_t data_size,
871 size_t header_size, 872 size_t header_size,
872 bool ordered) { 873 bool ordered) {
873 VirtualSocket::NetworkEntry entry; 874 VirtualSocket::NetworkEntry entry;
874 entry.size = data_size + header_size; 875 entry.size = data_size + header_size;
875 876
876 sender->network_size_ += entry.size; 877 sender->network_size_ += entry.size;
877 uint32 send_delay = SendDelay(static_cast<uint32>(sender->network_size_)); 878 uint32_t send_delay = SendDelay(static_cast<uint32_t>(sender->network_size_));
878 entry.done_time = cur_time + send_delay; 879 entry.done_time = cur_time + send_delay;
879 sender->network_.push_back(entry); 880 sender->network_.push_back(entry);
880 881
881 // Find the delay for crossing the many virtual hops of the network. 882 // Find the delay for crossing the many virtual hops of the network.
882 uint32 transit_delay = GetRandomTransitDelay(); 883 uint32_t transit_delay = GetRandomTransitDelay();
883 884
884 // When the incoming packet is from a binding of the any address, translate it 885 // When the incoming packet is from a binding of the any address, translate it
885 // to the default route here such that the recipient will see the default 886 // to the default route here such that the recipient will see the default
886 // route. 887 // route.
887 SocketAddress sender_addr = sender->local_addr_; 888 SocketAddress sender_addr = sender->local_addr_;
888 IPAddress default_ip = GetDefaultRoute(sender_addr.ipaddr().family()); 889 IPAddress default_ip = GetDefaultRoute(sender_addr.ipaddr().family());
889 if (sender_addr.IsAnyIP() && !IPIsUnspec(default_ip)) { 890 if (sender_addr.IsAnyIP() && !IPIsUnspec(default_ip)) {
890 sender_addr.SetIP(default_ip); 891 sender_addr.SetIP(default_ip);
891 } 892 }
892 893
893 // Post the packet as a message to be delivered (on our own thread) 894 // Post the packet as a message to be delivered (on our own thread)
894 Packet* p = new Packet(data, data_size, sender_addr); 895 Packet* p = new Packet(data, data_size, sender_addr);
895 896
896 uint32 ts = TimeAfter(send_delay + transit_delay); 897 uint32_t ts = TimeAfter(send_delay + transit_delay);
897 if (ordered) { 898 if (ordered) {
898 // Ensure that new packets arrive after previous ones 899 // Ensure that new packets arrive after previous ones
899 // TODO: consider ordering on a per-socket basis, since this 900 // TODO: consider ordering on a per-socket basis, since this
900 // introduces artifical delay. 901 // introduces artifical delay.
901 ts = TimeMax(ts, network_delay_); 902 ts = TimeMax(ts, network_delay_);
902 } 903 }
903 msg_queue_->PostAt(ts, recipient, MSG_ID_PACKET, p); 904 msg_queue_->PostAt(ts, recipient, MSG_ID_PACKET, p);
904 network_delay_ = TimeMax(ts, network_delay_); 905 network_delay_ = TimeMax(ts, network_delay_);
905 } 906 }
906 907
907 void VirtualSocketServer::PurgeNetworkPackets(VirtualSocket* socket, 908 void VirtualSocketServer::PurgeNetworkPackets(VirtualSocket* socket,
908 uint32 cur_time) { 909 uint32_t cur_time) {
909 while (!socket->network_.empty() && 910 while (!socket->network_.empty() &&
910 (socket->network_.front().done_time <= cur_time)) { 911 (socket->network_.front().done_time <= cur_time)) {
911 ASSERT(socket->network_size_ >= socket->network_.front().size); 912 ASSERT(socket->network_size_ >= socket->network_.front().size);
912 socket->network_size_ -= socket->network_.front().size; 913 socket->network_size_ -= socket->network_.front().size;
913 socket->network_.pop_front(); 914 socket->network_.pop_front();
914 } 915 }
915 } 916 }
916 917
917 uint32 VirtualSocketServer::SendDelay(uint32 size) { 918 uint32_t VirtualSocketServer::SendDelay(uint32_t size) {
918 if (bandwidth_ == 0) 919 if (bandwidth_ == 0)
919 return 0; 920 return 0;
920 else 921 else
921 return 1000 * size / bandwidth_; 922 return 1000 * size / bandwidth_;
922 } 923 }
923 924
924 #if 0 925 #if 0
925 void PrintFunction(std::vector<std::pair<double, double> >* f) { 926 void PrintFunction(std::vector<std::pair<double, double> >* f) {
926 return; 927 return;
927 double sum = 0; 928 double sum = 0;
928 for (uint32 i = 0; i < f->size(); ++i) { 929 for (uint32_t i = 0; i < f->size(); ++i) {
929 std::cout << (*f)[i].first << '\t' << (*f)[i].second << std::endl; 930 std::cout << (*f)[i].first << '\t' << (*f)[i].second << std::endl;
930 sum += (*f)[i].second; 931 sum += (*f)[i].second;
931 } 932 }
932 if (!f->empty()) { 933 if (!f->empty()) {
933 const double mean = sum / f->size(); 934 const double mean = sum / f->size();
934 double sum_sq_dev = 0; 935 double sum_sq_dev = 0;
935 for (uint32 i = 0; i < f->size(); ++i) { 936 for (uint32_t i = 0; i < f->size(); ++i) {
936 double dev = (*f)[i].second - mean; 937 double dev = (*f)[i].second - mean;
937 sum_sq_dev += dev * dev; 938 sum_sq_dev += dev * dev;
938 } 939 }
939 std::cout << "Mean = " << mean << " StdDev = " 940 std::cout << "Mean = " << mean << " StdDev = "
940 << sqrt(sum_sq_dev / f->size()) << std::endl; 941 << sqrt(sum_sq_dev / f->size()) << std::endl;
941 } 942 }
942 } 943 }
943 #endif // <unused> 944 #endif // <unused>
944 945
945 void VirtualSocketServer::UpdateDelayDistribution() { 946 void VirtualSocketServer::UpdateDelayDistribution() {
(...skipping 17 matching lines...) Expand all
963 #if 0 // static unused gives a warning 964 #if 0 // static unused gives a warning
964 static double Pareto(double x, double min, double k) { 965 static double Pareto(double x, double min, double k) {
965 if (x < min) 966 if (x < min)
966 return 0; 967 return 0;
967 else 968 else
968 return k * std::pow(min, k) / std::pow(x, k+1); 969 return k * std::pow(min, k) / std::pow(x, k+1);
969 } 970 }
970 #endif 971 #endif
971 972
972 VirtualSocketServer::Function* VirtualSocketServer::CreateDistribution( 973 VirtualSocketServer::Function* VirtualSocketServer::CreateDistribution(
973 uint32 mean, uint32 stddev, uint32 samples) { 974 uint32_t mean,
975 uint32_t stddev,
976 uint32_t samples) {
974 Function* f = new Function(); 977 Function* f = new Function();
975 978
976 if (0 == stddev) { 979 if (0 == stddev) {
977 f->push_back(Point(mean, 1.0)); 980 f->push_back(Point(mean, 1.0));
978 } else { 981 } else {
979 double start = 0; 982 double start = 0;
980 if (mean >= 4 * static_cast<double>(stddev)) 983 if (mean >= 4 * static_cast<double>(stddev))
981 start = mean - 4 * static_cast<double>(stddev); 984 start = mean - 4 * static_cast<double>(stddev);
982 double end = mean + 4 * static_cast<double>(stddev); 985 double end = mean + 4 * static_cast<double>(stddev);
983 986
984 for (uint32 i = 0; i < samples; i++) { 987 for (uint32_t i = 0; i < samples; i++) {
985 double x = start + (end - start) * i / (samples - 1); 988 double x = start + (end - start) * i / (samples - 1);
986 double y = Normal(x, mean, stddev); 989 double y = Normal(x, mean, stddev);
987 f->push_back(Point(x, y)); 990 f->push_back(Point(x, y));
988 } 991 }
989 } 992 }
990 return Resample(Invert(Accumulate(f)), 0, 1, samples); 993 return Resample(Invert(Accumulate(f)), 0, 1, samples);
991 } 994 }
992 995
993 uint32 VirtualSocketServer::GetRandomTransitDelay() { 996 uint32_t VirtualSocketServer::GetRandomTransitDelay() {
994 size_t index = rand() % delay_dist_->size(); 997 size_t index = rand() % delay_dist_->size();
995 double delay = (*delay_dist_)[index].second; 998 double delay = (*delay_dist_)[index].second;
996 //LOG_F(LS_INFO) << "random[" << index << "] = " << delay; 999 //LOG_F(LS_INFO) << "random[" << index << "] = " << delay;
997 return static_cast<uint32>(delay); 1000 return static_cast<uint32_t>(delay);
998 } 1001 }
999 1002
1000 struct FunctionDomainCmp { 1003 struct FunctionDomainCmp {
1001 bool operator()(const VirtualSocketServer::Point& p1, 1004 bool operator()(const VirtualSocketServer::Point& p1,
1002 const VirtualSocketServer::Point& p2) { 1005 const VirtualSocketServer::Point& p2) {
1003 return p1.first < p2.first; 1006 return p1.first < p2.first;
1004 } 1007 }
1005 bool operator()(double v1, const VirtualSocketServer::Point& p2) { 1008 bool operator()(double v1, const VirtualSocketServer::Point& p2) {
1006 return v1 < p2.first; 1009 return v1 < p2.first;
1007 } 1010 }
(...skipping 16 matching lines...) Expand all
1024 } 1027 }
1025 1028
1026 VirtualSocketServer::Function* VirtualSocketServer::Invert(Function* f) { 1029 VirtualSocketServer::Function* VirtualSocketServer::Invert(Function* f) {
1027 for (Function::size_type i = 0; i < f->size(); ++i) 1030 for (Function::size_type i = 0; i < f->size(); ++i)
1028 std::swap((*f)[i].first, (*f)[i].second); 1031 std::swap((*f)[i].first, (*f)[i].second);
1029 1032
1030 std::sort(f->begin(), f->end(), FunctionDomainCmp()); 1033 std::sort(f->begin(), f->end(), FunctionDomainCmp());
1031 return f; 1034 return f;
1032 } 1035 }
1033 1036
1034 VirtualSocketServer::Function* VirtualSocketServer::Resample( 1037 VirtualSocketServer::Function* VirtualSocketServer::Resample(Function* f,
1035 Function* f, double x1, double x2, uint32 samples) { 1038 double x1,
1039 double x2,
1040 uint32_t samples) {
1036 Function* g = new Function(); 1041 Function* g = new Function();
1037 1042
1038 for (size_t i = 0; i < samples; i++) { 1043 for (size_t i = 0; i < samples; i++) {
1039 double x = x1 + (x2 - x1) * i / (samples - 1); 1044 double x = x1 + (x2 - x1) * i / (samples - 1);
1040 double y = Evaluate(f, x); 1045 double y = Evaluate(f, x);
1041 g->push_back(Point(x, y)); 1046 g->push_back(Point(x, y));
1042 } 1047 }
1043 1048
1044 delete f; 1049 delete f;
1045 return g; 1050 return g;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 void VirtualSocketServer::SetDefaultRoute(const IPAddress& from_addr) { 1122 void VirtualSocketServer::SetDefaultRoute(const IPAddress& from_addr) {
1118 RTC_DCHECK(!IPIsAny(from_addr)); 1123 RTC_DCHECK(!IPIsAny(from_addr));
1119 if (from_addr.family() == AF_INET) { 1124 if (from_addr.family() == AF_INET) {
1120 default_route_v4_ = from_addr; 1125 default_route_v4_ = from_addr;
1121 } else if (from_addr.family() == AF_INET6) { 1126 } else if (from_addr.family() == AF_INET6) {
1122 default_route_v6_ = from_addr; 1127 default_route_v6_ = from_addr;
1123 } 1128 }
1124 } 1129 }
1125 1130
1126 } // namespace rtc 1131 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/virtualsocketserver.h ('k') | webrtc/base/win32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698