Skip to content

Commit

Permalink
Merge pull request #42 from sy-c/master
Browse files Browse the repository at this point in the history
SO_NOSIGPIPE
  • Loading branch information
sy-c authored Aug 4, 2020
2 parents 6161dca + 4c7036a commit ff3d614
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/InfoLoggerClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
#include "infoLoggerDefaults.h"

#ifndef MSG_NOSIGNAL
#ifdef SO_NOSIGPIPE
#define MSG_NOSIGNAL SO_NOSIGPIPE
#else
#define MSG_NOSIGNAL 0
#endif
#define MSG_NOSIGNAL 0
#endif
const int sendFlags = MSG_NOSIGNAL;

Expand Down Expand Up @@ -123,6 +119,19 @@ int InfoLoggerClient::connect() {
throw __LINE__;
}
*/

// configure socket to avoid SIGPIPE (when possible)
#ifdef SO_NOSIGPIPE
{
int optValue = 1;
socklen_t optLen = sizeof(optValue);
if (setsockopt(txSocket, SOL_SOCKET, SO_NOSIGPIPE, &optValue, optLen) == -1) {
if (isVerbose) log.error("setsockopt() failed: %s", strerror(errno));
throw __LINE__;
}
}
#endif


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

InfoLoggerClient::~InfoLoggerClient()
{
isVerbose = 1;
reconnectThreadCleanup();
disconnect();
if (messageBuffer.size()) {
Expand Down

0 comments on commit ff3d614

Please sign in to comment.