From 855af2106ce187c17278ed5079e054176f9cdfeb Mon Sep 17 00:00:00 2001 From: Mike Belopuhov Date: Mon, 4 Jul 2011 00:34:44 +0000 Subject: Implement an idle timeout for the socket splicing. A new `sp_idle' field of the `splice' structure can be used to specify a period of inactivity after which splicing will be dissolved. ETIMEDOUT error retrieved with a SO_ERROR indicates the idle timeout expiration. With comments from and OK bluhm. --- lib/libc/sys/getsockopt.2 | 21 +++++++++++++++------ share/man/man9/sosplice.9 | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2 index ecf38e1e6bd..9de91b68e69 100644 --- a/lib/libc/sys/getsockopt.2 +++ b/lib/libc/sys/getsockopt.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: getsockopt.2,v 1.32 2011/05/02 20:18:17 jmc Exp $ +.\" $OpenBSD: getsockopt.2,v 1.33 2011/07/04 00:34:43 mikeb Exp $ .\" $NetBSD: getsockopt.2,v 1.7 1995/02/27 12:33:29 cgd Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)getsockopt.2 8.3 (Berkeley) 4/19/94 .\" -.Dd $Mdocdate: May 2 2011 $ +.Dd $Mdocdate: July 4 2011 $ .Dt GETSOCKOPT 2 .Os .Sh NAME @@ -362,15 +362,19 @@ In the second form, is a .Vt struct splice with the drain socket in -.Va sp_fd -and a positive maximum number of bytes or 0 in -.Va sp_max . +.Va sp_fd , +a positive maximum number of bytes or 0 in +.Va sp_max +and an idle timeout +.Va sp_idle +in a form of a +.Vt struct timeval . If \-1 is given as drain socket, the source socket .Fa s gets unspliced. Otherwise the spliced data transfer continues within the kernel until the optional maximum is reached, one of the connections -terminates or an error occurs. +terminates, idle timeout expires or an error occurs. A successful .Xr select 2 , .Xr poll 2 , @@ -383,6 +387,11 @@ is available. The error status can be examined with .Dv SO_ERROR at the source socket. +.Er ETIMEDOUT +error is set if there was no data transfered between two sockets +during the +.Va sp_idle +period of time. Note that if a maximum is given, it is only guaranteed that no more bytes are transferred. A short splice can happen but then a second call to splice will diff --git a/share/man/man9/sosplice.9 b/share/man/man9/sosplice.9 index 7f865f479fd..c916b2bdaa5 100644 --- a/share/man/man9/sosplice.9 +++ b/share/man/man9/sosplice.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sosplice.9,v 1.2 2011/03/12 18:31:41 bluhm Exp $ +.\" $OpenBSD: sosplice.9,v 1.3 2011/07/04 00:34:43 mikeb Exp $ .\" .\" Copyright (c) 2011 Alexander Bluhm .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: March 12 2011 $ +.Dd $Mdocdate: July 4 2011 $ .Dt SOSPLICE 9 .Os .Sh NAME @@ -23,7 +23,7 @@ .Nd splice two sockets for zero-copy data transfer .Sh SYNOPSIS .Ft int -.Fn sosplice "struct socket *so" "int fd" "off_t max" +.Fn sosplice "struct socket *so" "int fd" "off_t max" "struct timeval *tv" .Ft int .Fn somove "struct socket *so" "int wait" .Sh DESCRIPTION @@ -41,6 +41,12 @@ is negative, an existing splicing gets dissolved. If .Fa max is positive, at most that many bytes will get transferred. +If +.Fa tv +is not NULL, a +.Xr timeout 9 +is scheduled to dissolve splicing in the case when no data can be +transferred for the specified period of time. Socket splicing can be invoked from user-land via the .Xr setsockopt 2 system-call at the @@ -138,6 +144,11 @@ If that fails and the drain socket cannot send anymore, an .Er EPIPE error is set on the source socket. .Pp +If the idle timeout was specified and no data was transferred +for that period of time, splicing gets dissolved and an +.Er ETIMEDOUT +error is set on the source socket. +.Pp Finally the socket splicing gets dissolved if the source socket cannot receive anymore and its receive buffer is empty; or if the drain socket cannot send anymore; or if the maximum has been reached; @@ -200,7 +211,8 @@ locked. .El .Sh SEE ALSO .Xr setsockopt 2 , -.Xr options 4 +.Xr options 4 , +.Xr timeout 9 .Sh HISTORY Socket splicing first appeared in .Ox 4.9 . -- cgit v1.2.3