kernel: Add POLLHUP and store it when a polled socket's peer disconnects
This commit is contained in:
parent
5e6ce50c70
commit
6a35cad8d5
@ -69,6 +69,8 @@ class Socket : public VFS::FileInode
|
|||||||
|
|
||||||
virtual bool can_read_data() const = 0;
|
virtual bool can_read_data() const = 0;
|
||||||
|
|
||||||
|
virtual bool peer_disconnected() const = 0;
|
||||||
|
|
||||||
virtual ~Socket() = default;
|
virtual ~Socket() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -27,6 +27,11 @@ class UnixSocket : public Socket
|
|||||||
return !m_listen_queue.is_empty();
|
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> send(const u8*, usize, int) override;
|
||||||
Result<usize> recv(u8*, usize, int) const override;
|
Result<usize> recv(u8*, usize, int) const override;
|
||||||
|
|
||||||
|
@ -50,6 +50,9 @@ Result<u64> sys_poll(Registers*, SyscallArgs args)
|
|||||||
|
|
||||||
if (kfds[i].events & POLLIN)
|
if (kfds[i].events & POLLIN)
|
||||||
{
|
{
|
||||||
|
fds_with_events++;
|
||||||
|
kfds[i].revents |= POLLIN;
|
||||||
|
|
||||||
if (inode->type() == VFS::InodeType::Socket)
|
if (inode->type() == VFS::InodeType::Socket)
|
||||||
{
|
{
|
||||||
auto socket = (Socket*)inode.ptr();
|
auto socket = (Socket*)inode.ptr();
|
||||||
@ -58,6 +61,11 @@ Result<u64> sys_poll(Registers*, SyscallArgs args)
|
|||||||
fds_with_events++;
|
fds_with_events++;
|
||||||
kfds[i].revents |= POLLIN;
|
kfds[i].revents |= POLLIN;
|
||||||
}
|
}
|
||||||
|
if (socket->peer_disconnected())
|
||||||
|
{
|
||||||
|
fds_with_events++;
|
||||||
|
kfds[i].revents |= POLLHUP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#define POLLIN (1 << 0)
|
#define POLLIN (1 << 0)
|
||||||
#define POLLERR (1 << 1)
|
#define POLLERR (1 << 1)
|
||||||
#define POLLNVAL (1 << 2)
|
#define POLLNVAL (1 << 2)
|
||||||
|
#define POLLHUP (1 << 3)
|
||||||
|
|
||||||
typedef __u64_t nfds_t;
|
typedef __u64_t nfds_t;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user