Kernel/LibC: Implement socketpair for UNIX sockets

This commit is contained in:
2025-05-27 07:09:04 +03:00
parent 12b93567f7
commit 89c9bfd052
9 changed files with 98 additions and 17 deletions

View File

@@ -129,6 +129,25 @@ namespace Kernel
return socket;
}
BAN::ErrorOr<void> NetworkManager::connect_sockets(Socket::Domain domain, BAN::RefPtr<Socket> socket1, BAN::RefPtr<Socket> socket2)
{
switch (domain)
{
case Socket::Domain::UNIX:
{
auto* usocket1 = static_cast<UnixDomainSocket*>(socket1.ptr());
auto* usocket2 = static_cast<UnixDomainSocket*>(socket2.ptr());
TRY(usocket1->make_socket_pair(*usocket2));
break;
}
default:
dwarnln("TODO: connect {} domain sockets", static_cast<int>(domain));
return BAN::Error::from_errno(ENOTSUP);
}
return {};
}
void NetworkManager::on_receive(NetworkInterface& interface, BAN::ConstByteSpan packet)
{
if (packet.size() < sizeof(EthernetHeader))

View File

@@ -69,6 +69,20 @@ namespace Kernel
}
}
BAN::ErrorOr<void> UnixDomainSocket::make_socket_pair(UnixDomainSocket& other)
{
if (!m_info.has<ConnectionInfo>() || !other.m_info.has<ConnectionInfo>())
return BAN::Error::from_errno(EINVAL);
TRY(this->get_weak_ptr());
TRY(other.get_weak_ptr());
this->m_info.get<ConnectionInfo>().connection = MUST(other.get_weak_ptr());
other.m_info.get<ConnectionInfo>().connection = MUST(this->get_weak_ptr());
return {};
}
BAN::ErrorOr<long> UnixDomainSocket::accept_impl(sockaddr* address, socklen_t* address_len, int flags)
{
if (!m_info.has<ConnectionInfo>())