From a6295e6d90c839da9f3d5894eb2d307615282b7b Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 16 Feb 2021 22:19:50 +0100 Subject: [PATCH] Allow poll on all kinds of files. --- kernel/fs/user.cpp | 11 ++++++++--- kernel/inode.cpp | 22 +++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/kernel/fs/user.cpp b/kernel/fs/user.cpp index de4735ec..fd7f866e 100644 --- a/kernel/fs/user.cpp +++ b/kernel/fs/user.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017 Jonas 'Sortie' Termansen. + * Copyright (c) 2012-2017, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -1444,9 +1445,13 @@ int Unode::gettermmode(ioctx_t* ctx, unsigned* mode) return ret; } -int Unode::poll(ioctx_t* /*ctx*/, PollNode* /*node*/) +int Unode::poll(ioctx_t* /*ctx*/, PollNode* node) { - return errno = ENOTSUP, -1; + short status = POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM; + if ( !(status & node->events) ) + return errno = EAGAIN, -1; + node->master->revents |= status & node->events; + return 0; } int Unode::rename_here(ioctx_t* ctx, Ref from, const char* oldname, diff --git a/kernel/inode.cpp b/kernel/inode.cpp index 439f7091..926c239b 100644 --- a/kernel/inode.cpp +++ b/kernel/inode.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017 Jonas 'Sortie' Termansen. + * Copyright (c) 2012-2017, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include #include #include @@ -488,19 +490,13 @@ int AbstractInode::gettermmode(ioctx_t* /*ctx*/, unsigned* /*mode*/) return errno = ENOTTY, -1; } -int AbstractInode::poll(ioctx_t* /*ctx*/, PollNode* /*node*/) +int AbstractInode::poll(ioctx_t* /*ctx*/, PollNode* node) { -#if 0 // TODO: Support poll on regular files as per POSIX. - if ( inode_type == INODE_TYPE_FILE ) - { - // TODO: Correct bits? - if ( !((POLLIN | POLLOUT) & node->events) ) - return errno = EAGAIN, -1; - node->master->revents |= (POLLIN | POLLOUT) & node->events; - return 0; - } -#endif - return errno = ENOTSUP, -1; + short status = POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM; + if ( !(status & node->events) ) + return errno = EAGAIN, -1; + node->master->revents |= status & node->events; + return 0; } int AbstractInode::rename_here(ioctx_t* /*ctx*/, Ref /*from*/,