Skip to content

Commit

Permalink
Session shutdown is now detectable with Link.isAlive()
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed May 1, 2024
1 parent a8ad424 commit 0312bf2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/tateyama/endpoint/ipc/wire.h
Expand Up @@ -376,9 +376,9 @@ class unidirectional_message_wire : public simple_wire<message_header> {

/**
* @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) {
Expand Down
13 changes: 10 additions & 3 deletions src/tateyama/endpoint/stream/stream.h
Expand Up @@ -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();
Expand All @@ -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";
Expand Down

0 comments on commit 0312bf2

Please sign in to comment.