mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:47:43 +00:00
Kernel: Add a new block state for accept() on a blocking socket
Rather than asserting, which really ruins everyone's day.
This commit is contained in:
parent
79a6312c8f
commit
f2fdac789c
4 changed files with 22 additions and 2 deletions
|
@ -2120,8 +2120,13 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
auto& socket = *accepting_socket_description->socket();
|
auto& socket = *accepting_socket_description->socket();
|
||||||
if (!socket.can_accept()) {
|
if (!socket.can_accept()) {
|
||||||
ASSERT(!accepting_socket_description->is_blocking());
|
if (accepting_socket_description->is_blocking()) {
|
||||||
return -EAGAIN;
|
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();
|
auto accepted_socket = socket.accept();
|
||||||
ASSERT(accepted_socket);
|
ASSERT(accepted_socket);
|
||||||
|
|
|
@ -137,6 +137,18 @@ bool Scheduler::pick_next()
|
||||||
return IterationDecision::Continue;
|
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.state() == Thread::BlockedSelect) {
|
||||||
if (thread.m_select_has_timeout) {
|
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)) {
|
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)) {
|
||||||
|
|
|
@ -179,6 +179,8 @@ const char* to_string(Thread::State state)
|
||||||
return "Connect";
|
return "Connect";
|
||||||
case Thread::BlockedReceive:
|
case Thread::BlockedReceive:
|
||||||
return "Receive";
|
return "Receive";
|
||||||
|
case Thread::BlockedAccept:
|
||||||
|
return "Accepting";
|
||||||
case Thread::BlockedCondition:
|
case Thread::BlockedCondition:
|
||||||
return "Condition";
|
return "Condition";
|
||||||
case Thread::__Begin_Blocked_States__:
|
case Thread::__Begin_Blocked_States__:
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
BlockedSelect,
|
BlockedSelect,
|
||||||
BlockedConnect,
|
BlockedConnect,
|
||||||
BlockedReceive,
|
BlockedReceive,
|
||||||
|
BlockedAccept,
|
||||||
BlockedCondition,
|
BlockedCondition,
|
||||||
__End_Blocked_States__
|
__End_Blocked_States__
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue