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

Side by Side Diff: media/cast/test/utility/udp_proxy.cc

Issue 721273002: Remove timing limitation to set Broadcast, ReceiveBuffer, and SendBuffer options from UDPSocket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <math.h> 5 #include <math.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <vector> 7 #include <vector>
8 8
9 #include "media/cast/test/utility/udp_proxy.h" 9 #include "media/cast/test/utility/udp_proxy.h"
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "base/time/default_tick_clock.h" 15 #include "base/time/default_tick_clock.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/udp/udp_socket.h" 18 #include "net/udp/udp_server_socket.h"
19 19
20 namespace media { 20 namespace media {
21 namespace cast { 21 namespace cast {
22 namespace test { 22 namespace test {
23 23
24 const size_t kMaxPacketSize = 65536; 24 const size_t kMaxPacketSize = 65536;
25 25
26 PacketPipe::PacketPipe() {} 26 PacketPipe::PacketPipe() {}
27 PacketPipe::~PacketPipe() {} 27 PacketPipe::~PacketPipe() {}
28 void PacketPipe::InitOnIOThread( 28 void PacketPipe::InitOnIOThread(
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 if (result == net::ERR_IO_PENDING) { 731 if (result == net::ERR_IO_PENDING) {
732 blocked_ = true; 732 blocked_ = true;
733 } else if (result < 0) { 733 } else if (result < 0) {
734 LOG(ERROR) << "Failed to write packet."; 734 LOG(ERROR) << "Failed to write packet.";
735 } 735 }
736 } 736 }
737 737
738 private: 738 private:
739 void Start(base::WaitableEvent* start_event, 739 void Start(base::WaitableEvent* start_event,
740 net::NetLog* net_log) { 740 net::NetLog* net_log) {
741 socket_.reset(new net::UDPSocket(net::DatagramSocket::DEFAULT_BIND, 741 socket_.reset(new net::UDPServerSocket(net_log, net::NetLog::Source()));
742 net::RandIntCallback(),
743 net_log,
744 net::NetLog::Source()));
745 BuildPipe(&to_dest_pipe_, new PacketSender(this, &destination_)); 742 BuildPipe(&to_dest_pipe_, new PacketSender(this, &destination_));
746 BuildPipe(&from_dest_pipe_, new PacketSender(this, &return_address_)); 743 BuildPipe(&from_dest_pipe_, new PacketSender(this, &return_address_));
747 to_dest_pipe_->InitOnIOThread(base::MessageLoopProxy::current(), 744 to_dest_pipe_->InitOnIOThread(base::MessageLoopProxy::current(),
748 &tick_clock_); 745 &tick_clock_);
749 from_dest_pipe_->InitOnIOThread(base::MessageLoopProxy::current(), 746 from_dest_pipe_->InitOnIOThread(base::MessageLoopProxy::current(),
750 &tick_clock_); 747 &tick_clock_);
751 748
752 VLOG(0) << "From:" << local_port_.ToString(); 749 VLOG(0) << "From:" << local_port_.ToString();
753 if (!destination_is_mutable_) 750 if (!destination_is_mutable_)
754 VLOG(0) << "To:" << destination_.ToString(); 751 VLOG(0) << "To:" << destination_.ToString();
755 752
756 CHECK_GE(socket_->Bind(local_port_), 0); 753 CHECK_GE(socket_->Listen(local_port_), 0);
757 754
758 start_event->Signal(); 755 start_event->Signal();
759 PollRead(); 756 PollRead();
760 } 757 }
761 758
762 void Stop(base::WaitableEvent* stop_event) { 759 void Stop(base::WaitableEvent* stop_event) {
763 to_dest_pipe_.reset(NULL); 760 to_dest_pipe_.reset(NULL);
764 from_dest_pipe_.reset(NULL); 761 from_dest_pipe_.reset(NULL);
765 socket_.reset(NULL); 762 socket_.reset(NULL);
766 stop_event->Signal(); 763 stop_event->Signal();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 net::IPEndPoint local_port_; 820 net::IPEndPoint local_port_;
824 821
825 net::IPEndPoint destination_; 822 net::IPEndPoint destination_;
826 bool destination_is_mutable_; 823 bool destination_is_mutable_;
827 824
828 net::IPEndPoint return_address_; 825 net::IPEndPoint return_address_;
829 bool set_destination_next_; 826 bool set_destination_next_;
830 827
831 base::DefaultTickClock tick_clock_; 828 base::DefaultTickClock tick_clock_;
832 base::Thread proxy_thread_; 829 base::Thread proxy_thread_;
833 scoped_ptr<net::UDPSocket> socket_; 830 scoped_ptr<net::UDPServerSocket> socket_;
834 scoped_ptr<PacketPipe> to_dest_pipe_; 831 scoped_ptr<PacketPipe> to_dest_pipe_;
835 scoped_ptr<PacketPipe> from_dest_pipe_; 832 scoped_ptr<PacketPipe> from_dest_pipe_;
836 833
837 // For receiving. 834 // For receiving.
838 net::IPEndPoint recv_address_; 835 net::IPEndPoint recv_address_;
839 scoped_ptr<Packet> packet_; 836 scoped_ptr<Packet> packet_;
840 837
841 // For sending. 838 // For sending.
842 bool blocked_; 839 bool blocked_;
843 840
(...skipping 14 matching lines...) Expand all
858 destination, 855 destination,
859 to_dest_pipe.Pass(), 856 to_dest_pipe.Pass(),
860 from_dest_pipe.Pass(), 857 from_dest_pipe.Pass(),
861 net_log)); 858 net_log));
862 return ret.Pass(); 859 return ret.Pass();
863 } 860 }
864 861
865 } // namespace test 862 } // namespace test
866 } // namespace cast 863 } // namespace cast
867 } // namespace media 864 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698