1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-21 14:45:07 +00:00

Kernel: Store socket errors as errno codes rather than ErrorOr values

This commit is contained in:
Timothy Flynn 2023-02-09 12:57:19 -05:00 committed by Linus Groh
parent d32961777b
commit bd4bddf31b
2 changed files with 11 additions and 11 deletions

View file

@ -169,11 +169,9 @@ ErrorOr<void> Socket::getsockopt(OpenFileDescription&, int level, int option, Us
case SO_ERROR: { case SO_ERROR: {
if (size < sizeof(int)) if (size < sizeof(int))
return EINVAL; return EINVAL;
int errno; int errno = 0;
if (so_error().is_error()) if (auto const& error = so_error(); error.has_value())
errno = so_error().error().code(); errno = error.value();
else
errno = 0;
TRY(copy_to_user(static_ptr_cast<int*>(value), &errno)); TRY(copy_to_user(static_ptr_cast<int*>(value), &errno));
size = sizeof(int); size = sizeof(int);
TRY(copy_to_user(value_size, &size)); TRY(copy_to_user(value_size, &size));

View file

@ -124,7 +124,7 @@ protected:
Role m_role { Role::None }; Role m_role { Role::None };
ErrorOr<void> so_error() const Optional<ErrnoCode> const& so_error() const
{ {
VERIFY(m_mutex.is_exclusively_locked_by_current_thread()); VERIFY(m_mutex.is_exclusively_locked_by_current_thread());
return m_so_error; return m_so_error;
@ -133,14 +133,16 @@ protected:
Error set_so_error(ErrnoCode error_code) Error set_so_error(ErrnoCode error_code)
{ {
MutexLocker locker(mutex()); MutexLocker locker(mutex());
auto error = Error::from_errno(error_code); m_so_error = error_code;
m_so_error = error;
return error; return Error::from_errno(error_code);
} }
Error set_so_error(Error error) Error set_so_error(Error error)
{ {
MutexLocker locker(mutex()); MutexLocker locker(mutex());
m_so_error = error; m_so_error = static_cast<ErrnoCode>(error.code());
return error; return error;
} }
@ -178,7 +180,7 @@ private:
Time m_send_timeout {}; Time m_send_timeout {};
int m_timestamp { 0 }; int m_timestamp { 0 };
ErrorOr<void> m_so_error; Optional<ErrnoCode> m_so_error;
NonnullLockRefPtrVector<Socket> m_pending; NonnullLockRefPtrVector<Socket> m_pending;
}; };