From 7bb0688d10de060de5300a6e10cb36b6935fee53 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 29 Jan 2019 21:19:24 +0000 Subject: [PATCH] Set keepalive on Unix socket --- libweb3jsonrpc/UnixSocketServer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libweb3jsonrpc/UnixSocketServer.cpp b/libweb3jsonrpc/UnixSocketServer.cpp index 9510f1a6c4d..9528ba8419f 100644 --- a/libweb3jsonrpc/UnixSocketServer.cpp +++ b/libweb3jsonrpc/UnixSocketServer.cpp @@ -86,6 +86,15 @@ bool UnixDomainSocketServer::StartListening() ::bind(m_socket, reinterpret_cast(&m_address), sizeof(sockaddr_un)); fs::permissions(m_path, fs::owner_read | fs::owner_write); listen(m_socket, 128); + + int keepalive = 1; + if (setsockopt(m_socket, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive) < 0) + { + CloseConnection(m_socket); + m_socket = -1; + unlink(m_path.c_str()); + return false; + } } return IpcServerBase::StartListening(); }