mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:27:35 +00:00
Kernel: Use TRY() in IPv4Socket
This commit is contained in:
parent
d65fbdc44d
commit
982991d92d
1 changed files with 6 additions and 17 deletions
|
@ -46,18 +46,10 @@ KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
|
||||||
if (!receive_buffer)
|
if (!receive_buffer)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
if (type == SOCK_STREAM) {
|
if (type == SOCK_STREAM)
|
||||||
auto tcp_socket_or_error = TCPSocket::try_create(protocol, receive_buffer.release_nonnull());
|
return TRY(TCPSocket::try_create(protocol, receive_buffer.release_nonnull()));
|
||||||
if (tcp_socket_or_error.is_error())
|
if (type == SOCK_DGRAM)
|
||||||
return tcp_socket_or_error.error();
|
return TRY(UDPSocket::try_create(protocol, receive_buffer.release_nonnull()));
|
||||||
return tcp_socket_or_error.release_value();
|
|
||||||
}
|
|
||||||
if (type == SOCK_DGRAM) {
|
|
||||||
auto udp_socket_or_error = UDPSocket::try_create(protocol, receive_buffer.release_nonnull());
|
|
||||||
if (udp_socket_or_error.is_error())
|
|
||||||
return udp_socket_or_error.error();
|
|
||||||
return udp_socket_or_error.release_value();
|
|
||||||
}
|
|
||||||
if (type == SOCK_RAW) {
|
if (type == SOCK_RAW) {
|
||||||
auto raw_socket = adopt_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol, receive_buffer.release_nonnull(), {}));
|
auto raw_socket = adopt_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol, receive_buffer.release_nonnull(), {}));
|
||||||
if (raw_socket)
|
if (raw_socket)
|
||||||
|
@ -593,11 +585,9 @@ KResult IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> a
|
||||||
return EFAULT;
|
return EFAULT;
|
||||||
|
|
||||||
Userspace<const char*> user_rt_dev((FlatPtr)route.rt_dev);
|
Userspace<const char*> user_rt_dev((FlatPtr)route.rt_dev);
|
||||||
auto ifname_or_error = try_copy_kstring_from_user(user_rt_dev, IFNAMSIZ);
|
auto ifname = TRY(try_copy_kstring_from_user(user_rt_dev, IFNAMSIZ));
|
||||||
if (ifname_or_error.is_error())
|
|
||||||
return ifname_or_error.error();
|
|
||||||
|
|
||||||
auto adapter = NetworkingManagement::the().lookup_by_name(ifname_or_error.value()->view());
|
auto adapter = NetworkingManagement::the().lookup_by_name(ifname->view());
|
||||||
if (!adapter)
|
if (!adapter)
|
||||||
return ENODEV;
|
return ENODEV;
|
||||||
|
|
||||||
|
@ -801,5 +791,4 @@ void IPv4Socket::set_can_read(bool value)
|
||||||
if (value)
|
if (value)
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue