Kernel: Fix unix domain socket close detection

This commit is contained in:
Bananymous 2025-04-22 08:23:41 +03:00
parent 33a0f562d3
commit b853d29992
1 changed files with 13 additions and 10 deletions

View File

@ -60,7 +60,10 @@ namespace Kernel
{ {
auto& connection_info = m_info.get<ConnectionInfo>(); auto& connection_info = m_info.get<ConnectionInfo>();
if (auto connection = connection_info.connection.lock(); connection && connection->m_info.has<ConnectionInfo>()) if (auto connection = connection_info.connection.lock(); connection && connection->m_info.has<ConnectionInfo>())
{
connection->m_info.get<ConnectionInfo>().target_closed = true; connection->m_info.get<ConnectionInfo>().target_closed = true;
connection->m_packet_thread_blocker.unblock();
}
} }
} }
@ -350,6 +353,9 @@ namespace Kernel
} }
BAN::ErrorOr<size_t> UnixDomainSocket::recvfrom_impl(BAN::ByteSpan buffer, sockaddr*, socklen_t*) BAN::ErrorOr<size_t> UnixDomainSocket::recvfrom_impl(BAN::ByteSpan buffer, sockaddr*, socklen_t*)
{
auto state = m_packet_lock.lock();
while (m_packet_size_total == 0)
{ {
if (m_info.has<ConnectionInfo>()) if (m_info.has<ConnectionInfo>())
{ {
@ -361,9 +367,6 @@ namespace Kernel
return BAN::Error::from_errno(ENOTCONN); return BAN::Error::from_errno(ENOTCONN);
} }
auto state = m_packet_lock.lock();
while (m_packet_size_total == 0)
{
m_packet_lock.unlock(state); m_packet_lock.unlock(state);
TRY(Thread::current().block_or_eintr_indefinite(m_packet_thread_blocker)); TRY(Thread::current().block_or_eintr_indefinite(m_packet_thread_blocker));
state = m_packet_lock.lock(); state = m_packet_lock.lock();