kernel: Add POLLHUP and store it when a polled socket's peer disconnects
This commit is contained in:
parent
b614fa04de
commit
753a56d14c
@ -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:
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user