diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2018-11-07 04:07:11 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2018-11-07 04:07:11 +0000 |
commit | 7cedf5da5331fb08ee306eb19958f397f86e97aa (patch) | |
tree | 40ddfe92482c4903543dd67a7ffb7842e43f491a /network/netmgr/monitor.cpp | |
parent | 20077d56e6f6dae98d2365d4d67e739bc49a5076 (diff) | |
parent | aa76124b9f5fddd3279bb144267fda7a29aa9afe (diff) | |
download | android_device_generic_goldfish-7cedf5da5331fb08ee306eb19958f397f86e97aa.tar.gz android_device_generic_goldfish-7cedf5da5331fb08ee306eb19958f397f86e97aa.tar.bz2 android_device_generic_goldfish-7cedf5da5331fb08ee306eb19958f397f86e97aa.zip |
Snap for 5115288 from aa76124b9f5fddd3279bb144267fda7a29aa9afe to pi-qpr2-release
Change-Id: If8d613cafaffda76bdcc72ebb95cc5d85c26f873
Diffstat (limited to 'network/netmgr/monitor.cpp')
-rw-r--r-- | network/netmgr/monitor.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/network/netmgr/monitor.cpp b/network/netmgr/monitor.cpp index 492e7c6..4ab111e 100644 --- a/network/netmgr/monitor.cpp +++ b/network/netmgr/monitor.cpp @@ -44,7 +44,7 @@ void Monitor::setOnInterfaceState(OnInterfaceStateCallback callback) { mOnInterfaceStateCallback = callback; } -void Monitor::onReadAvailable() { +bool Monitor::onReadAvailable(int /*fd*/, int* /*status*/) { char buffer[32768]; struct sockaddr_storage storage; @@ -56,16 +56,21 @@ void Monitor::onReadAvailable() { MSG_DONTWAIT, reinterpret_cast<struct sockaddr*>(&storage), &addrSize); - if (status < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { - // Nothing to receive, everything is fine - return; - } else if (status < 0) { + if (status < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + // Nothing to receive, everything is fine + return true; + } else if (errno == EINTR) { + continue; + } LOGE("Monitor receive failed: %s", strerror(errno)); - return; + // An error occurred but let's keep trying + return true; } else if (addrSize < 0 || static_cast<size_t>(addrSize) != sizeof(struct sockaddr_nl)) { LOGE("Monitor received invalid address size"); - return; + // It's an error but no need to exit, let's keep polling + return true; } size_t length = static_cast<size_t>(status); @@ -84,20 +89,30 @@ void Monitor::onReadAvailable() { } } -void Monitor::onClose() { +bool Monitor::onClose(int /*fd*/, int* status) { // Socket was closed from the other end, close it from our end and re-open closeSocket(); Result res = openSocket(); if (!res) { LOGE("%s", res.c_str()); + *status = 1; + return false; } + return true; +} + +bool Monitor::onTimeout(int* /*status*/) { + return true; } -void Monitor::onTimeout() { +void Monitor::getPollData(std::vector<pollfd>* fds) const { + if (mSocketFd != -1) { + fds->push_back(pollfd{mSocketFd, POLLIN, 0}); + } } -Pollable::Data Monitor::data() const { - return Pollable::Data{ mSocketFd, Pollable::Timestamp::max() }; +Pollable::Timestamp Monitor::getTimeout() const { + return Pollable::Timestamp::max(); } Result Monitor::openSocket() { |