MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Extended Library Functions                        sendfilev(3EXT)



NAME
     sendfilev - send a file

SYNOPSIS
     cc [ flag... ] file... -lsendfile  [ library... ]
     #include 

     ssizet sendfilev(int fildes, const struct sendfilevec *vec,
          int sfvcnt, sizet *xferred);


PARAMETERS
     The sendfilev() function supports the following parameters:

     fildes     A file descriptor to  a  regular  file  or  to  a
                AFNCA,   AFINET,   or   AFINET6   family  type
                SOCKSTREAM socket that is open for writing.  For
                AFNCA, the protocol type should be zero.


     vec        An array of  SENDFILEVECT,  as  defined  in  the
                sendfilevec structure above.


     sfvcnt     The number of members in vec.


     xferred    The total number of bytes written to outfd.


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 AFNCA,
     AFINET, or AFINET6 family type SOCKSTREAM 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     sfvfd;         /* input fd */
               uintt  sfvflag;       /* Flags. see below */



SunOS 5.11          Last change: 25 Feb 2009                    1






Extended Library Functions                        sendfilev(3EXT)



               offt   sfvoff;        /* offset to start reading from */
               sizet  sfvlen;        /* amount of data */
       } sendfilevect;

       #define SFVFDSELF     (-2)



     To send a file, open the file for reading and  point  sfvfd
     to  the  file  descriptor returned as a result. See open(2).
     sfvoff should contain the offset within the  file.  sfvlen
     should have the length of the file to be transferred.


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


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


     To send data directly from the address space of the process,
     set sfvfd to SFVFDSELF. sfvoff should point to the data,
     with sfvlen containing the length of the buffer.

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

ERORS
     EACES          The  process  does  not   have   appropriate
                     privileges  or  one  of the files pointed by
                     sfvfd does not   have  appropriate  permis-
                     sions.


     EAFNOSUPORT    The  implementation  does  not  support  the
                     specified address 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.
                     ONDELAY  or ONONBLOCK 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  ONDELAY  or  the  ONONBLOCK
                     flag set.




SunOS 5.11          Last change: 25 Feb 2009                    2






Extended Library Functions                        sendfilev(3EXT)



     EBADF           The fildes argument is not a valid  descrip-
                     tor open for writing or an sfvfd is invalid
                     or not open for reading.


     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  opera-
                     tion and no data was transferred.


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

                     Fewer  bytes  were  transferred  than   were
                     requested.


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


     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(5).

EXAMPLES
     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 
       .
       .
       .
       int
       main (int argc, char *argv[]){



SunOS 5.11          Last change: 25 Feb 2009                    3






Extended Library Functions                        sendfilev(3EXT)



         int sockfd;
         ssizet ret;
         sizet xfer;
         struct sendfilevec vec[2];
           .
           .
           .
         vec[0].sfvfd = SFVFDSELF;
         vec[0].sfvflag = 0;
         vec[0].sfvoff = "HEADERDATA";
         vec[0].sfvlen = strlen("HEADERDATA");
         vec[1].sfvfd = open("inputfile",.... );
         vec[1].sfvflag = 0;
         vec[1].sfvoff = 0;
         vec[1].sfvlen = 100;

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


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



     
           ATRIBUTE TYPE               ATRIBUTE VALUE       
    
     Interface Stability          Committed                   
    
     MT-Level                     MT-Safe                     
    


SEE ALSO
     open(2),   writev(2),   libsendfile(3LIB),   sendfile(3EXT),
     socket(3SOCKET), attributes(5)














SunOS 5.11          Last change: 25 Feb 2009                    4



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™