Kernel: Unix domain sockets close can now be detected
When a unix domain socket is closed and it has a connection to another socket, it will make the other socket readable and recv will return 0. This allows detection of socket closing
This commit is contained in:
parent
f12ffa92a0
commit
446220494e
|
@ -46,6 +46,7 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
bool listening { false };
|
bool listening { false };
|
||||||
BAN::Atomic<bool> connection_done { false };
|
BAN::Atomic<bool> connection_done { false };
|
||||||
|
mutable BAN::Atomic<bool> target_closed { false };
|
||||||
BAN::WeakPtr<UnixDomainSocket> connection;
|
BAN::WeakPtr<UnixDomainSocket> connection;
|
||||||
BAN::Queue<BAN::RefPtr<UnixDomainSocket>> pending_connections;
|
BAN::Queue<BAN::RefPtr<UnixDomainSocket>> pending_connections;
|
||||||
Semaphore pending_semaphore;
|
Semaphore pending_semaphore;
|
||||||
|
|
|
@ -55,7 +55,15 @@ namespace Kernel
|
||||||
auto it = s_bound_sockets.find(m_bound_path);
|
auto it = s_bound_sockets.find(m_bound_path);
|
||||||
if (it != s_bound_sockets.end())
|
if (it != s_bound_sockets.end())
|
||||||
s_bound_sockets.remove(it);
|
s_bound_sockets.remove(it);
|
||||||
|
m_bound_path.clear();
|
||||||
}
|
}
|
||||||
|
if (m_info.has<ConnectionInfo>())
|
||||||
|
{
|
||||||
|
auto& connection_info = m_info.get<ConnectionInfo>();
|
||||||
|
if (auto connection = connection_info.connection.lock(); connection && connection->m_info.has<ConnectionInfo>())
|
||||||
|
connection->m_info.get<ConnectionInfo>().target_closed = true;
|
||||||
|
}
|
||||||
|
m_info.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<long> UnixDomainSocket::accept_impl(sockaddr* address, socklen_t* address_len)
|
BAN::ErrorOr<long> UnixDomainSocket::accept_impl(sockaddr* address, socklen_t* address_len)
|
||||||
|
@ -256,6 +264,8 @@ namespace Kernel
|
||||||
if (m_info.has<ConnectionInfo>())
|
if (m_info.has<ConnectionInfo>())
|
||||||
{
|
{
|
||||||
auto& connection_info = m_info.get<ConnectionInfo>();
|
auto& connection_info = m_info.get<ConnectionInfo>();
|
||||||
|
if (connection_info.target_closed)
|
||||||
|
return true;
|
||||||
if (!connection_info.pending_connections.empty())
|
if (!connection_info.pending_connections.empty())
|
||||||
return true;
|
return true;
|
||||||
if (!connection_info.connection)
|
if (!connection_info.connection)
|
||||||
|
@ -338,6 +348,8 @@ namespace Kernel
|
||||||
if (m_info.has<ConnectionInfo>())
|
if (m_info.has<ConnectionInfo>())
|
||||||
{
|
{
|
||||||
auto& connection_info = m_info.get<ConnectionInfo>();
|
auto& connection_info = m_info.get<ConnectionInfo>();
|
||||||
|
if (connection_info.target_closed.compare_exchange(true, false))
|
||||||
|
return 0;
|
||||||
if (!connection_info.connection)
|
if (!connection_info.connection)
|
||||||
return BAN::Error::from_errno(ENOTCONN);
|
return BAN::Error::from_errno(ENOTCONN);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue