mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 17:28:48 +00:00
Kernel: Add support for the MSG_WAITALL sys$recvmsg flag
This commit is contained in:
parent
5514d60d8d
commit
e521ffd156
Notes:
sideshowbarker
2024-07-17 23:10:44 +09:00
Author: https://github.com/IdanHo
Commit: e521ffd156
Pull-request: https://github.com/SerenityOS/serenity/pull/11152
Reviewed-by: https://github.com/awesomekling
3 changed files with 22 additions and 10 deletions
|
@ -53,6 +53,7 @@ extern "C" {
|
||||||
#define MSG_PEEK 0x4
|
#define MSG_PEEK 0x4
|
||||||
#define MSG_OOB 0x8
|
#define MSG_OOB 0x8
|
||||||
#define MSG_DONTROUTE 0x10
|
#define MSG_DONTROUTE 0x10
|
||||||
|
#define MSG_WAITALL 0x20
|
||||||
#define MSG_DONTWAIT 0x40
|
#define MSG_DONTWAIT 0x40
|
||||||
|
|
||||||
typedef uint16_t sa_family_t;
|
typedef uint16_t sa_family_t;
|
||||||
|
|
|
@ -391,15 +391,26 @@ ErrorOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKer
|
||||||
|
|
||||||
dbgln_if(IPV4_SOCKET_DEBUG, "recvfrom: type={}, local_port={}", type(), local_port());
|
dbgln_if(IPV4_SOCKET_DEBUG, "recvfrom: type={}, local_port={}", type(), local_port());
|
||||||
|
|
||||||
|
ErrorOr<size_t> total_nreceived = 0;
|
||||||
|
do {
|
||||||
|
auto offset_buffer = buffer.offset(total_nreceived.value());
|
||||||
|
auto offset_buffer_length = buffer_length - total_nreceived.value();
|
||||||
|
|
||||||
ErrorOr<size_t> nreceived = 0;
|
ErrorOr<size_t> nreceived = 0;
|
||||||
if (buffer_mode() == BufferMode::Bytes)
|
if (buffer_mode() == BufferMode::Bytes)
|
||||||
nreceived = receive_byte_buffered(description, buffer, buffer_length, flags, user_addr, user_addr_length);
|
nreceived = receive_byte_buffered(description, offset_buffer, offset_buffer_length, flags, user_addr, user_addr_length);
|
||||||
else
|
else
|
||||||
nreceived = receive_packet_buffered(description, buffer, buffer_length, flags, user_addr, user_addr_length, packet_timestamp);
|
nreceived = receive_packet_buffered(description, offset_buffer, offset_buffer_length, flags, user_addr, user_addr_length, packet_timestamp);
|
||||||
|
|
||||||
if (!nreceived.is_error())
|
if (nreceived.is_error())
|
||||||
Thread::current()->did_ipv4_socket_read(nreceived.value());
|
total_nreceived = nreceived;
|
||||||
return nreceived;
|
else
|
||||||
|
total_nreceived.value() += nreceived.value();
|
||||||
|
} while ((flags & MSG_WAITALL) && !total_nreceived.is_error() && total_nreceived.value() < buffer_length);
|
||||||
|
|
||||||
|
if (!total_nreceived.is_error())
|
||||||
|
Thread::current()->did_ipv4_socket_read(total_nreceived.value());
|
||||||
|
return total_nreceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, ReadonlyBytes packet, const Time& packet_timestamp)
|
bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, ReadonlyBytes packet, const Time& packet_timestamp)
|
||||||
|
|
|
@ -607,8 +607,8 @@ static void format_connect(FormattedSyscallBuilder& builder, int socket, const s
|
||||||
struct MsgOptions : BitflagBase {
|
struct MsgOptions : BitflagBase {
|
||||||
static constexpr auto options = {
|
static constexpr auto options = {
|
||||||
BITFLAG(MSG_TRUNC), BITFLAG(MSG_CTRUNC), BITFLAG(MSG_PEEK),
|
BITFLAG(MSG_TRUNC), BITFLAG(MSG_CTRUNC), BITFLAG(MSG_PEEK),
|
||||||
BITFLAG(MSG_OOB), BITFLAG(MSG_DONTROUTE), BITFLAG(MSG_DONTWAIT)
|
BITFLAG(MSG_OOB), BITFLAG(MSG_DONTROUTE), BITFLAG(MSG_WAITALL),
|
||||||
// TODO: add MSG_WAITALL once its definition is added
|
BITFLAG(MSG_DONTWAIT)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue