pipefs: change how HUP/ERR is handled

This commit is contained in:
Matheus
2026-06-03 19:46:15 -03:00
parent 008cfd9b63
commit 0f8b1ac5a6
+8 -8
View File
@@ -113,21 +113,21 @@ static int internalpoll(vnode_t *node, polldata_t *data, int events) {
pipenode_t *pipenode = (pipenode_t *)node; pipenode_t *pipenode = (pipenode_t *)node;
int revents = 0; int revents = 0;
if (pipenode->writers == 0 && pipenode->open)
revents |= POLLHUP;
if (pipenode->readers == 0 && pipenode->open)
revents |= POLLHUP;
if (events & POLLIN) { if (events & POLLIN) {
events |= POLLHUP;
if (pipenode->writers == 0 && pipenode->open)
revents |= POLLHUP;
if (RINGBUFFER_DATACOUNT(&pipenode->data) > 0) if (RINGBUFFER_DATACOUNT(&pipenode->data) > 0)
revents |= POLLIN; revents |= POLLIN;
} }
if (events & POLLOUT) { if (events & POLLOUT) {
events |= POLLERR;
if (pipenode->readers == 0 && pipenode->open)
revents |= POLLERR;
// poll will only return POLLOUT if an atomic write can be done without blocking // poll will only return POLLOUT if an atomic write can be done without blocking
// this is undocumented in POSIX but many unices implement it like this // this is undocumented in POSIX but many unices implement it like this
else if (RINGBUFFER_DATACOUNT(&pipenode->data) < BUFFER_SIZE - PIPE_ATOMIC_SIZE) if (RINGBUFFER_DATACOUNT(&pipenode->data) < BUFFER_SIZE - PIPE_ATOMIC_SIZE)
revents |= POLLOUT; revents |= POLLOUT;
} }
@@ -231,7 +231,7 @@ int pipefs_write(vnode_t *node, iovec_iterator_t *iovec_iterator, size_t size, u
while (1) { while (1) {
// check for space or if the read end has been closed // check for space or if the read end has been closed
int revents = internalpoll(node, NULL, POLLOUT); int revents = internalpoll(node, NULL, POLLOUT);
if (revents & POLLERR) if (revents & (POLLERR | POLLHUP))
break; break;
size_t freebytes = RINGBUFFER_FREESPACE(&pipenode->data); size_t freebytes = RINGBUFFER_FREESPACE(&pipenode->data);