title: How to prevent SIGPIPE in sendfile function
body: <p>Good day i have small http server where i have threadpool current connections, when i do send file in thread i get signal SIGPIPE and my server crash. Part of code: 
  //in thread:
  <pre><code> detail::create_headers(headers,stat_buf.st_size,mime_types::extension_to_type(extension.c_str()));
      if(detail::write_to_client(fd_client,headers,unicode_strlen(headers))!=-1)
      {
          while(offset!=stat_buf.st_size)
          {
              if(sendfile(fd_client,src,&amp;offset,stat_buf.st_size)==-1)
              {
                  DEBUG_MSG_FORMAT("sendfile error: %d",errno);
                  break;
              }
          }
      }</pre></code>
  //and :
  <pre><code>
  size_t write_to_client(int fd_client,const void *buf,size_t len)
  {
      int optval = 1;
      setsockopt (fd_client, SOL_TCP, TCP_CORK, &amp;optval, sizeof (int));
      size_t result = write(fd_client,buf,len);
      if(result==-1)
      {
          DEBUG_MSG_FORMAT("write error: %d",errno);
      }
      optval = 0;
      setsockopt (fd_client, SOL_TCP, TCP_CORK, &amp;optval, sizeof (int));
                  return result;
  }
  </pre></code>
  How can i handle or prevent SIGPIPE in thread?</p>