From 10ff9c6a14837e6f51e85d4461e80c1b448bea35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 20 Mar 2021 18:24:30 +0100 Subject: [PATCH] unix: sendmsg should return EPIPE after close https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html "[EPIPE] ... the socket is connection-mode and is no longer connected." Change-Id: I6728b088d2f717b769697218edf26c76c59f488e Reviewed-on: https://review.haiku-os.org/c/haiku/+/3816 Reviewed-by: Adrien Destugues --- src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp | 6 ++++-- src/add-ons/kernel/network/protocols/unix/UnixEndpoint.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp b/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp index a9b7349030..a53e9a741e 100644 --- a/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp +++ b/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.cpp @@ -48,7 +48,8 @@ UnixEndpoint::UnixEndpoint(net_socket* socket) fReceiveFifo(NULL), fState(UNIX_ENDPOINT_CLOSED), fAcceptSemaphore(-1), - fIsChild(false) + fIsChild(false), + fWasConnected(false) { TRACE("[%" B_PRId32 "] %p->UnixEndpoint::UnixEndpoint()\n", find_thread(NULL), this); @@ -383,6 +384,7 @@ UnixEndpoint::Connect(const struct sockaddr *_address) peerFifoDeleter.Detach(); fState = UNIX_ENDPOINT_CONNECTED; + fWasConnected = true; gSocketModule->set_connected(newSocket); @@ -802,7 +804,7 @@ UnixEndpoint::_LockConnectedEndpoints(UnixEndpointLocker& locker, UnixEndpointLocker& peerLocker) { if (fState != UNIX_ENDPOINT_CONNECTED) - RETURN_ERROR(ENOTCONN); + RETURN_ERROR(fWasConnected ? EPIPE : ENOTCONN); // We need to lock the peer, too. Get a reference -- we might need to // unlock ourselves to get the locking order right. diff --git a/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.h b/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.h index 5e09fb022f..717ac7a97f 100644 --- a/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.h +++ b/src/add-ons/kernel/network/protocols/unix/UnixEndpoint.h @@ -119,6 +119,7 @@ private: sem_id fAcceptSemaphore; ucred fCredentials; bool fIsChild; + bool fWasConnected; }; #endif // UNIX_ENDPOINT_H