| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "tools/android/forwarder2/forwarders_manager.h" | 5 #include "tools/android/forwarder2/forwarders_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <sys/select.h> | 8 #include <sys/select.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 base::Passed(&socket2))); | 43 base::Passed(&socket2))); |
| 44 | 44 |
| 45 // Guarantees that the CreateNewForwarderOnInternalThread callback posted to | 45 // Guarantees that the CreateNewForwarderOnInternalThread callback posted to |
| 46 // the internal thread gets executed immediately. | 46 // the internal thread gets executed immediately. |
| 47 wakeup_notifier_.Notify(); | 47 wakeup_notifier_.Notify(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void ForwardersManager::CreateNewForwarderOnInternalThread( | 50 void ForwardersManager::CreateNewForwarderOnInternalThread( |
| 51 std::unique_ptr<Socket> socket1, | 51 std::unique_ptr<Socket> socket1, |
| 52 std::unique_ptr<Socket> socket2) { | 52 std::unique_ptr<Socket> socket2) { |
| 53 DCHECK(thread_.task_runner()->RunsTasksOnCurrentThread()); | 53 DCHECK(thread_.task_runner()->RunsTasksInCurrentSequence()); |
| 54 forwarders_.push_back(new Forwarder(std::move(socket1), std::move(socket2))); | 54 forwarders_.push_back(new Forwarder(std::move(socket1), std::move(socket2))); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ForwardersManager::WaitForEventsOnInternalThreadSoon() { | 57 void ForwardersManager::WaitForEventsOnInternalThreadSoon() { |
| 58 thread_.task_runner()->PostTask( | 58 thread_.task_runner()->PostTask( |
| 59 FROM_HERE, | 59 FROM_HERE, |
| 60 base::Bind(&ForwardersManager::WaitForEventsOnInternalThread, | 60 base::Bind(&ForwardersManager::WaitForEventsOnInternalThread, |
| 61 base::Unretained(this))); | 61 base::Unretained(this))); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ForwardersManager::WaitForEventsOnInternalThread() { | 64 void ForwardersManager::WaitForEventsOnInternalThread() { |
| 65 DCHECK(thread_.task_runner()->RunsTasksOnCurrentThread()); | 65 DCHECK(thread_.task_runner()->RunsTasksInCurrentSequence()); |
| 66 fd_set read_fds; | 66 fd_set read_fds; |
| 67 fd_set write_fds; | 67 fd_set write_fds; |
| 68 | 68 |
| 69 FD_ZERO(&read_fds); | 69 FD_ZERO(&read_fds); |
| 70 FD_ZERO(&write_fds); | 70 FD_ZERO(&write_fds); |
| 71 | 71 |
| 72 // Populate the file descriptor sets. | 72 // Populate the file descriptor sets. |
| 73 int max_fd = -1; | 73 int max_fd = -1; |
| 74 for (ScopedVector<Forwarder>::iterator it = forwarders_.begin(); | 74 for (ScopedVector<Forwarder>::iterator it = forwarders_.begin(); |
| 75 it != forwarders_.end(); ++it) { | 75 it != forwarders_.end(); ++it) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 ++i; | 124 ++i; |
| 125 continue; | 125 continue; |
| 126 } | 126 } |
| 127 | 127 |
| 128 std::swap(forwarders_[i], forwarders_.back()); | 128 std::swap(forwarders_[i], forwarders_.back()); |
| 129 forwarders_.pop_back(); | 129 forwarders_.pop_back(); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace forwarder2 | 133 } // namespace forwarder2 |
| OLD | NEW |