Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../../usr/man/man3c/sendfile.3c
Real path: /usr/share/man/man3c/sendfile.3c
Zurück
'\" te .\" Copyright (c) 2006, 2022, Oracle and/or its affiliates. .TH sendfile 3C "21 Mar 2022" "Oracle Solaris 11.4" "Standard C Library Functions" .SH NAME sendfile \- send files over sockets or copy files to files .SH SYNOPSIS .LP .nf #include <sys/sendfile.h> \fBssize_t\fR \fBsendfile\fR(\fBint\fR \fIout_fd\fR, \fBint\fR \fIin_fd\fR, \fBoff_t *\fR\fIoff\fR, \fBsize_t\fR \fIlen\fR); .fi .SH DESCRIPTION .sp .LP The \fBsendfile()\fR function copies data from \fIin_fd\fR to \fIout_fd\fR, starting at an offset of \fIoff\fR bytes and continuing for a length of \fIlen\fR bytes. .sp .LP The \fIin_fd\fR argument should be a file descriptor to a regular file opened for reading. For more information, see the \fBopen\fR(2) man page. The \fIout_fd\fR argument should be a file descriptor to a regular file opened for writing or to a connected \fBAF_INET\fR or \fBAF_INET6\fR socket of \fBSOCK_STREAM\fR type. For more information, see the \fBsocket\fR(3C) man page. .sp .LP If the \fIoff\fR argument is not null, the \fIoff\fR argument is a pointer to a variable. The variable holds the input file pointer position from which the data is read. After \fBsendfile()\fR has completed, the variable is set to the offset of the byte following the last byte that was read. .sp .LP If the \fIoff\fR argument is null, data is read from \fIin_fd\fR starting at its own file offset, and the file offset of \fIin_fd\fR is updated to the offset of the byte following the last byte that was read. .sp .LP The \fBsendfile()\fR function modifies the file pointer for \fIout_fd\fR, if it is a regular file. .sp .LP The \fBsendfile()\fR function can also be used to send buffers from the calling program's memory by setting \fIin_fd\fR to \fBSFV_FD_SELF\fR and \fIoff\fR to the address of the memory buffer. .SH RETURN VALUES .sp .LP Upon successful completion, \fBsendfile()\fR returns the total number of bytes written to \fIout_fd\fR and also updates the offset to point to the byte that follows the last byte read. Otherwise, it returns \fB\(mi1\fR, and \fBerrno\fR is set to indicate the error. .SH ERRORS .sp .LP The \fBsendfile()\fR function will fail if: .sp .ne 2 .mk .na \fB\fBEAFNOSUPPORT\fR\fR .ad .RS 16n .rt The implementation does not support the specified address family of the socket. .RE .sp .ne 2 .mk .na \fB\fBEAGAIN\fR\fR .ad .RS 16n .rt Mandatory file or record locking is set on either the file descriptor or output file descriptor if it points at regular files. \fBO_NDELAY\fR or \fBO_NONBLOCK\fR is set, and there is a blocking record lock. An attempt has been made to write to a stream that cannot accept data with the \fBO_NDELAY\fR or the \fBO_NONBLOCK\fR flag set. .RE .sp .ne 2 .mk .na \fB\fBEBADF\fR\fR .ad .RS 16n .rt The \fIout_fd\fR or \fIin_fd\fR argument is either not a valid file descriptor, \fIout_fd\fR is not opened for writing, or \fIin_fd\fR is not opened for reading. .RE .sp .ne 2 .mk .na \fB\fBEINVAL\fR\fR .ad .RS 16n .rt The offset cannot be represented by the \fBoff_t\fR structure, or the length is negative when cast to \fBssize_t\fR. .RE .sp .ne 2 .mk .na \fB\fBEIO\fR\fR .ad .RS 16n .rt An I/O error occurred while accessing the file system. .RE .sp .ne 2 .mk .na \fB\fBENOMEM\fR\fR .ad .RS 16n .rt There is insufficient memory available. .RE .sp .ne 2 .mk .na \fB\fBENOTCONN\fR\fR .ad .RS 16n .rt The socket is not connected. .RE .sp .ne 2 .mk .na \fB\fBEOPNOTSUPP\fR\fR .ad .RS 16n .rt The socket type is not supported. .RE .sp .ne 2 .mk .na \fB\fBEPERM\fR\fR .ad .RS 16n .rt The output file has the \fBappendonly\fR system attribute set but the \fIout_fd\fR file descriptor does not have the \fBO_APPEND\fR flag set. .sp The output file has one or more of the \fBreadonly\fR, \fBimmutable\fR, or \fBrtime\fR system attributes set. .RE .sp .ne 2 .mk .na \fB\fBEPIPE\fR\fR .ad .RS 16n .rt The \fIout_fd\fR argument is no longer connected to the peer endpoint. .RE .sp .ne 2 .mk .na \fB\fBEINTR\fR\fR .ad .RS 16n .rt A signal was caught during the write operation and no data was transferred. .RE .SH USAGE .sp .LP The \fBsendfile()\fR function has a transitional interface for 64-bit file offsets. See \fBlf64\fR(7). .SH EXAMPLES .LP \fBExample 1\fR Sending a Buffer Over a Socket .sp .LP The following example demonstrates how to send the buffer \fIbuf\fR over a socket. At the end, it prints the number of bytes transferred over the socket from the buffer. It assumes that \fIaddr\fR will be filled up appropriately, depending upon where to send the buffer. .sp .in +2 .nf int tfd; off_t baddr; struct sockaddr_in sin; char buf[64 * 1024]; in_addr_t addr; size_t len; tfd = socket(AF_INET, SOCK_STREAM, 0); if (tfd == -1) { perror("socket"); exit(1); } sin.sin_family = AF_INET; sin.sin_addr.s_addr = addr; /* Fill in the appropriate address. */ sin.sin_port = htons(2345); if (connect(tfd, (struct sockaddr *)&sin, sizeof(sin))<0) { perror("connect"); exit(1); } baddr = (off_t)buf; len = sizeof(buf); while (len > 0) { ssize_t res; res = sendfile(tfd, SFV_FD_SELF, &baddr, len); if (res == -1) if (errno != EINTR) { perror("sendfile"); exit(1); } else continue; len -= res; } .fi .in -2 .sp .LP \fBExample 2\fR Transferring Files to Sockets .sp .LP The following program demonstrates a transfer of files to sockets: .sp .in +2 .nf int ffd, tfd; off_t off; struct sockaddr_in sin; in_addr_t addr; int len; struct stat stat_buf; ssize_t len; ffd = open("file", O_RDONLY); if (ffd == -1) { perror("open"); exit(1); } tfd = socket(AF_INET, SOCK_STREAM, 0); if (tfd == -1) { perror("socket"); exit(1); } sin.sin_family = AF_INET; sin.sin_addr = addr; /* Fill in the appropriate address. */ sin.sin_port = htons(2345); if (connect(tfd, (struct sockaddr *) &sin, sizeof(sin)) <0) { perror("connect"); exit(1); } if (fstat(ffd, &stat_buf) == -1) { perror("fstat"); exit(1); } len = stat_buf.st_size; while (len > 0) { ssize_t res; res = sendfile(tfd, ffd, &off, len); if (res == -1) if (errno != EINTR) { perror("sendfile"); exit(1); } else continue; len -= res; } .fi .in -2 .sp .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .TS tab( ) box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed _ MT-Level MT-Safe .TE .sp .SH SEE ALSO .sp .LP \fBopen\fR(2), \fBsendfilev\fR(3C), \fBsocket\fR(3C), \fBattributes\fR(7), \fBlf64\fR(7), \fBsysattr\fR(7) .SH HISTORY .sp .LP The \fBsendfile()\fR function was added to Oracle Solaris in the Solaris 9 release.