Kernel/LibC: Implement FIONREAD for tcp and udp sockets

This commit is contained in:
2025-08-08 01:14:11 +03:00
parent 009b073892
commit 5b587d199e
5 changed files with 40 additions and 1 deletions

View File

@@ -8,6 +8,7 @@
#include <fcntl.h>
#include <netinet/in.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
namespace Kernel
{
@@ -255,6 +256,18 @@ namespace Kernel
return {};
}
BAN::ErrorOr<long> TCPSocket::ioctl_impl(int request, void* argument)
{
switch (request)
{
case FIONREAD:
*static_cast<int*>(argument) = m_recv_window.data_size;
return 0;
}
return NetworkSocket::ioctl_impl(request, argument);
}
bool TCPSocket::can_read_impl() const
{
if (m_has_connected && !m_has_sent_zero && m_state != State::Established && m_state != State::Listen)

View File

@@ -4,6 +4,7 @@
#include <kernel/Thread.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
namespace Kernel
{
@@ -138,4 +139,22 @@ namespace Kernel
return TRY(m_network_layer.sendto(*this, message, address, address_len));
}
BAN::ErrorOr<long> UDPSocket::ioctl_impl(int request, void* argument)
{
switch (request)
{
case FIONREAD:
{
SpinLockGuard guard(m_packet_lock);
if (m_packets.empty())
*static_cast<int*>(argument) = 0;
else
*static_cast<int*>(argument) = m_packets.front().packet_size;
return 0;
}
}
return NetworkSocket::ioctl_impl(request, argument);
}
}