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

Kernel: Support non-blocking connect().

If connect() is called on a non-blocking socket, it will "fail" immediately
with -EINPROGRESS. After that, you select() on the socket and wait for it to
become writable.
This commit is contained in:
Andreas Kling 2019-04-08 04:52:21 +02:00
parent 7fcca0ce4b
commit 65d6318c33
11 changed files with 22 additions and 17 deletions

View file

@ -152,7 +152,7 @@ NetworkOrdered<word> TCPSocket::compute_tcp_checksum(const IPv4Address& source,
return ~(checksum & 0xffff);
}
KResult TCPSocket::protocol_connect()
KResult TCPSocket::protocol_connect(ShouldBlock should_block)
{
auto* adapter = adapter_for_route_to(destination_address());
if (!adapter)
@ -166,11 +166,14 @@ KResult TCPSocket::protocol_connect()
send_tcp_packet(TCPFlags::SYN);
m_state = State::Connecting;
current->set_blocked_socket(this);
current->block(Thread::BlockedConnect);
if (should_block == ShouldBlock::Yes) {
current->set_blocked_socket(this);
current->block(Thread::BlockedConnect);
ASSERT(is_connected());
return KSuccess;
}
ASSERT(is_connected());
return KSuccess;
return KResult(-EINPROGRESS);
}
int TCPSocket::protocol_allocate_source_port()