title: How can I write spliceAll in Linux?
body: <p>I want to drain a pipe by pushing all its data to a socket using the <code>splice</code> system call on Linux.</p>
  
  <p>My current attempt is:</p>
  
  <pre><code>ssize_t splice(int i, loff_t* io, int o, loff_t* oo, size_t l, unsigned int flags);
  int  spliceAll(int i, loff_t* io, int o, loff_t* oo, size_t l, unsigned int flags) {
    size_t t =  0; int n = 0;
    while (t &lt;  l) { if ((n = splice(i, io, o, oo, l - t, flags)) &lt; 0) break; t += n; }
    return t == l ? 0 : -1;
  }
  </code></pre>
  
  <p>the user-space buffer equivalent to this is is simply:</p>
  
  <pre><code>int sendAll(int s, void* b, size_t l, int flags) {
    size_t t =  0; int n = 0;
    while (t &lt;  l) { if ((n = send(s, b + t, l - t, flags)) &lt; 0) break; t += n; }
    return t == l ? 0 : -1;
  }
  </code></pre>
  
  <hr>
  
  <p>Assuming non-blocking sockets (and pipes for <code>spliceAll</code>) AND <code>send</code> &amp; <code>splice</code> never returning <code>0</code>:</p>
  
  <ul>
  <li>Is the loop in <code>spliceAll</code> correct?</li>
  </ul>
  
  <hr>
  
  <ul>
  <li>Are there any other errors I am failing to see in both <code>spliceAll</code> and <code>sendAll</code>?</li>
  </ul>