Skip to content

Commit f3a4854

Browse files
committed
Ignore SIGPIPE signal when using TcpClient class
1 parent 64f7319 commit f3a4854

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

trantor/net/TcpClient.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void removeConnector(const ConnectorPtr &connector)
4444
// connector->
4545
}
4646

47+
TcpClient::IgnoreSigPipe TcpClient::initObj;
48+
4749
static void defaultConnectionCallback(const TcpConnectionPtr &conn)
4850
{
4951
LOG_TRACE << conn->localAddr().toIpPort() << " -> "

trantor/net/TcpClient.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ class TcpClient : NonCopyable
132132
#ifdef USE_OPENSSL
133133
std::shared_ptr<SSL_CTX> _sslCtxPtr;
134134
#endif
135+
class IgnoreSigPipe
136+
{
137+
public:
138+
IgnoreSigPipe()
139+
{
140+
::signal(SIGPIPE, SIG_IGN);
141+
}
142+
};
143+
144+
static IgnoreSigPipe initObj;
135145
};
136146

137147
} // namespace trantor

0 commit comments

Comments
 (0)