diff options
author | dg <dg@FreeBSD.org> | 1998-11-05 14:43:29 +0000 |
---|---|---|
committer | dg <dg@FreeBSD.org> | 1998-11-05 14:43:29 +0000 |
commit | 5f9efae0f81c8356caf17820cc3e0fcb0c8bc83c (patch) | |
tree | 4d5f9e7d08d60bd47a82148062d9cbf579cd35a5 /lib | |
parent | 4a09196d8cd8611817e2b28bfaf0b7e012f154b1 (diff) | |
download | FreeBSD-src-5f9efae0f81c8356caf17820cc3e0fcb0c8bc83c.zip FreeBSD-src-5f9efae0f81c8356caf17820cc3e0fcb0c8bc83c.tar.gz |
Added a manual page for sendfile(2).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/sys/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/sys/sendfile.2 | 137 |
2 files changed, 139 insertions, 2 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 6882621..238e10a 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,5 +1,5 @@ # @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 -# $Id: Makefile.inc,v 1.54 1998/07/28 03:33:25 jlemon Exp $ +# $Id: Makefile.inc,v 1.55 1998/08/17 03:41:28 jb Exp $ # sys sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/sys ${.CURDIR}/../libc/sys @@ -87,7 +87,7 @@ MAN2+= _exit.2 accept.2 access.2 acct.2 adjtime.2 \ mount.2 mprotect.2 msync.2 munmap.2 nanosleep.2 \ nfssvc.2 open.2 pathconf.2 pipe.2 poll.2 profil.2 ptrace.2 quotactl.2 \ read.2 readlink.2 reboot.2 recv.2 rename.2 revoke.2 rfork.2 rmdir.2 \ - rtprio.2 select.2 semctl.2 semget.2 semop.2 send.2 \ + rtprio.2 select.2 semctl.2 semget.2 semop.2 send.2 sendfile.2 \ setgroups.2 setpgid.2 setregid.2 setreuid.2 setsid.2 setuid.2 \ shmat.2 shmctl.2 shmget.2 shutdown.2 \ sigaction.2 sigaltstack.2 sigpending.2 sigprocmask.2 sigreturn.2 \ diff --git a/lib/libc/sys/sendfile.2 b/lib/libc/sys/sendfile.2 new file mode 100644 index 0000000..20ca6c8 --- /dev/null +++ b/lib/libc/sys/sendfile.2 @@ -0,0 +1,137 @@ +.\" Copyright (c) 1998, David Greenman +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice unmodified, this list of conditions, and the following +.\" disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $Id$ +.\" +.Dd November 5, 1998 +.Dt SENDFILE 2 +.Os +.Sh NAME +.Nm sendfile +.Nd send a file to a socket +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/socket.h> +.Fd #include <sys/uio.h> +.Ft int +.Fn sendfile "int fd" "int s" "off_t offset" "size_t nbytes" "struct sf_hdtr *hdtr" "off_t *sbytes" "int flags" +.Sh DESCRIPTION +.Fn Sendfile +sends a regular file specified by descriptor +.Fa fd +out a stream socket specified by descriptor +.Fa s . +.Pp +The +.Fa offset +argument specifies where to begin in the file. The +.Fa nbytes +argument specifies how many bytes of the file should be sent, with 0 having the special +meaning of send until the end of file has been reached. +.Pp +An optional header and/or trailer can be sent before and after the file data by specifying +a pointer to a struct sf_hdtr, which has the following structure: +.Pp +.Bd -literal -offset indent -compact +struct sf_hdtr { + struct iovec *headers; /* pointer to header iovecs */ + int hdr_cnt; /* number of header iovecs */ + struct iovec *trailers; /* pointer to trailer iovecs */ + int trl_cnt; /* number of trailer iovecs */ +}; +.Ed +.Pp +The +.Fa headers +and +.Fa tailers +pointers, if non-NULL, point to arrays of struct iovec structures. See the +.Fn writev +system call for information on the iovec structure. The number of iovecs in these +arrays is specified by +.Fa hdr_cnt +and +.Fa trl_cnt . +.Pp +If non-NULL, the system will write the total number of bytes sent on the socket to the +variable pointed to by +.Fa sbytes . +.Pp +The +.Fa flags +argument is currently undefined and should be specified as 0. +.Sh IMPLEMENTATION NOTES +.Pp +The FreeBSD implementation of +.Fn sendfile +is "zero-copy", meaning that it has been optimized so that copying of the file data is avoided. +.Sh RETURN VALUES +Upon successful completion, +.Fn sendfile +returns 0. Otherwise a -1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EBADF +.Fa fd +is not a valid file descriptor. +.It Bq Er EBADF +.Fa s +is not a valid socket descriptor. +.It Bq Er ENOTSOCK +.Fa s +is not a socket. +.It Bq Er EINVAL +.Fa fd +is not a regular file. +.It Bq Er EINVAL +.Fa s +is not a SOCK_STREAM type socket. +.It Bq Er EINVAL +.Fa offset +is negative or out of range. +.It Bq Er ENOTCONN +.Fa s +points to an unconnected socket. +.It Bq Er EPIPE +The socket peer has closed the connection. +.It Bq Er EIO +An error occurred while reading from +.Fa fd . +.It Bq Er EFAULT +An invalid address was specified for a parameter. +.El +.Sh SEE ALSO +.Xr open 2 , +.Xr socket 2 , +.Xr send 2 , +.Xr writev 2 +.Sh HISTORY +.Fn sendfile +first appeared in FreeBSD 3.0.1. +.Sh AUTHORS +.Fn sendfile +and this manual page were written by David Greenman <dg@root.com>. |