mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
pipefs: better nonblocking named fifo open() handling
This commit is contained in:
@@ -40,6 +40,9 @@ int pipefs_close(vnode_t *node, int flags, cred_t *cred) {
|
|||||||
if (pipenode->writers == 0)
|
if (pipenode->writers == 0)
|
||||||
poll_event(&pipenode->pollheader, POLLHUP);
|
poll_event(&pipenode->pollheader, POLLHUP);
|
||||||
|
|
||||||
|
if (pipenode->writers == 0 && pipenode->readers == 0)
|
||||||
|
pipenode->open = false;
|
||||||
|
|
||||||
INTERNAL_UNLOCK(node);
|
INTERNAL_UNLOCK(node);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -61,8 +64,10 @@ int pipefs_open(vnode_t **node, int flags, cred_t *cred) {
|
|||||||
|
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
if (pipenode->writers > 0 && pipenode->readers > 0)
|
if (pipenode->writers > 0 && pipenode->readers > 0) {
|
||||||
|
pipenode->open = true;
|
||||||
goto leave;
|
goto leave;
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & V_FFLAGS_NONBLOCKING) {
|
if (flags & V_FFLAGS_NONBLOCKING) {
|
||||||
if (flags & V_FFLAGS_READ) {
|
if (flags & V_FFLAGS_READ) {
|
||||||
@@ -110,7 +115,7 @@ static int internalpoll(vnode_t *node, polldata_t *data, int events) {
|
|||||||
|
|
||||||
if (events & POLLIN) {
|
if (events & POLLIN) {
|
||||||
events |= POLLHUP;
|
events |= POLLHUP;
|
||||||
if (pipenode->writers == 0)
|
if (pipenode->writers == 0 && pipenode->open)
|
||||||
revents |= POLLHUP;
|
revents |= POLLHUP;
|
||||||
else if (RINGBUFFER_DATACOUNT(&pipenode->data) > 0)
|
else if (RINGBUFFER_DATACOUNT(&pipenode->data) > 0)
|
||||||
revents |= POLLIN;
|
revents |= POLLIN;
|
||||||
@@ -118,7 +123,7 @@ static int internalpoll(vnode_t *node, polldata_t *data, int events) {
|
|||||||
|
|
||||||
if (events & POLLOUT) {
|
if (events & POLLOUT) {
|
||||||
events |= POLLERR;
|
events |= POLLERR;
|
||||||
if (pipenode->readers == 0)
|
if (pipenode->readers == 0 && pipenode->open)
|
||||||
revents |= POLLERR;
|
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
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ typedef struct pipenode_t {
|
|||||||
vattr_t attr;
|
vattr_t attr;
|
||||||
ringbuffer_t data;
|
ringbuffer_t data;
|
||||||
size_t readers, writers;
|
size_t readers, writers;
|
||||||
|
bool open;
|
||||||
pollheader_t pollheader;
|
pollheader_t pollheader;
|
||||||
eventheader_t readopenevent;
|
eventheader_t readopenevent;
|
||||||
eventheader_t writeopenevent;
|
eventheader_t writeopenevent;
|
||||||
|
|||||||
Reference in New Issue
Block a user