Skip to content

Commit ff3d614

Browse files
authored
Merge pull request #42 from sy-c/master
SO_NOSIGPIPE
2 parents 6161dca + 4c7036a commit ff3d614

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/InfoLoggerClient.cxx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@
3434
#include "infoLoggerDefaults.h"
3535

3636
#ifndef MSG_NOSIGNAL
37-
#ifdef SO_NOSIGPIPE
38-
#define MSG_NOSIGNAL SO_NOSIGPIPE
39-
#else
40-
#define MSG_NOSIGNAL 0
41-
#endif
37+
#define MSG_NOSIGNAL 0
4238
#endif
4339
const int sendFlags = MSG_NOSIGNAL;
4440

@@ -123,6 +119,19 @@ int InfoLoggerClient::connect() {
123119
throw __LINE__;
124120
}
125121
*/
122+
123+
// configure socket to avoid SIGPIPE (when possible)
124+
#ifdef SO_NOSIGPIPE
125+
{
126+
int optValue = 1;
127+
socklen_t optLen = sizeof(optValue);
128+
if (setsockopt(txSocket, SOL_SOCKET, SO_NOSIGPIPE, &optValue, optLen) == -1) {
129+
if (isVerbose) log.error("setsockopt() failed: %s", strerror(errno));
130+
throw __LINE__;
131+
}
132+
}
133+
#endif
134+
126135

127136
// configure socket TX buffer size
128137
if (cfg.txSocketOutBufferSize != -1) {
@@ -206,6 +215,7 @@ int InfoLoggerClient::isOk()
206215

207216
InfoLoggerClient::~InfoLoggerClient()
208217
{
218+
isVerbose = 1;
209219
reconnectThreadCleanup();
210220
disconnect();
211221
if (messageBuffer.size()) {

0 commit comments

Comments
 (0)