diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-14 15:17:30 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-14 15:17:30 +0100 |
commit | 54b1d6f57fe52de11701e96461a19fd2750fd2d4 (patch) | |
tree | 952cec4305680d4e65fb6200106ef126e5d9ce0f /Kernel/Socket.cpp | |
parent | 1d66670ad7add1e9e9073413136fc48528c90157 (diff) | |
download | serenity-54b1d6f57fe52de11701e96461a19fd2750fd2d4.zip |
Kernel: More sockets work. Fleshing out accept().
Diffstat (limited to 'Kernel/Socket.cpp')
-rw-r--r-- | Kernel/Socket.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Kernel/Socket.cpp b/Kernel/Socket.cpp index 44e11c3753..18fb351779 100644 --- a/Kernel/Socket.cpp +++ b/Kernel/Socket.cpp @@ -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; +} |