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

Kernel: Properly implement SO_ERROR option

This fixes the placeholder stub for the SO_ERROR via getsockopt. It
leverages the m_so_error value that each socket maintains. The SO_ERROR
option obtains and then clears this field, which is useful when checking
for errors that occur between socket calls. This uses an integer value
to return the SO_ERROR status.

Resolves #146
This commit is contained in:
brapru 2021-08-01 16:36:28 -04:00 committed by Andreas Kling
parent 0095c7cb7d
commit 342e1f0a84
2 changed files with 3 additions and 5 deletions

View file

@ -343,9 +343,8 @@ KResultOr<size_t> LocalSocket::recvfrom(FileDescription& description, UserOrKern
} }
} else if (!can_read(description, 0)) { } else if (!can_read(description, 0)) {
auto unblock_flags = Thread::FileDescriptionBlocker::BlockFlags::None; auto unblock_flags = Thread::FileDescriptionBlocker::BlockFlags::None;
if (Thread::current()->block<Thread::ReadBlocker>({}, description, unblock_flags).was_interrupted()) { if (Thread::current()->block<Thread::ReadBlocker>({}, description, unblock_flags).was_interrupted())
return set_so_error(EINTR); return set_so_error(EINTR);
}
} }
if (!has_attached_peer(description) && socket_buffer->is_empty()) if (!has_attached_peer(description) && socket_buffer->is_empty())
return 0; return 0;

View file

@ -181,14 +181,13 @@ KResult Socket::getsockopt(FileDescription&, int level, int option, Userspace<vo
case SO_ERROR: { case SO_ERROR: {
if (size < sizeof(int)) if (size < sizeof(int))
return EINVAL; return EINVAL;
dbgln("getsockopt(SO_ERROR): FIXME!"); int errno = so_error().error();
int errno = 0;
if (!copy_to_user(static_ptr_cast<int*>(value), &errno)) if (!copy_to_user(static_ptr_cast<int*>(value), &errno))
return EFAULT; return EFAULT;
size = sizeof(int); size = sizeof(int);
if (!copy_to_user(value_size, &size)) if (!copy_to_user(value_size, &size))
return EFAULT; return EFAULT;
return KSuccess; return set_so_error(KSuccess);
} }
case SO_BINDTODEVICE: case SO_BINDTODEVICE:
if (size < IFNAMSIZ) if (size < IFNAMSIZ)