Kernel/LibC: Implement FIONREAD for tcp and udp sockets
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user