From 0312bf278031bb5482b84538b14c2b381aa51f05 Mon Sep 17 00:00:00 2001 From: t-horikawa Date: Wed, 1 May 2024 09:20:32 +0900 Subject: [PATCH] Session shutdown is now detectable with Link.isAlive() --- src/tateyama/endpoint/ipc/wire.h | 6 +++--- src/tateyama/endpoint/stream/stream.h | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/tateyama/endpoint/ipc/wire.h b/src/tateyama/endpoint/ipc/wire.h index 565ce279..cb5d9866 100644 --- a/src/tateyama/endpoint/ipc/wire.h +++ b/src/tateyama/endpoint/ipc/wire.h @@ -376,9 +376,9 @@ class unidirectional_message_wire : public simple_wire { /** * @brief wait a request message arives and peep the current header. - * @returnm the essage_header if request message has been received, for normal reception of request message. - * otherwise, dummy request message whose length is 0 and index is message_header::termination_request for termination request, - * and dummy request message whose length is 0 and index is message_header::timeout for timeout. + * @return the essage_header if request message has been received, for normal reception of request message. + * otherwise, dummy request message whose length is 0 and index is message_header::termination_request for termination request + * @throws std::runtime_error when timeout occures. */ message_header peep(const char* base) { while (true) { diff --git a/src/tateyama/endpoint/stream/stream.h b/src/tateyama/endpoint/stream/stream.h index e2667a72..7a6f0738 100644 --- a/src/tateyama/endpoint/stream/stream.h +++ b/src/tateyama/endpoint/stream/stream.h @@ -221,9 +221,9 @@ class stream_socket await_result await(unsigned char& info, std::uint16_t& slot, std::string& payload) { DVLOG_LP(log_trace) << "-- enter waiting REQUEST --"; - fds_[0].fd = socket_; // NOLINT - fds_[0].events = POLLIN; // NOLINT - fds_[0].revents = 0; // NOLINT + fds_[0].fd = socket_; // NOLINT + fds_[0].events = POLLIN | POLLPRI; // NOLINT + fds_[0].revents = 0; // NOLINT while (true) { if (!queue_.empty() && slot_using_ < slot_size_) { auto entry = queue_.front(); @@ -241,6 +241,13 @@ class stream_socket throw std::runtime_error("error in poll"); } + if (fds_[0].revents & POLLPRI) { // NOLINT + unsigned char buf{}; + if (::recv (socket_, &buf, 1, MSG_OOB) < 0) { + return await_result::socket_closed; + } + return await_result::timeout; + } if (fds_[0].revents & POLLIN) { // NOLINT if (auto size_i = ::recv(socket_, &info, 1, 0); size_i == 0) { DVLOG_LP(log_trace) << "socket is closed by the client";