summaryrefslogtreecommitdiff
path: root/Kernel/Net/Socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/Net/Socket.cpp')
-rw-r--r--Kernel/Net/Socket.cpp50
1 files changed, 28 insertions, 22 deletions
diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp
index 9ae1585b94..f5e8357a70 100644
--- a/Kernel/Net/Socket.cpp
+++ b/Kernel/Net/Socket.cpp
@@ -100,7 +100,9 @@ ErrorOr<void> Socket::setsockopt(int level, int option, Userspace<void const*> u
auto device = NetworkingManagement::the().lookup_by_name(ifname->view());
if (!device)
return ENODEV;
- m_bound_interface = move(device);
+ m_bound_interface.with([&device](auto& bound_device) {
+ bound_device = move(device);
+ });
return {};
}
case SO_DEBUG:
@@ -169,31 +171,35 @@ ErrorOr<void> Socket::getsockopt(OpenFileDescription&, int level, int option, Us
case SO_ERROR: {
if (size < sizeof(int))
return EINVAL;
- int errno = 0;
- if (auto const& error = so_error(); error.has_value())
- errno = error.value();
- TRY(copy_to_user(static_ptr_cast<int*>(value), &errno));
- size = sizeof(int);
- TRY(copy_to_user(value_size, &size));
- clear_so_error();
- return {};
+ return so_error().with([&size, value, value_size](auto& error) -> ErrorOr<void> {
+ int errno = 0;
+ if (error.has_value())
+ errno = error.value();
+ TRY(copy_to_user(static_ptr_cast<int*>(value), &errno));
+ size = sizeof(int);
+ TRY(copy_to_user(value_size, &size));
+ error = {};
+ return {};
+ });
}
case SO_BINDTODEVICE:
if (size < IFNAMSIZ)
return EINVAL;
- if (m_bound_interface) {
- auto name = m_bound_interface->name();
- auto length = name.length() + 1;
- auto characters = name.characters_without_null_termination();
- TRY(copy_to_user(static_ptr_cast<char*>(value), characters, length));
- size = length;
- return copy_to_user(value_size, &size);
- } else {
- size = 0;
- TRY(copy_to_user(value_size, &size));
- // FIXME: This return value looks suspicious.
- return EFAULT;
- }
+ return m_bound_interface.with([&](auto& bound_device) -> ErrorOr<void> {
+ if (bound_device) {
+ auto name = bound_device->name();
+ auto length = name.length() + 1;
+ auto characters = name.characters_without_null_termination();
+ TRY(copy_to_user(static_ptr_cast<char*>(value), characters, length));
+ size = length;
+ return copy_to_user(value_size, &size);
+ } else {
+ size = 0;
+ TRY(copy_to_user(value_size, &size));
+ // FIXME: This return value looks suspicious.
+ return EFAULT;
+ }
+ });
case SO_TIMESTAMP:
if (size < sizeof(int))
return EINVAL;