if(FD_ISSET(m_socketFd, &wset)){
if(-1 == (write_res = write(m_socketFd, reinterpret_cast<const char *>(bytes) + current_offset, bytes_to_write))){
- if(errno == ECONNRESET){
+ if(errno == ECONNRESET || errno == EPIPE){
LogInfo("Connection closed : " << strerror(errno));
ThrowMsg(Exception::SocketStreamException,
"Connection closed : " << strerror(errno) << ". Couldn't write whole data");
}
pthread_t mainThread;
+
if((returned_value = pthread_create(&mainThread, NULL, &serverThread, this)) < 0){
errno = returned_value;
throwWithErrnoMessage("pthread_create()");
timespec timeout;
maxfd = (m_listenFd > signal_fd) ? (m_listenFd) : (signal_fd);
++maxfd;
+ //this will block SIGPIPE for this thread and every thread created in it
+ //reason : from here on we don't won't to receive SIGPIPE on writing to closed socket
+ //instead of signal we want to receive error from write - hence blocking SIGPIPE
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set, SIGPIPE);
+ pthread_sigmask(SIG_BLOCK, &set, NULL);
while(1){
timeout.tv_sec = TIMEOUT_SEC;