From 61ef761d69fc007db2ea443b938b34ba181f6745 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 20 Apr 2008 02:59:23 +0000 Subject: [PATCH] Send() and Receive() select notified the wrong socket about readability respectively writability. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25069 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../network/protocols/unix/UnixEndpoint.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp b/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp index 824ec8da8d..3a7314c2db 100644 --- a/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp +++ b/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp @@ -462,9 +462,12 @@ UnixEndpoint::Send(net_buffer *buffer) fifoLocker.Unlock(); locker.Lock(); + bool peerLocked = (fPeerEndpoint == peerEndpoint + && _LockConnectedEndpoints(locker, peerLocker) == B_OK); + // send notifications - if (notifyRead) - gSocketModule->notify(socket, B_SELECT_READ, readable); + if (peerLocked && notifyRead) + gSocketModule->notify(peerEndpoint->socket, B_SELECT_READ, readable); if (notifyWrite) gSocketModule->notify(socket, B_SELECT_WRITE, writable); @@ -517,6 +520,9 @@ UnixEndpoint::Receive(size_t numBytes, uint32 flags, net_buffer **_buffer) if (fReceiveFifo == NULL) RETURN_ERROR(ENOTCONN); + UnixEndpoint* peerEndpoint = fPeerEndpoint; + Reference peerReference(peerEndpoint); + // lock our FIFO UnixFifo* fifo = fReceiveFifo; Reference _(fifo); @@ -542,11 +548,15 @@ UnixEndpoint::Receive(size_t numBytes, uint32 flags, net_buffer **_buffer) fifoLocker.Unlock(); locker.Lock(); + UnixEndpointLocker peerLocker; + bool peerLocked = (peerEndpoint != NULL && fPeerEndpoint == peerEndpoint + && _LockConnectedEndpoints(locker, peerLocker) == B_OK); + // send notifications if (notifyRead) gSocketModule->notify(socket, B_SELECT_READ, readable); - if (notifyWrite) - gSocketModule->notify(socket, B_SELECT_WRITE, writable); + if (peerLocked && notifyWrite) + gSocketModule->notify(peerEndpoint->socket, B_SELECT_WRITE, writable); switch (error) { case UNIX_FIFO_SHUTDOWN: @@ -630,7 +640,7 @@ UnixEndpoint::SetReceiveBufferSize(size_t size) status_t UnixEndpoint::Shutdown(int direction) { - TRACE("[%ld] %p->UnixEndpoint::SetReceiveBufferSize(%d)\n", + TRACE("[%ld] %p->UnixEndpoint::Shutdown(%d)\n", find_thread(NULL), this, direction); uint32 shutdown;