title: Is there a cleaner way to use the write() function reliably?
body: <p>I read the <code>man</code> pages, and my understanding is that if <code>write()</code> fails and sets the <code>errno</code> to <code>EAGAIN</code> or <code>EINTR</code>, I may perform the <code>write()</code> again, so I came up with the following code:</p>
  
  <pre><code>  ret = 0;
    while(ret != count) {
      write_count = write(connFD, (char *)buf + ret,  count);
      while (write_count &lt; 0) {
        switch(errno) {
          case EINTR:
          case EAGAIN:
            write_count = write(connFD, (char *)buf + ret,  count -ret);
            break;
          default:
            printf("\n The value of ret is : %d\n", ret);
            printf("\n The error number is : %d\n", errno);      
            ASSERT(0);
        }
      }
      ret += write_count;
    }
  </code></pre>
  
  <p>I am performing <code>read()</code> and <code>write()</code> on sockets and handling the <code>read()</code> similarly as above. I am using Linux, with <code>gcc</code> compiler.</p>