OLD | NEW |
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 <fcntl.h> | 5 #include <fcntl.h> |
6 #include <linux/if_tun.h> | 6 #include <linux/if_tun.h> |
7 #include <linux/types.h> | 7 #include <linux/types.h> |
8 #include <math.h> | 8 #include <math.h> |
9 #include <net/if.h> | 9 #include <net/if.h> |
10 #include <netinet/in.h> | 10 #include <netinet/in.h> |
(...skipping 23 matching lines...) Expand all Loading... |
34 namespace media { | 34 namespace media { |
35 namespace cast { | 35 namespace cast { |
36 namespace test { | 36 namespace test { |
37 | 37 |
38 const size_t kMaxPacketSize = 4096; | 38 const size_t kMaxPacketSize = 4096; |
39 | 39 |
40 class SendToFDPipe : public PacketPipe { | 40 class SendToFDPipe : public PacketPipe { |
41 public: | 41 public: |
42 explicit SendToFDPipe(int fd) : fd_(fd) { | 42 explicit SendToFDPipe(int fd) : fd_(fd) { |
43 } | 43 } |
44 virtual void Send(scoped_ptr<Packet> packet) OVERRIDE { | 44 virtual void Send(scoped_ptr<Packet> packet) override { |
45 while (1) { | 45 while (1) { |
46 int written = write( | 46 int written = write( |
47 fd_, | 47 fd_, |
48 reinterpret_cast<char*>(&packet->front()), | 48 reinterpret_cast<char*>(&packet->front()), |
49 packet->size()); | 49 packet->size()); |
50 if (written < 0) { | 50 if (written < 0) { |
51 if (errno == EINTR) continue; | 51 if (errno == EINTR) continue; |
52 perror("write"); | 52 perror("write"); |
53 exit(1); | 53 exit(1); |
54 } | 54 } |
(...skipping 27 matching lines...) Expand all Loading... |
82 packet_pipe_ = tmp.Pass(); | 82 packet_pipe_ = tmp.Pass(); |
83 } | 83 } |
84 packet_pipe_->InitOnIOThread(base::MessageLoopProxy::current(), | 84 packet_pipe_->InitOnIOThread(base::MessageLoopProxy::current(), |
85 &tick_clock_); | 85 &tick_clock_); |
86 } | 86 } |
87 | 87 |
88 virtual ~QueueManager() { | 88 virtual ~QueueManager() { |
89 } | 89 } |
90 | 90 |
91 // MessageLoopForIO::Watcher methods | 91 // MessageLoopForIO::Watcher methods |
92 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE { | 92 virtual void OnFileCanReadWithoutBlocking(int fd) override { |
93 scoped_ptr<Packet> packet(new Packet(kMaxPacketSize)); | 93 scoped_ptr<Packet> packet(new Packet(kMaxPacketSize)); |
94 int nread = read(input_fd_, | 94 int nread = read(input_fd_, |
95 reinterpret_cast<char*>(&packet->front()), | 95 reinterpret_cast<char*>(&packet->front()), |
96 kMaxPacketSize); | 96 kMaxPacketSize); |
97 if (nread < 0) { | 97 if (nread < 0) { |
98 if (errno == EINTR) return; | 98 if (errno == EINTR) return; |
99 perror("read"); | 99 perror("read"); |
100 exit(1); | 100 exit(1); |
101 } | 101 } |
102 if (nread == 0) return; | 102 if (nread == 0) return; |
103 packet->resize(nread); | 103 packet->resize(nread); |
104 packet_pipe_->Send(packet.Pass()); | 104 packet_pipe_->Send(packet.Pass()); |
105 } | 105 } |
106 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE { | 106 virtual void OnFileCanWriteWithoutBlocking(int fd) override { |
107 NOTREACHED(); | 107 NOTREACHED(); |
108 } | 108 } |
109 | 109 |
110 private: | 110 private: |
111 int input_fd_; | 111 int input_fd_; |
112 scoped_ptr<PacketPipe> packet_pipe_; | 112 scoped_ptr<PacketPipe> packet_pipe_; |
113 base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; | 113 base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; |
114 base::DefaultTickClock tick_clock_; | 114 base::DefaultTickClock tick_clock_; |
115 }; | 115 }; |
116 | 116 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 ByteCounter in_pipe_input_counter; | 167 ByteCounter in_pipe_input_counter; |
168 ByteCounter in_pipe_output_counter; | 168 ByteCounter in_pipe_output_counter; |
169 ByteCounter out_pipe_input_counter; | 169 ByteCounter out_pipe_input_counter; |
170 ByteCounter out_pipe_output_counter; | 170 ByteCounter out_pipe_output_counter; |
171 | 171 |
172 class ByteCounterPipe : public media::cast::test::PacketPipe { | 172 class ByteCounterPipe : public media::cast::test::PacketPipe { |
173 public: | 173 public: |
174 ByteCounterPipe(ByteCounter* counter) : counter_(counter) {} | 174 ByteCounterPipe(ByteCounter* counter) : counter_(counter) {} |
175 virtual void Send(scoped_ptr<media::cast::Packet> packet) | 175 virtual void Send(scoped_ptr<media::cast::Packet> packet) |
176 OVERRIDE { | 176 override { |
177 counter_->Increment(packet->size()); | 177 counter_->Increment(packet->size()); |
178 pipe_->Send(packet.Pass()); | 178 pipe_->Send(packet.Pass()); |
179 } | 179 } |
180 private: | 180 private: |
181 ByteCounter* counter_; | 181 ByteCounter* counter_; |
182 }; | 182 }; |
183 | 183 |
184 void SetupByteCounters(scoped_ptr<media::cast::test::PacketPipe>* pipe, | 184 void SetupByteCounters(scoped_ptr<media::cast::test::PacketPipe>* pipe, |
185 ByteCounter* pipe_input_counter, | 185 ByteCounter* pipe_input_counter, |
186 ByteCounter* pipe_output_counter) { | 186 ByteCounter* pipe_output_counter) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 int fd2 = tun_alloc(argv[2], IFF_TAP); | 309 int fd2 = tun_alloc(argv[2], IFF_TAP); |
310 | 310 |
311 base::MessageLoopForIO message_loop; | 311 base::MessageLoopForIO message_loop; |
312 last_printout = base::TimeTicks::Now(); | 312 last_printout = base::TimeTicks::Now(); |
313 media::cast::test::QueueManager qm1(fd1, fd2, in_pipe.Pass()); | 313 media::cast::test::QueueManager qm1(fd1, fd2, in_pipe.Pass()); |
314 media::cast::test::QueueManager qm2(fd2, fd1, out_pipe.Pass()); | 314 media::cast::test::QueueManager qm2(fd2, fd1, out_pipe.Pass()); |
315 CheckByteCounters(); | 315 CheckByteCounters(); |
316 printf("Press Ctrl-C when done.\n"); | 316 printf("Press Ctrl-C when done.\n"); |
317 message_loop.Run(); | 317 message_loop.Run(); |
318 } | 318 } |
OLD | NEW |