This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 151e6fa5c57c02783e3a572f29e04a4e9e0addee Author: Damian Meden <[email protected]> AuthorDate: Thu Jul 11 20:04:38 2024 +0200 JSONRPC Client - Fix OSX/FreeBSD write socket issue. (#11537) This fix will get CI running. It may need some cleanup afterwards. (cherry picked from commit 75f553584005428c2b4edb8f8eaa8a084eb1cbf5) --- include/shared/rpc/IPCSocketClient.h | 1 + src/mgmt/rpc/server/unit_tests/test_rpcserver.cc | 2 +- src/shared/rpc/IPCSocketClient.cc | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/shared/rpc/IPCSocketClient.h b/include/shared/rpc/IPCSocketClient.h index 9c7273bc4c..891c2581d7 100644 --- a/include/shared/rpc/IPCSocketClient.h +++ b/include/shared/rpc/IPCSocketClient.h @@ -85,6 +85,7 @@ struct IPCSocketClient { } protected: + ssize_t _safe_write(int fd, const char *buffer, int len); std::string _path; struct sockaddr_un _server; diff --git a/src/mgmt/rpc/server/unit_tests/test_rpcserver.cc b/src/mgmt/rpc/server/unit_tests/test_rpcserver.cc index 7238450f34..5b2cb2411f 100644 --- a/src/mgmt/rpc/server/unit_tests/test_rpcserver.cc +++ b/src/mgmt/rpc/server/unit_tests/test_rpcserver.cc @@ -159,7 +159,7 @@ struct ScopedLocalSocket : shared::rpc::IPCSocketClient { int chunk_number{1}; auto chunks = chunk<N>(data); for (auto &&part : chunks) { - if (safe_write(_sock, part.c_str(), part.size()) < 0) { + if (super::_safe_write(_sock, part.c_str(), part.size()) == -1) { Debug(logTag, "error sending message :%s", std ::strerror(errno)); break; } diff --git a/src/shared/rpc/IPCSocketClient.cc b/src/shared/rpc/IPCSocketClient.cc index a6c6215f93..2c8ba9b3e2 100644 --- a/src/shared/rpc/IPCSocketClient.cc +++ b/src/shared/rpc/IPCSocketClient.cc @@ -154,11 +154,28 @@ IPCSocketClient::connect(std::chrono::milliseconds ms, int attempts) return *this; } +ssize_t +IPCSocketClient::_safe_write(int fd, const char *buffer, int len) +{ + ssize_t written{0}; + while (written < len) { + const int ret = ::write(fd, buffer + written, len - written); + if (ret == -1) { + if (errno == EAGAIN || errno == EINTR) { + continue; + } + return -1; + } + written += ret; + } + + return written; +} IPCSocketClient::self_reference IPCSocketClient ::send(std::string_view data) { std::string msg{data}; - if (safe_write(_sock, msg.c_str(), msg.size()) < 0) { + if (_safe_write(_sock, msg.c_str(), msg.size()) == -1) { this->close(); std::string text; throw std::runtime_error{swoc::bwprint(text, "Error writing on stream socket {}({})", std::strerror(errno), errno)};
