chore(wave6a): reserve P2 error domains, guard IO pipe SIGPIPE, extend ProcessHelper, and add Wave 6A specs

This commit is contained in:
faumaray committed 2026-11-24 10:56:39 +03:00
1 parent 44799602c9
commit 3f67b1ecb7
6 files changed
+470 -2

No files matched your search

+55
View File
@@ -14,6 +14,7 @@
#ifdef __linux__
#include <fcntl.h>
#include <signal.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/socket.h>
@@ -30,6 +31,55 @@ namespace
return std::error_code{err, std::generic_category()};
}
#ifdef __linux__
[[nodiscard]] ssize_t write_pipe_nosigpipe(
int fd, const void* buf, std::size_t len, int& out_errno) noexcept
{
sigset_t pending{};
::sigemptyset(&pending);
::sigpending(&pending);
const bool was_pending = (::sigismember(&pending, SIGPIPE) == 1);
sigset_t block{};
::sigemptyset(&block);
::sigaddset(&block, SIGPIPE);
sigset_t old_mask{};
const int mask_rc = ::pthread_sigmask(SIG_BLOCK, &block, &old_mask);
const bool was_blocked =
(mask_rc == 0) && (::sigismember(&old_mask, SIGPIPE) == 1);
ssize_t n = -1;
out_errno = 0;
for (;;) {
n = ::write(fd, buf, len);
if (n < 0) {
out_errno = errno;
if (out_errno == EINTR) {
continue;
}
}
break;
}
if (n < 0 && out_errno == EPIPE && !was_pending && !was_blocked) {
const struct timespec zero_wait{0, 0};
for (;;) {
if (::sigtimedwait(&block, nullptr, &zero_wait) >= 0) {
break;
}
if (errno != EINTR) {
break;
}
}
}
if (mask_rc == 0 && !was_blocked) {
(void)::pthread_sigmask(SIG_SETMASK, &old_mask, nullptr);
}
return n;
}
#endif
void dispatch_tickets(std::vector<Async::ResumeTicket>& tickets)
{
for (auto& t : tickets) {
@@ -1503,6 +1553,10 @@ private:
continue;
}
if (saved_errno == ENOTSOCK) {
#ifdef __linux__
n = write_pipe_nosigpipe(
fd, op->write_ptr, to_write, saved_errno);
#else
n = ::write(fd, op->write_ptr, to_write);
if (n < 0) {
saved_errno = errno;
@@ -1510,6 +1564,7 @@ private:
continue;
}
}
#endif
}
}
break;