apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Ghent <da...@elemental.org>
Subject solaris sendfilev
Date Sat, 25 Aug 2001 05:05:23 GMT

Someone here (I think it was Justin?) was curious to see the man page for
solaris's new sendfilev() implementation. Sun just released it in patch
108808-30, and here it is below:

Extended Library Functions                        sendfilev(3EXT)

     sendfilev - send a file

     cc -flag ...  file ...-lsendfile  [-library]
     #include <sys/sendfile.h>

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

     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].  fildes  is  a  file
     descriptor  to  a  regular  file or to a AF_NCA, AF_INET, or
     AF_INET6 family type SOCK_STREAM socket  that  is  open  for

     This function is analogous to the writev() system call.  See
     writev(2).  However,  instead of sending out chunks of data,
     sendfilev() can read input data from data  buffers  or  file

     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. Point  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 to be transferred.

     The xferred parameter 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 containing the length of the buffer.

     The sendfilev() function supports the following parameters:

SunOS 5.8           Last change: 25 Apr 2001                    1

Extended Library Functions                        sendfilev(3EXT)

           A file descriptor to a regular file or  to  a  AF_NCA,
           AF_INET,  or  AF_INET6  family type SOCK_STREAM socket
           that is open for writing.  For  AF_NCA,  the  protocol
           type should be zero.

     vec   An array of SENDFILEVEC_T, as  defined  in  the  send-
           filevec structure above.

           The number of members in vec.

           The total number of bytes written to out_fd.

     Upon successful completion, sendfilev() returns total number
     of bytes written to out_fd. Otherwise,  it  returns  -1, and
     errno is set to indicate an  error.   xferred  contains  the
     amount of data successfuly transferred, which can be used to
     discover the error vector.

           The    implementation    does    not    support    the
           specified address family for socket.

           The socket type is not supported.

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

           The process does not have  appropriate  privileges  or
           one  of  the  files  pointed  by sfv_fd does not  have
           appropriate permissions.

           Out of memory.

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

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

           The vec argument points to an illegal address.

           The xferred argument points to an illegal address.

SunOS 5.8           Last change: 25 Apr 2001                    2

Extended Library Functions                        sendfilev(3EXT)

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

           This error code indicates one of the following:

              o  Mandatory file or record locking is set.

              o  O_NDELAY or O-NONBLOCK is set, and  there  is  a
                 blocking record lock.

              o  An attempt has been made to write  to  a  stream
                 that  cannot accept data with the O_NDELAY or O-
                 NONBLOCK flag set.

              o  A write to a pipe of FIFO of  PIP_BUF  bytes  or
                 less  is  requested and less than nbytes of free
                 space is available.

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

     The following example sends 2 vectors, one  of  HEADER  data
     and  a  file  of length 100 over sockfd. sockfd is in a con-
     nected state, that is, socket(), accept(), and bind() opera-
     tion are complete.

     #include <sys/sendfile.h>
     main (int argc, char eargv[]){
       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;

SunOS 5.8           Last change: 25 Apr 2001                    3

Extended Library Functions                        sendfilev(3EXT)

       vec[1].sfv_len = 100;

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

     See attributes(5)  for descriptions of the following  attri-

    |       ATTRIBUTE TYPE        |       ATTRIBUTE VALUE       |
    | Availability                | SUNWcsl(32 -bit)            |
    |                             | SUNWcslx (64-bit)           |
    | Interface Stability         | Evolving                    |
    | MT-Level                    | MT-Safe                     |

     open(2), writev(2), attributes(5)

View raw message