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

Unified Diff: tools/android/forwarder2/socket.cc

Issue 15008004: Add device port unmapping support to forwarder2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: tools/android/forwarder2/socket.cc
diff --git a/tools/android/forwarder2/socket.cc b/tools/android/forwarder2/socket.cc
index 12729b406c04f3adff767914a55a51638b2a4da1..7340ee3a6270ecd2990399f93d72db74f2bae36a 100644
--- a/tools/android/forwarder2/socket.cc
+++ b/tools/android/forwarder2/socket.cc
@@ -14,6 +14,8 @@
#include <sys/types.h>
#include <unistd.h>
+#include <algorithm>
+
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "base/safe_strerror_posix.h"
@@ -73,9 +75,7 @@ Socket::Socket()
socket_error_(false),
family_(AF_INET),
addr_ptr_(reinterpret_cast<sockaddr*>(&addr_.addr4)),
- addr_len_(sizeof(sockaddr)),
- exit_notifier_fd_(-1),
- exited_(false) {
+ addr_len_(sizeof(sockaddr)) {
memset(&addr_, 0, sizeof(addr_));
}
@@ -330,6 +330,16 @@ int Socket::WriteString(const std::string& buffer) {
return WriteNumBytes(buffer.c_str(), buffer.size());
}
+void Socket::AddEventFd(int event_fd) {
+ event_fds_.push_back(event_fd);
+ std::sort(event_fds_.begin(), event_fds_.end());
+}
+
+bool Socket::DidReceiveEventOnFd(int fd) const {
+ return std::find(
+ fired_events_.begin(), fired_events_.end(), fd) != fired_events_.end();
+}
+
int Socket::WriteNumBytes(const void* buffer, size_t num_bytes) {
int bytes_written = 0;
int ret = 1;
@@ -343,9 +353,9 @@ int Socket::WriteNumBytes(const void* buffer, size_t num_bytes) {
}
bool Socket::WaitForEvent(EventType type, int timeout_secs) {
- if (exit_notifier_fd_ == -1 || socket_ == -1)
+ if (event_fds_.empty() || socket_ == -1)
return true;
- const int nfds = std::max(socket_, exit_notifier_fd_) + 1;
+ const int nfds = std::max(socket_, event_fds_.back()) + 1;
fd_set read_fds;
fd_set write_fds;
FD_ZERO(&read_fds);
@@ -354,8 +364,10 @@ bool Socket::WaitForEvent(EventType type, int timeout_secs) {
FD_SET(socket_, &read_fds);
else
FD_SET(socket_, &write_fds);
- FD_SET(exit_notifier_fd_, &read_fds);
-
+ for (std::vector<int>::const_iterator it = event_fds_.begin();
+ it != event_fds_.end(); ++it) {
+ FD_SET(*it, &read_fds);
+ }
timeval tv = {};
timeval* tv_ptr = NULL;
if (timeout_secs > 0) {
@@ -365,11 +377,12 @@ bool Socket::WaitForEvent(EventType type, int timeout_secs) {
}
if (HANDLE_EINTR(select(nfds, &read_fds, &write_fds, NULL, tv_ptr)) <= 0)
return false;
- if (FD_ISSET(exit_notifier_fd_, &read_fds)) {
- exited_ = true;
- return false;
+ for (std::vector<int>::const_iterator it = event_fds_.begin();
+ it != event_fds_.end(); ++it) {
+ if (FD_ISSET(*it, &read_fds))
+ fired_events_.push_back(*it);
}
- return true;
+ return fired_events_.empty();
}
// static
« tools/android/forwarder2/host_forwarder_main.cc ('K') | « tools/android/forwarder2/socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698