sendfilev(3c) 맨 페이지 - 윈디하나의 솔라나라

개요

섹션
맨 페이지 이름
검색(S)

sendfilev(3c)

sendfilev(3C)            Standard C Library Functions            sendfilev(3C)

NAME
       sendfilev - send a file

SYNOPSIS
       #include <sys/sendfile.h>

       ssize_t sendfilev(int fildes, const struct sendfilevec *vec,
            int sfvcnt, size_t *xferred);

PARAMETERS
       The sendfilev() function supports the following parameters:

       fildes     A  file  descriptor  to  a  regular file, or to a AF_INET or
                  AF_INET6 family type SOCK_STREAM socket  that  is  open  for
                  writing.


       vec        An  array  of  sendfilevec_t,  as defined in the sendfilevec
                  structure below.


       sfvcnt     The number of members in vec.


       xferred    The total number of bytes written to out_fd.


DESCRIPTION
       The sendfilev() function attempts to write data from the sfvcnt buffers
       specified  by  the  members  of  vec  array:  vec[0],  vec[1],  ...   ,
       vec[sfvcnt−1].  The  fildes  argument is a file descriptor to a regular
       file, or to an AF_INET or AF_INET6 family type SOCK_STREAM socket  that
       is open for writing.


       This function is analogous to writev(2), but can read from both buffers
       and  file descriptors. Unlike writev(), in the case of multiple writers
       to a file the effect of sendfilev()  is  not  necessarily  atomic;  the
       writes may be interleaved. Application-specific synchronization methods
       must be employed if this causes problems.


       The following is the sendfilevec structure:

         typedef struct sendfilevec {
                 int     sfv_fd;         /* input fd */
                 uint_t  sfv_flag;       /* Flags. see below */
                 off_t   sfv_off;        /* offset to start reading from */
                 size_t  sfv_len;        /* amount of data */
         } sendfilevec_t;

         #define SFV_FD_SELF     (-2)



       To  send  a  file, open the file for reading and set sfv_fd to the file
       descriptor returned as a result. See open(2).  sfv_off  should  contain
       the  offset within the file. sfv_len should have the length of the file
       portion to be transferred.


       The xferred argument is updated to record the  total  number  of  bytes
       written to out_fd.


       The sfv_flag field is reserved and should be set to zero.


       To send data directly from the address space of the process, set sfv_fd
       to SFV_FD_SELF. sfv_off should point to the data, with sfv_len contain‐
       ing the length of the buffer.

RETURN VALUES
       Upon successful completion, the sendfilev() function returns total num‐
       ber  of bytes written to out_fd. Otherwise, it returns -1, and errno is
       set to indicate the error. The xferred argument contains the amount  of
       data  successfully transferred, which can be used to discover the error
       vector.

ERRORS
       EACCES          The process does not have appropriate privileges or one
                       of the files pointed by sfv_fd does not have  appropri‐
                       ate permissions.


       EAFNOSUPPORT    The  implementation  does not support the specified ad‐
                       dress family for socket.


       EAGAIN          Mandatory file or record locking is set on  either  the
                       file  descriptor or output file descriptor if it points
                       at regular files. O_NDELAY or O_NONBLOCK  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 O_NDELAY or the O_NONBLOCK flag set.


       EBADF           The  fildes argument is not a valid descriptor open for
                       writing or an sfv_fd is invalid or not open  for  read‐
                       ing.


       EFAULT          The vec argument points to an illegal address.

                       The xferred argument points to an illegal address.


       EINTR           A  signal  was caught during the write operation and no
                       data was transferred.


       EINVAL          The sfvcnt argument was less than or equal to 0. One of
                       the sfv_len values in vec array was less than or  equal
                       to  0,  or greater than the file size. An sfv_fd is not
                       seekable.

                       Fewer bytes were transferred than were requested.


       EIO             An I/O error occurred while accessing the file system.


       ENOMEM          There is insufficient memory available. The offset  pa‐
                       rameter is updated by the amount of data transferred so
                       that the call may be retried.


       EPERM           The output file has the appendonly system attribute set
                       but  the fildes file descriptor does not have the O_AP‐
                       PEND flag set.

                       The output file has one or more of  the  readonly,  im‐
                       mutable, or rtime system attributes set.


       EPIPE           The fildes argument is a socket that has been shut down
                       for writing.


       EPROTOTYPE      The socket type is not supported.


USAGE
       The  sendfilev()  function has a transitional interface for 64-bit file
       offsets. See lf64(7).

EXAMPLES
       The following example sends 2 vectors, one of HEADER data and a file of
       length 100 over sockfd. sockfd  is  in  a  connected  state,  that  is,
       socket(), accept(), and bind() operation are complete.

         #include <sys/sendfile.h>
         .
         .
         .
         int
         main (int argc, char *argv[]){
             int sockfd;
             ssize_t ret;
             size_t xfer;
             struct sendfilevec vec[2];
               .
               .
               .
             vec[0].sfv_fd = SFV_FD_SELF;
             vec[0].sfv_flag = 0;
             vec[0].sfv_off = "HEADER_DATA";
             vec[0].sfv_len = strlen("HEADER_DATA");
             vec[1].sfv_fd = open("input_file", ... );
             vec[1].sfv_flag = 0;
             vec[1].sfv_off = 0;
             vec[1].sfv_len = 100;

             ret = sendfilev(sockfd, vec, 2, &xfer);
               .
               .
               .
         }


ATTRIBUTES
       See attributes(7) for descriptions of the following attributes:

       tab()  box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
       TRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelMT-Safe


SEE ALSO
       open(2), writev(2), sendfile(3C), socket(3C), attributes(7), sysattr(7)

HISTORY
       The sendfilev() function was added to Oracle Solaris in the  Solaris  8
       7/01 (Update 5) release.

Oracle Solaris 11.4               21 Mar 2022                    sendfilev(3C)
맨 페이지 내용의 저작권은 맨 페이지 작성자에게 있습니다.
RSS ATOM XHTML 5 CSS3