kernel: Add POLLHUP and store it when a polled socket's peer disconnects

This commit is contained in:
apio 2023-08-14 13:22:41 +02:00
parent b614fa04de
commit 753a56d14c
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 16 additions and 0 deletions

View File

@ -69,6 +69,8 @@ class Socket : public VFS::FileInode
virtual bool can_read_data() const = 0;
virtual bool peer_disconnected() const = 0;
virtual ~Socket() = default;
protected:

View File

@ -27,6 +27,11 @@ class UnixSocket : public Socket
return !m_listen_queue.is_empty();
}
bool peer_disconnected() const override
{
return m_state == Reset;
}
Result<usize> send(const u8*, usize, int) override;
Result<usize> recv(u8*, usize, int) const override;

View File

@ -48,6 +48,9 @@ Result<u64> sys_poll(Registers*, SyscallArgs args)
if (kfds[i].events & POLLIN)
{
fds_with_events++;
kfds[i].revents |= POLLIN;
if (inode->type() == VFS::InodeType::Socket)
{
auto socket = (Socket*)inode.ptr();
@ -56,6 +59,11 @@ Result<u64> sys_poll(Registers*, SyscallArgs args)
fds_with_events++;
kfds[i].revents |= POLLIN;
}
if (socket->peer_disconnected())
{
fds_with_events++;
kfds[i].revents |= POLLHUP;
}
}
else
{

View File

@ -8,6 +8,7 @@
#define POLLIN (1 << 0)
#define POLLERR (1 << 1)
#define POLLNVAL (1 << 2)
#define POLLHUP (1 << 3)
typedef __u64_t nfds_t;