1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:58:12 +00:00

Kernel: Handle OOM from DoubleBuffer usage in IPv4Socket

The IPv4Socket requires a DoubleBuffer for storage of any data it
received on the socket. However it was previously using the default
constructor which can not observe allocation failure. Address this by
plumbing the receive buffer through the various derived classes.
This commit is contained in:
Brian Gianforcaro 2021-08-01 02:42:03 -07:00 committed by Andreas Kling
parent 109c885585
commit ca94a83337
6 changed files with 41 additions and 26 deletions

View file

@ -43,8 +43,8 @@ SocketHandle<UDPSocket> UDPSocket::from_port(u16 port)
return { *socket };
}
UDPSocket::UDPSocket(int protocol)
: IPv4Socket(SOCK_DGRAM, protocol)
UDPSocket::UDPSocket(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer)
: IPv4Socket(SOCK_DGRAM, protocol, move(receive_buffer))
{
}
@ -54,9 +54,9 @@ UDPSocket::~UDPSocket()
sockets_by_port().resource().remove(local_port());
}
KResultOr<NonnullRefPtr<UDPSocket>> UDPSocket::create(int protocol)
KResultOr<NonnullRefPtr<UDPSocket>> UDPSocket::create(int protocol, NonnullOwnPtr<DoubleBuffer> receive_buffer)
{
auto socket = adopt_ref_if_nonnull(new (nothrow) UDPSocket(protocol));
auto socket = adopt_ref_if_nonnull(new (nothrow) UDPSocket(protocol, move(receive_buffer)));
if (socket)
return socket.release_nonnull();
return ENOMEM;