diff --git a/Kernel/Console.cpp b/Kernel/Console.cpp index c4054189420..0fd10a34fa0 100644 --- a/Kernel/Console.cpp +++ b/Kernel/Console.cpp @@ -28,7 +28,7 @@ Console::~Console() { } -bool Console::can_read(FileDescription&) const +bool Console::can_read(const FileDescription&) const { return false; } diff --git a/Kernel/Console.h b/Kernel/Console.h index a9c89f5df7b..e7e0b92d319 100644 --- a/Kernel/Console.h +++ b/Kernel/Console.h @@ -20,8 +20,8 @@ public: virtual ~Console() override; // ^CharacterDevice - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override { return true; } virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; virtual const char* class_name() const override { return "Console"; } diff --git a/Kernel/Devices/BXVGADevice.cpp b/Kernel/Devices/BXVGADevice.cpp index 40e7569a52b..5c277075d17 100644 --- a/Kernel/Devices/BXVGADevice.cpp +++ b/Kernel/Devices/BXVGADevice.cpp @@ -150,12 +150,12 @@ int BXVGADevice::ioctl(FileDescription&, unsigned request, unsigned arg) }; } -bool BXVGADevice::can_read(FileDescription&) const +bool BXVGADevice::can_read(const FileDescription&) const { ASSERT_NOT_REACHED(); } -bool BXVGADevice::can_write(FileDescription&) const +bool BXVGADevice::can_write(const FileDescription&) const { ASSERT_NOT_REACHED(); } diff --git a/Kernel/Devices/BXVGADevice.h b/Kernel/Devices/BXVGADevice.h index 908bfd3bdb0..465203a9a8d 100644 --- a/Kernel/Devices/BXVGADevice.h +++ b/Kernel/Devices/BXVGADevice.h @@ -17,8 +17,8 @@ public: private: virtual const char* class_name() const override { return "BXVGA"; } - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; diff --git a/Kernel/Devices/DebugLogDevice.h b/Kernel/Devices/DebugLogDevice.h index 1c3296a2861..50142037106 100644 --- a/Kernel/Devices/DebugLogDevice.h +++ b/Kernel/Devices/DebugLogDevice.h @@ -11,7 +11,7 @@ private: // ^CharacterDevice virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; } virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; - virtual bool can_write(FileDescription&) const override { return true; } - virtual bool can_read(FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override { return true; } virtual const char* class_name() const override { return "DebugLogDevice"; } }; diff --git a/Kernel/Devices/DiskPartition.h b/Kernel/Devices/DiskPartition.h index 6ad35eb2c4b..0c2ea477d4c 100644 --- a/Kernel/Devices/DiskPartition.h +++ b/Kernel/Devices/DiskPartition.h @@ -15,9 +15,9 @@ public: // ^BlockDevice virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; } - virtual bool can_read(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override { return true; } virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return 0; } - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } private: virtual const char* class_name() const override; diff --git a/Kernel/Devices/FloppyDiskDevice.h b/Kernel/Devices/FloppyDiskDevice.h index 0b35f47fb7e..7afc0e49f1d 100644 --- a/Kernel/Devices/FloppyDiskDevice.h +++ b/Kernel/Devices/FloppyDiskDevice.h @@ -143,9 +143,9 @@ public: // ^BlockDevice virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; } - virtual bool can_read(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override { return true; } virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return 0; } - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } protected: explicit FloppyDiskDevice(DriveType); diff --git a/Kernel/Devices/FullDevice.cpp b/Kernel/Devices/FullDevice.cpp index b76a79d5bf2..55a985ad4a5 100644 --- a/Kernel/Devices/FullDevice.cpp +++ b/Kernel/Devices/FullDevice.cpp @@ -12,7 +12,7 @@ FullDevice::~FullDevice() { } -bool FullDevice::can_read(FileDescription&) const +bool FullDevice::can_read(const FileDescription&) const { return true; } diff --git a/Kernel/Devices/FullDevice.h b/Kernel/Devices/FullDevice.h index 9ba58161f16..14d0bbb6a0e 100644 --- a/Kernel/Devices/FullDevice.h +++ b/Kernel/Devices/FullDevice.h @@ -12,7 +12,7 @@ private: // ^CharacterDevice virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override { return true; } virtual const char* class_name() const override { return "FullDevice"; } }; diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index 37356d7bc99..cc64d85a6d0 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -368,7 +368,7 @@ KeyboardDevice::~KeyboardDevice() { } -bool KeyboardDevice::can_read(FileDescription&) const +bool KeyboardDevice::can_read(const FileDescription&) const { return !m_queue.is_empty(); } diff --git a/Kernel/Devices/KeyboardDevice.h b/Kernel/Devices/KeyboardDevice.h index 1ac2bcf8418..7ba84937449 100644 --- a/Kernel/Devices/KeyboardDevice.h +++ b/Kernel/Devices/KeyboardDevice.h @@ -24,9 +24,9 @@ public: // ^CharacterDevice virtual ssize_t read(FileDescription&, u8* buffer, ssize_t) override; - virtual bool can_read(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; virtual ssize_t write(FileDescription&, const u8* buffer, ssize_t) override; - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } private: // ^IRQHandler diff --git a/Kernel/Devices/MBVGADevice.cpp b/Kernel/Devices/MBVGADevice.cpp index d65524c9736..2b4554e7e5c 100644 --- a/Kernel/Devices/MBVGADevice.cpp +++ b/Kernel/Devices/MBVGADevice.cpp @@ -82,12 +82,12 @@ int MBVGADevice::ioctl(FileDescription&, unsigned request, unsigned arg) }; } -bool MBVGADevice::can_read(FileDescription&) const +bool MBVGADevice::can_read(const FileDescription&) const { ASSERT_NOT_REACHED(); } -bool MBVGADevice::can_write(FileDescription&) const +bool MBVGADevice::can_write(const FileDescription&) const { ASSERT_NOT_REACHED(); } diff --git a/Kernel/Devices/MBVGADevice.h b/Kernel/Devices/MBVGADevice.h index 2c46b8296fa..a7980a1fcb3 100644 --- a/Kernel/Devices/MBVGADevice.h +++ b/Kernel/Devices/MBVGADevice.h @@ -17,8 +17,8 @@ public: private: virtual const char* class_name() const override { return "MBVGA"; } - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; diff --git a/Kernel/Devices/NullDevice.cpp b/Kernel/Devices/NullDevice.cpp index b4fa429219f..e91a3cd68c8 100644 --- a/Kernel/Devices/NullDevice.cpp +++ b/Kernel/Devices/NullDevice.cpp @@ -20,7 +20,7 @@ NullDevice::~NullDevice() { } -bool NullDevice::can_read(FileDescription&) const +bool NullDevice::can_read(const FileDescription&) const { return true; } diff --git a/Kernel/Devices/NullDevice.h b/Kernel/Devices/NullDevice.h index 822e61508db..84e0a8fc020 100644 --- a/Kernel/Devices/NullDevice.h +++ b/Kernel/Devices/NullDevice.h @@ -14,7 +14,7 @@ private: // ^CharacterDevice virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; - virtual bool can_write(FileDescription&) const override { return true; } - virtual bool can_read(FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override; virtual const char* class_name() const override { return "NullDevice"; } }; diff --git a/Kernel/Devices/PATADiskDevice.h b/Kernel/Devices/PATADiskDevice.h index 0dbf1b4afe4..56beb60f881 100644 --- a/Kernel/Devices/PATADiskDevice.h +++ b/Kernel/Devices/PATADiskDevice.h @@ -36,9 +36,9 @@ public: // ^BlockDevice virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; } - virtual bool can_read(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override { return true; } virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return 0; } - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } protected: explicit PATADiskDevice(PATAChannel&, DriveType, int, int); diff --git a/Kernel/Devices/PS2MouseDevice.cpp b/Kernel/Devices/PS2MouseDevice.cpp index 2fa2822df04..2cacdc85d4f 100644 --- a/Kernel/Devices/PS2MouseDevice.cpp +++ b/Kernel/Devices/PS2MouseDevice.cpp @@ -255,7 +255,7 @@ u8 PS2MouseDevice::mouse_read() return IO::in8(I8042_BUFFER); } -bool PS2MouseDevice::can_read(FileDescription&) const +bool PS2MouseDevice::can_read(const FileDescription&) const { return !m_queue.is_empty(); } diff --git a/Kernel/Devices/PS2MouseDevice.h b/Kernel/Devices/PS2MouseDevice.h index c16cb6eb67b..180fae48f13 100644 --- a/Kernel/Devices/PS2MouseDevice.h +++ b/Kernel/Devices/PS2MouseDevice.h @@ -14,10 +14,10 @@ public: static PS2MouseDevice& the(); // ^CharacterDevice - virtual bool can_read(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } private: // ^IRQHandler diff --git a/Kernel/Devices/RandomDevice.cpp b/Kernel/Devices/RandomDevice.cpp index 5fcd4ace1a3..9df6a2c23ac 100644 --- a/Kernel/Devices/RandomDevice.cpp +++ b/Kernel/Devices/RandomDevice.cpp @@ -26,7 +26,7 @@ static void mysrand(unsigned seed) } #endif -bool RandomDevice::can_read(FileDescription&) const +bool RandomDevice::can_read(const FileDescription&) const { return true; } diff --git a/Kernel/Devices/RandomDevice.h b/Kernel/Devices/RandomDevice.h index b1a3e7b0d4e..a11589d310d 100644 --- a/Kernel/Devices/RandomDevice.h +++ b/Kernel/Devices/RandomDevice.h @@ -14,7 +14,7 @@ private: // ^CharacterDevice virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override { return true; } virtual const char* class_name() const override { return "RandomDevice"; } }; diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp index e376b17f7e0..0ec3b382450 100644 --- a/Kernel/Devices/SB16.cpp +++ b/Kernel/Devices/SB16.cpp @@ -84,7 +84,7 @@ void SB16::initialize() enable_irq(); } -bool SB16::can_read(FileDescription&) const +bool SB16::can_read(const FileDescription&) const { return false; } diff --git a/Kernel/Devices/SB16.h b/Kernel/Devices/SB16.h index d91de1c2d4d..63d54569b86 100644 --- a/Kernel/Devices/SB16.h +++ b/Kernel/Devices/SB16.h @@ -17,10 +17,10 @@ public: static SB16& the(); // ^CharacterDevice - virtual bool can_read(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } private: // ^IRQHandler diff --git a/Kernel/Devices/SerialDevice.cpp b/Kernel/Devices/SerialDevice.cpp index 7f555ae8072..95183915cb4 100644 --- a/Kernel/Devices/SerialDevice.cpp +++ b/Kernel/Devices/SerialDevice.cpp @@ -12,7 +12,7 @@ SerialDevice::~SerialDevice() { } -bool SerialDevice::can_read(FileDescription&) const +bool SerialDevice::can_read(const FileDescription&) const { return (get_line_status() & DataReady) != 0; } @@ -30,7 +30,7 @@ ssize_t SerialDevice::read(FileDescription&, u8* buffer, ssize_t size) return 1; } -bool SerialDevice::can_write(FileDescription&) const +bool SerialDevice::can_write(const FileDescription&) const { return (get_line_status() & EmptyTransmitterHoldingRegister) != 0; } diff --git a/Kernel/Devices/SerialDevice.h b/Kernel/Devices/SerialDevice.h index 78706e1be84..d6ac9e0cfcf 100644 --- a/Kernel/Devices/SerialDevice.h +++ b/Kernel/Devices/SerialDevice.h @@ -12,9 +12,9 @@ public: virtual ~SerialDevice() override; // ^CharacterDevice - virtual bool can_read(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; enum InterruptEnable { diff --git a/Kernel/Devices/ZeroDevice.cpp b/Kernel/Devices/ZeroDevice.cpp index cfb3e3b4c36..352541a3cc2 100644 --- a/Kernel/Devices/ZeroDevice.cpp +++ b/Kernel/Devices/ZeroDevice.cpp @@ -11,7 +11,7 @@ ZeroDevice::~ZeroDevice() { } -bool ZeroDevice::can_read(FileDescription&) const +bool ZeroDevice::can_read(const FileDescription&) const { return true; } diff --git a/Kernel/Devices/ZeroDevice.h b/Kernel/Devices/ZeroDevice.h index 42ceff3abe9..f6df9bf0a05 100644 --- a/Kernel/Devices/ZeroDevice.h +++ b/Kernel/Devices/ZeroDevice.h @@ -12,7 +12,7 @@ private: // ^CharacterDevice virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override { return true; } virtual const char* class_name() const override { return "ZeroDevice"; } }; diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp index 6fc77a7b2bf..390a05d16fd 100644 --- a/Kernel/FileSystem/FIFO.cpp +++ b/Kernel/FileSystem/FIFO.cpp @@ -83,12 +83,12 @@ void FIFO::detach(Direction direction) } } -bool FIFO::can_read(FileDescription&) const +bool FIFO::can_read(const FileDescription&) const { return !m_buffer.is_empty() || !m_writers; } -bool FIFO::can_write(FileDescription&) const +bool FIFO::can_write(const FileDescription&) const { return m_buffer.bytes_in_write_buffer() < 4096 || !m_readers; } diff --git a/Kernel/FileSystem/FIFO.h b/Kernel/FileSystem/FIFO.h index 77c5427ba2e..2869545fe66 100644 --- a/Kernel/FileSystem/FIFO.h +++ b/Kernel/FileSystem/FIFO.h @@ -30,8 +30,8 @@ private: // ^File virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override; - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual String absolute_path(const FileDescription&) const override; virtual const char* class_name() const override { return "FIFO"; } virtual bool is_fifo() const override { return true; } diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index 4f838f93351..36d468f4421 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -46,8 +46,8 @@ public: virtual KResultOr> open(int options); virtual void close(); - virtual bool can_read(FileDescription&) const = 0; - virtual bool can_write(FileDescription&) const = 0; + virtual bool can_read(const FileDescription&) const = 0; + virtual bool can_write(const FileDescription&) const = 0; virtual ssize_t read(FileDescription&, u8*, ssize_t) = 0; virtual ssize_t write(FileDescription&, const u8*, ssize_t) = 0; diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index 3b99620018b..cb5e6c27175 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -121,14 +121,12 @@ ssize_t FileDescription::write(const u8* data, ssize_t size) bool FileDescription::can_write() const { - // FIXME: Remove this const_cast. - return m_file->can_write(const_cast(*this)); + return m_file->can_write(*this); } bool FileDescription::can_read() const { - // FIXME: Remove this const_cast. - return m_file->can_read(const_cast(*this)); + return m_file->can_read(*this); } ByteBuffer FileDescription::read_entire_file() diff --git a/Kernel/FileSystem/InodeFile.h b/Kernel/FileSystem/InodeFile.h index b2ee30c1969..c7def9be459 100644 --- a/Kernel/FileSystem/InodeFile.h +++ b/Kernel/FileSystem/InodeFile.h @@ -16,8 +16,8 @@ public: const Inode& inode() const { return *m_inode; } Inode& inode() { return *m_inode; } - virtual bool can_read(FileDescription&) const override { return true; } - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp index 9a5e3840959..797683535c9 100644 --- a/Kernel/FileSystem/InodeWatcher.cpp +++ b/Kernel/FileSystem/InodeWatcher.cpp @@ -18,12 +18,12 @@ InodeWatcher::~InodeWatcher() safe_inode->unregister_watcher({}, *this); } -bool InodeWatcher::can_read(FileDescription&) const +bool InodeWatcher::can_read(const FileDescription&) const { return !m_queue.is_empty() || !m_inode; } -bool InodeWatcher::can_write(FileDescription&) const +bool InodeWatcher::can_write(const FileDescription&) const { return true; } diff --git a/Kernel/FileSystem/InodeWatcher.h b/Kernel/FileSystem/InodeWatcher.h index e4091429f24..62cf5ee9153 100644 --- a/Kernel/FileSystem/InodeWatcher.h +++ b/Kernel/FileSystem/InodeWatcher.h @@ -21,8 +21,8 @@ public: Type type { Type::Invalid }; }; - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; virtual String absolute_path(const FileDescription&) const override; diff --git a/Kernel/FileSystem/SharedMemory.h b/Kernel/FileSystem/SharedMemory.h index d7848b97983..f81c3296958 100644 --- a/Kernel/FileSystem/SharedMemory.h +++ b/Kernel/FileSystem/SharedMemory.h @@ -24,8 +24,8 @@ public: private: // ^File - virtual bool can_read(FileDescription&) const override { return true; } - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } virtual int read(FileDescription&, u8*, int) override; virtual int write(FileDescription&, const u8*, int) override; virtual String absolute_path(const FileDescription&) const override; diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 1385ae80b93..2e4dd1344bc 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -144,7 +144,7 @@ void IPv4Socket::detach(FileDescription&) { } -bool IPv4Socket::can_read(FileDescription&) const +bool IPv4Socket::can_read(const FileDescription&) const { if (m_role == Role::Listener) return can_accept(); @@ -153,7 +153,7 @@ bool IPv4Socket::can_read(FileDescription&) const return m_can_read; } -bool IPv4Socket::can_write(FileDescription&) const +bool IPv4Socket::can_write(const FileDescription&) const { return is_connected(); } @@ -282,9 +282,13 @@ ssize_t IPv4Socket::recvfrom(FileDescription& description, void* buffer, size_t return protocol_receive(packet.data.value(), buffer, buffer_length, flags); } -void IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, KBuffer&& packet) +bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, KBuffer&& packet) { LOCKER(lock()); + if (m_receive_queue.size_slow() > 2000) { + kprintf("IPv4Socket(%p): did_receive refusing packet since queue is full.\n", this); + return false; + } auto packet_size = packet.size(); m_receive_queue.append({ source_address, source_port, move(packet) }); m_can_read = true; @@ -292,6 +296,7 @@ void IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, #ifdef IPV4_SOCKET_DEBUG kprintf("IPv4Socket(%p): did_receive %d bytes, total_received=%u, packets in queue: %d\n", this, packet_size, m_bytes_received, m_receive_queue.size_slow()); #endif + return true; } String IPv4Socket::absolute_path(const FileDescription&) const diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h index ff59ae3831b..5c887ae2d64 100644 --- a/Kernel/Net/IPv4Socket.h +++ b/Kernel/Net/IPv4Socket.h @@ -27,8 +27,8 @@ public: virtual bool get_peer_address(sockaddr*, socklen_t*) override; virtual void attach(FileDescription&) override; virtual void detach(FileDescription&) override; - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual ssize_t sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override; virtual ssize_t recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override; virtual KResult setsockopt(int level, int option, const void*, socklen_t) override; @@ -36,7 +36,7 @@ public: virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override; - void did_receive(const IPv4Address& peer_address, u16 peer_port, KBuffer&&); + bool did_receive(const IPv4Address& peer_address, u16 peer_port, KBuffer&&); const IPv4Address& local_address() const { return m_local_address; } u16 local_port() const { return m_local_port; } diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 542daada86e..6f16fed2f53 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -186,7 +186,7 @@ void LocalSocket::detach(FileDescription& description) } } -bool LocalSocket::can_read(FileDescription& description) const +bool LocalSocket::can_read(const FileDescription& description) const { auto role = this->role(description); if (role == Role::Listener) @@ -208,7 +208,7 @@ bool LocalSocket::has_attached_peer(const FileDescription& description) const ASSERT_NOT_REACHED(); } -bool LocalSocket::can_write(FileDescription& description) const +bool LocalSocket::can_write(const FileDescription& description) const { auto role = this->role(description); if (role == Role::Accepted) diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h index 2a6ee5bd2be..bd529933f1b 100644 --- a/Kernel/Net/LocalSocket.h +++ b/Kernel/Net/LocalSocket.h @@ -25,8 +25,8 @@ public: virtual bool get_peer_address(sockaddr*, socklen_t*) override; virtual void attach(FileDescription&) override; virtual void detach(FileDescription&) override; - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual ssize_t sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override; virtual ssize_t recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override; diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 1799c6ac98c..c6ae7bfaf7e 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -574,9 +574,12 @@ void handle_tcp(const IPv4Packet& ipv4_packet) socket->sequence_number()); #endif - socket->send_tcp_packet(TCPFlags::ACK); + bool should_ack = true; + if (payload_size != 0) { + should_ack = socket->did_receive(ipv4_packet.source(), tcp_packet.source_port(), KBuffer::copy(&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size())); + } - if (payload_size != 0) - socket->did_receive(ipv4_packet.source(), tcp_packet.source_port(), KBuffer::copy(&ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size())); + if (should_ack) + socket->send_tcp_packet(TCPFlags::ACK); } } diff --git a/Kernel/ProcessTracer.h b/Kernel/ProcessTracer.h index cfde92d2f82..5c769f6cfd5 100644 --- a/Kernel/ProcessTracer.h +++ b/Kernel/ProcessTracer.h @@ -12,10 +12,10 @@ public: bool is_dead() const { return m_dead; } void set_dead() { m_dead = true; } - virtual bool can_read(FileDescription&) const override { return !m_calls.is_empty() || m_dead; } + virtual bool can_read(const FileDescription&) const override { return !m_calls.is_empty() || m_dead; } virtual int read(FileDescription&, u8*, int) override; - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } virtual int write(FileDescription&, const u8*, int) override { return -EIO; } virtual String absolute_path(const FileDescription&) const override; diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index efd29a7f27c..dc46506ce84 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -46,14 +46,14 @@ ssize_t MasterPTY::write(FileDescription&, const u8* buffer, ssize_t size) return size; } -bool MasterPTY::can_read(FileDescription&) const +bool MasterPTY::can_read(const FileDescription&) const { if (!m_slave) return true; return !m_buffer.is_empty(); } -bool MasterPTY::can_write(FileDescription&) const +bool MasterPTY::can_write(const FileDescription&) const { return true; } diff --git a/Kernel/TTY/MasterPTY.h b/Kernel/TTY/MasterPTY.h index dbc4f46bffa..e3246dfd6aa 100644 --- a/Kernel/TTY/MasterPTY.h +++ b/Kernel/TTY/MasterPTY.h @@ -24,8 +24,8 @@ private: // ^CharacterDevice virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual void close() override; virtual bool is_master_pty() const override { return true; } virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override; diff --git a/Kernel/TTY/PTYMultiplexer.h b/Kernel/TTY/PTYMultiplexer.h index a51520298b2..cc8ffd5b510 100644 --- a/Kernel/TTY/PTYMultiplexer.h +++ b/Kernel/TTY/PTYMultiplexer.h @@ -18,8 +18,8 @@ public: virtual KResultOr> open(int options) override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; } virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return 0; } - virtual bool can_read(FileDescription&) const override { return true; } - virtual bool can_write(FileDescription&) const override { return true; } + virtual bool can_read(const FileDescription&) const override { return true; } + virtual bool can_write(const FileDescription&) const override { return true; } void notify_master_destroyed(Badge, unsigned index); diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp index 23a0378d1df..ce5461175b4 100644 --- a/Kernel/TTY/SlavePTY.cpp +++ b/Kernel/TTY/SlavePTY.cpp @@ -48,12 +48,12 @@ ssize_t SlavePTY::on_tty_write(const u8* data, ssize_t size) return m_master->on_slave_write(data, size); } -bool SlavePTY::can_write(FileDescription&) const +bool SlavePTY::can_write(const FileDescription&) const { return m_master->can_write_from_slave(); } -bool SlavePTY::can_read(FileDescription& description) const +bool SlavePTY::can_read(const FileDescription& description) const { if (m_master->is_closed()) return true; diff --git a/Kernel/TTY/SlavePTY.h b/Kernel/TTY/SlavePTY.h index 0659079acf2..9417b0e24df 100644 --- a/Kernel/TTY/SlavePTY.h +++ b/Kernel/TTY/SlavePTY.h @@ -19,9 +19,9 @@ private: virtual void echo(u8) override; // ^CharacterDevice - virtual bool can_read(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; virtual ssize_t read(FileDescription&, u8*, ssize_t) override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual const char* class_name() const override { return "SlavePTY"; } virtual void close() override; diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index a7777e43204..0e45e694399 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -68,7 +68,7 @@ ssize_t TTY::write(FileDescription&, const u8* buffer, ssize_t size) return size; } -bool TTY::can_read(FileDescription&) const +bool TTY::can_read(const FileDescription&) const { if (in_canonical_mode()) { return m_available_lines > 0; @@ -76,7 +76,7 @@ bool TTY::can_read(FileDescription&) const return !m_input_buffer.is_empty(); } -bool TTY::can_write(FileDescription&) const +bool TTY::can_write(const FileDescription&) const { return true; } diff --git a/Kernel/TTY/TTY.h b/Kernel/TTY/TTY.h index 2d4420bf34c..6e7513b9ada 100644 --- a/Kernel/TTY/TTY.h +++ b/Kernel/TTY/TTY.h @@ -13,8 +13,8 @@ public: virtual ssize_t read(FileDescription&, u8*, ssize_t) override; virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; - virtual bool can_read(FileDescription&) const override; - virtual bool can_write(FileDescription&) const override; + virtual bool can_read(const FileDescription&) const override; + virtual bool can_write(const FileDescription&) const override; virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override final; virtual String absolute_path(const FileDescription&) const override { return tty_name(); }