Subject: Re: Splice on blocking TCP sockets again..

From: Eric Dumazet <[email-masked]>
Date: Fri, 02 Oct 2009 20:05:01 +0200

Jason Gunthorpe a écrit :

> 
> I'd suggest a construct like the following as a compatability
> solution:
> 
> struct pollfd pfd = {.fd = tcpfd, events = POLLIN | POLLRDHUP};
> while (..) {
>    rc = splice(tcpfd,0,pfd[1],0,count,SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
>    if (rc == -1)
>      //...
>    if (rc == 0) {
>        if (pfd.revents & POLLRDHUP)
>           // oops, EOF on TCP
> 
>        /* Might be an old kernel that nonblocks on TCP, have to check
>           if this is EOF or do blocking. */
>        rc = poll(&pfd,1,-1);
>        if (rc == -1)
>           //...
>    }
> 
>    rc = splice(pfd[0],0,ofd,0,..., SPLICE_F_MOVE)
> }
> 
> Which should add no overhead in the new splice blocks case, and falls
> back gracefully on older kernels..
> 

Agreed, thanks for the tip.

Indeed, new kernel will permit a loop with only splice() syscalls, while on an old
kernel, some poll() syscalls might be needed if tcp socket is empty.