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

Kernel: Make TCPSocket::create API OOM safe

Note that the changes to IPv4Socket::create are unfortunately needed as
the return type of TCPSocket::create and IPv4Socket::create don't match.

 - KResultOr<NonnullRefPtr<TcpSocket>>>
   vs
 - KResultOr<NonnullRefPtr<Socket>>>

To handle this we are forced to manually decompose the KResultOr<T> and
return the value() and error() separately.
This commit is contained in:
Brian Gianforcaro 2021-05-13 01:01:38 -07:00 committed by Andreas Kling
parent 9375f3dc09
commit 46ce7adf7b
3 changed files with 17 additions and 6 deletions

View file

@ -36,8 +36,12 @@ Lockable<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets()
KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
{
if (type == SOCK_STREAM)
return TCPSocket::create(protocol);
if (type == SOCK_STREAM) {
auto tcp_socket = TCPSocket::create(protocol);
if (tcp_socket.is_error())
return tcp_socket.error();
return tcp_socket.release_value();
}
if (type == SOCK_DGRAM)
return UDPSocket::create(protocol);
if (type == SOCK_RAW)