mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +00:00
IPv4: Take the socket lock more (fixes TCP connection to localhost)
This fixes an issue where making a TCP connection to localhost didn't work correctly since the loopback interface is currently synchronous. (Sending something to localhost would enqueue a packet on the same interface and then immediately wake the network task to process that packet.) This was preventing the TCP handshake from working correctly with localhost since we'd send out the SYN packet before moving to the SynSent state. The lock is now held long enough for this operation to be atomic.
This commit is contained in:
parent
91ea6057d6
commit
a6aee0c097
4 changed files with 12 additions and 0 deletions
|
@ -368,6 +368,8 @@ KResult TCPSocket::protocol_listen()
|
|||
|
||||
KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock should_block)
|
||||
{
|
||||
Locker locker(lock());
|
||||
|
||||
auto routing_decision = route_to(peer_address(), local_address());
|
||||
if (routing_decision.is_zero())
|
||||
return KResult(-EHOSTUNREACH);
|
||||
|
@ -388,8 +390,10 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
|
|||
m_direction = Direction::Outgoing;
|
||||
|
||||
if (should_block == ShouldBlock::Yes) {
|
||||
locker.unlock();
|
||||
if (Thread::current()->block<Thread::ConnectBlocker>(nullptr, description).was_interrupted())
|
||||
return KResult(-EINTR);
|
||||
locker.lock();
|
||||
ASSERT(setup_state() == SetupState::Completed);
|
||||
if (has_error()) {
|
||||
m_role = Role::None;
|
||||
|
@ -458,6 +462,7 @@ void TCPSocket::shut_down_for_writing()
|
|||
|
||||
KResult TCPSocket::close()
|
||||
{
|
||||
Locker socket_locker(lock());
|
||||
auto result = IPv4Socket::close();
|
||||
if (state() == State::CloseWait) {
|
||||
#ifdef TCP_SOCKET_DEBUG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue