diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp index 1608378cc2..8cd9db38c2 100644 --- a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp @@ -471,17 +471,21 @@ TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer) { TRACE("ReadData(%lu bytes)", numBytes); - //BenaphoreLocker lock(&fReceiveLock); + RecursiveLocker locker(fLock); if (fState == SYNCHRONIZE_SENT || fState == SYNCHRONIZE_RECEIVED) { // we need to wait until the connection becomes established if (flags & MSG_DONTWAIT) return B_WOULD_BLOCK; + locker.Unlock(); + status_t status = acquire_sem_etc(fSendLock, 1, B_RELATIVE_TIMEOUT | B_CAN_INTERRUPT, socket->receive.timeout); if (status < B_OK) return status; + + locker.Lock(); } if ((fFlags & FLAG_NO_RECEIVE) != 0 && fReceiveQueue.Available() == 0) { @@ -496,8 +500,6 @@ TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer) bigtime_t timeout = system_time() + socket->receive.timeout; - RecursiveLocker locker(fLock); - do { locker.Unlock();