Loading libs/binder/RpcServer.cpp +1 −18 Original line number Diff line number Diff line Loading @@ -16,14 +16,12 @@ #define LOG_TAG "RpcServer" #include <poll.h> #include <sys/socket.h> #include <sys/un.h> #include <thread> #include <vector> #include <android-base/macros.h> #include <android-base/scopeguard.h> #include <binder/Parcel.h> #include <binder/RpcServer.h> Loading Loading @@ -140,22 +138,7 @@ void RpcServer::join() { LOG_ALWAYS_FATAL_IF(mShutdownTrigger == nullptr, "Cannot create join signaler"); } while (true) { pollfd pfd[]{{.fd = mServer.get(), .events = POLLIN, .revents = 0}, {.fd = mShutdownTrigger->readFd().get(), .events = POLLHUP, .revents = 0}}; int ret = TEMP_FAILURE_RETRY(poll(pfd, arraysize(pfd), -1)); if (ret < 0) { ALOGE("Could not poll socket: %s", strerror(errno)); continue; } if (ret == 0) { continue; } if (pfd[1].revents & POLLHUP) { LOG_RPC_DETAIL("join() exiting because shutdown requested."); break; } while (mShutdownTrigger->triggerablePollRead(mServer)) { (void)acceptOneNoCheck(); } Loading libs/binder/RpcSession.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -19,10 +19,12 @@ #include <binder/RpcSession.h> #include <inttypes.h> #include <poll.h> #include <unistd.h> #include <string_view> #include <android-base/macros.h> #include <binder/Parcel.h> #include <binder/RpcServer.h> #include <binder/Stability.h> Loading Loading @@ -123,6 +125,25 @@ void RpcSession::FdTrigger::trigger() { mWrite.reset(); } bool RpcSession::FdTrigger::triggerablePollRead(base::borrowed_fd fd) { while (true) { pollfd pfd[]{{.fd = fd.get(), .events = POLLIN, .revents = 0}, {.fd = mRead.get(), .events = POLLHUP, .revents = 0}}; int ret = TEMP_FAILURE_RETRY(poll(pfd, arraysize(pfd), -1)); if (ret < 0) { ALOGE("Could not poll: %s", strerror(errno)); continue; } if (ret == 0) { continue; } if (pfd[1].revents & POLLHUP) { return false; } return true; } } status_t RpcSession::readId() { { std::lock_guard<std::mutex> _l(mMutex); Loading libs/binder/include/binder/RpcSession.h +10 −0 Original line number Diff line number Diff line Loading @@ -119,11 +119,21 @@ private: * poll() on this fd for POLLHUP to get notification when trigger is called */ base::borrowed_fd readFd() const { return mRead; } /** * Close the write end of the pipe so that the read end receives POLLHUP. */ void trigger(); /** * Poll for a read event. * * Return: * true - time to read! * false - trigger happened */ bool triggerablePollRead(base::borrowed_fd fd); private: base::unique_fd mWrite; base::unique_fd mRead; Loading Loading
libs/binder/RpcServer.cpp +1 −18 Original line number Diff line number Diff line Loading @@ -16,14 +16,12 @@ #define LOG_TAG "RpcServer" #include <poll.h> #include <sys/socket.h> #include <sys/un.h> #include <thread> #include <vector> #include <android-base/macros.h> #include <android-base/scopeguard.h> #include <binder/Parcel.h> #include <binder/RpcServer.h> Loading Loading @@ -140,22 +138,7 @@ void RpcServer::join() { LOG_ALWAYS_FATAL_IF(mShutdownTrigger == nullptr, "Cannot create join signaler"); } while (true) { pollfd pfd[]{{.fd = mServer.get(), .events = POLLIN, .revents = 0}, {.fd = mShutdownTrigger->readFd().get(), .events = POLLHUP, .revents = 0}}; int ret = TEMP_FAILURE_RETRY(poll(pfd, arraysize(pfd), -1)); if (ret < 0) { ALOGE("Could not poll socket: %s", strerror(errno)); continue; } if (ret == 0) { continue; } if (pfd[1].revents & POLLHUP) { LOG_RPC_DETAIL("join() exiting because shutdown requested."); break; } while (mShutdownTrigger->triggerablePollRead(mServer)) { (void)acceptOneNoCheck(); } Loading
libs/binder/RpcSession.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -19,10 +19,12 @@ #include <binder/RpcSession.h> #include <inttypes.h> #include <poll.h> #include <unistd.h> #include <string_view> #include <android-base/macros.h> #include <binder/Parcel.h> #include <binder/RpcServer.h> #include <binder/Stability.h> Loading Loading @@ -123,6 +125,25 @@ void RpcSession::FdTrigger::trigger() { mWrite.reset(); } bool RpcSession::FdTrigger::triggerablePollRead(base::borrowed_fd fd) { while (true) { pollfd pfd[]{{.fd = fd.get(), .events = POLLIN, .revents = 0}, {.fd = mRead.get(), .events = POLLHUP, .revents = 0}}; int ret = TEMP_FAILURE_RETRY(poll(pfd, arraysize(pfd), -1)); if (ret < 0) { ALOGE("Could not poll: %s", strerror(errno)); continue; } if (ret == 0) { continue; } if (pfd[1].revents & POLLHUP) { return false; } return true; } } status_t RpcSession::readId() { { std::lock_guard<std::mutex> _l(mMutex); Loading
libs/binder/include/binder/RpcSession.h +10 −0 Original line number Diff line number Diff line Loading @@ -119,11 +119,21 @@ private: * poll() on this fd for POLLHUP to get notification when trigger is called */ base::borrowed_fd readFd() const { return mRead; } /** * Close the write end of the pipe so that the read end receives POLLHUP. */ void trigger(); /** * Poll for a read event. * * Return: * true - time to read! * false - trigger happened */ bool triggerablePollRead(base::borrowed_fd fd); private: base::unique_fd mWrite; base::unique_fd mRead; Loading