#pragma once #include "arch/CPU.h" #include "fs/VFS.h" #include "thread/Thread.h" #include class Socket : public VFS::FileInode { public: Socket() = default; VFS::InodeType type() const override { return VFS::InodeType::Socket; } void set_fs(VFS::FileSystem* fs) { m_fs = fs; } void set_inode_number(usize inum) { m_inode_number = inum; } VFS::FileSystem* fs() const override { return m_fs; } usize inode_number() const override { return m_inode_number; } Result read(u8* buf, usize, usize length) const override { return recv(buf, length, 0); } Result write(const u8* buf, usize, usize length) override { return send(buf, length, 0); } virtual Result send(const u8*, usize, int) = 0; virtual Result recv(u8*, usize, int) const = 0; virtual Result bind(SharedPtr, struct sockaddr*, socklen_t) = 0; virtual Result connect(Registers*, int, struct sockaddr*, socklen_t) = 0; virtual Result> accept(Registers*, int, struct sockaddr**, socklen_t*) = 0; virtual Result listen(int backlog) = 0; Result truncate(usize) override { return err(EINVAL); } usize size() const override { return 0; } mode_t mode() const override { return m_mode; } u32 uid() const override { return m_uid; } u32 gid() const override { return m_gid; } nlink_t nlinks() const override { return (nlink_t)m_nlinks; } Result chmod(mode_t mode) override { m_mode = mode; return {}; } Result chown(u32 uid, u32 gid) override { m_uid = uid; m_gid = gid; return {}; } void did_link() override { m_nlinks++; } void did_unlink() override { m_nlinks--; } virtual ~Socket() = default; protected: VFS::FileSystem* m_fs { nullptr }; usize m_inode_number { 0 }; mode_t m_mode; u32 m_uid { 0 }; u32 m_gid { 0 }; u32 m_nlinks { 0 }; };