diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 4c96a794b7..395c469f68 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2120,8 +2120,13 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a return -ENOTSOCK; auto& socket = *accepting_socket_description->socket(); if (!socket.can_accept()) { - ASSERT(!accepting_socket_description->is_blocking()); - return -EAGAIN; + if (accepting_socket_description->is_blocking()) { + current->block(Thread::State::BlockedAccept, *accepting_socket_description); + if (current->m_was_interrupted_while_blocked) + return -EINTR; + } else { + return -EAGAIN; + } } auto accepted_socket = socket.accept(); ASSERT(accepted_socket); diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 15b4b6f8f8..9041bbdaa2 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -137,6 +137,18 @@ bool Scheduler::pick_next() return IterationDecision::Continue; } + if (thread.state() == Thread::BlockedAccept) { + auto& description = *thread.m_blocked_description; + auto& socket = *description.socket(); + + if (socket.can_accept()) { + thread.unblock(); + return IterationDecision::Continue; + } + + return IterationDecision::Continue; + } + if (thread.state() == Thread::BlockedSelect) { if (thread.m_select_has_timeout) { if (now_sec > thread.m_select_timeout.tv_sec || (now_sec == thread.m_select_timeout.tv_sec && now_usec >= thread.m_select_timeout.tv_usec)) { diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 9ec9b838b1..1f1ef5fa41 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -179,6 +179,8 @@ const char* to_string(Thread::State state) return "Connect"; case Thread::BlockedReceive: return "Receive"; + case Thread::BlockedAccept: + return "Accepting"; case Thread::BlockedCondition: return "Condition"; case Thread::__Begin_Blocked_States__: diff --git a/Kernel/Thread.h b/Kernel/Thread.h index b9f8da5e47..716b006e2d 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -73,6 +73,7 @@ public: BlockedSelect, BlockedConnect, BlockedReceive, + BlockedAccept, BlockedCondition, __End_Blocked_States__ };