1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

Kernel: More sockets work. Fleshing out accept().

This commit is contained in:
Andreas Kling 2019-02-14 15:17:30 +01:00
parent 1d66670ad7
commit 54b1d6f57f
7 changed files with 103 additions and 9 deletions

View file

@ -8,7 +8,7 @@ RetainPtr<Socket> Socket::create(int domain, int type, int protocol, int& error)
(void)protocol;
switch (domain) {
case AF_LOCAL:
return LocalSocket::create(type);
return LocalSocket::create(type & SOCK_TYPE_MASK);
default:
error = EAFNOSUPPORT;
return nullptr;
@ -26,4 +26,25 @@ Socket::~Socket()
{
}
bool Socket::listen(int backlog, int& error)
{
LOCKER(m_lock);
if (m_type != SOCK_STREAM) {
error = -EOPNOTSUPP;
return false;
}
m_backlog = backlog;
m_listening = true;
kprintf("Socket{%p} listening with backlog=%d\n", m_backlog);
return true;
}
RetainPtr<Socket> Socket::accept()
{
LOCKER(m_lock);
if (m_pending.is_empty())
return nullptr;
auto client = m_pending.take_first();
m_clients.append(client.copy_ref());
return client;
}