Exemple #1
0
ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count)
{
#if defined(CONFIG_NET_TCP) && CONFIG_NSOCKET_DESCRIPTORS > 0

  /* Check the destination file descriptor:  Is it a (probable) file
   * descriptor?  Check the source file:  Is it a normal file?
   */

  if ((unsigned int)outfd >= CONFIG_NFILE_DESCRIPTORS &&
      (unsigned int)infd < CONFIG_NFILE_DESCRIPTORS)
    {
      FAR struct filelist *list;

      /* This appears to be a file-to-socket transfer.  Get the thread-
       * specific file list.
       */

      list = sched_getfiles();
      DEBUGASSERT(list);

      /* Then let net_sendfile do the work. */

      return net_sendfile(outfd, &list->fl_files[infd], offset, count);
    }
  else
#endif
    {
      /* No... then this is probably a file-to-file transfer.  The generic
       * lib_sendfile() can handle that case.
       */

      return lib_sendfile(outfd, infd, offset, count);
    }
}
Exemple #2
0
ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count)
{
#if defined(CONFIG_NET_TCP) && CONFIG_NSOCKET_DESCRIPTORS > 0

    /* Check the destination file descriptor:  Is it a (probable) file
     * descriptor?  Check the source file:  Is it a normal file?
     */

    if ((unsigned int)outfd >= CONFIG_NFILE_DESCRIPTORS &&
            (unsigned int)infd < CONFIG_NFILE_DESCRIPTORS)
    {
        FAR struct file *filep;

        /* This appears to be a file-to-socket transfer.  Get the file
         * structure.
         */

        filep = fs_getfilep(fd);
        if (!filep)
        {
            /* The errno value has already been set */

            return ERROR;
        }

        /* Then let net_sendfile do the work. */

        return net_sendfile(outfd, filep, offset, count);
    }
    else
#endif
    {
        /* No... then this is probably a file-to-file transfer.  The generic
         * lib_sendfile() can handle that case.
         */

        return lib_sendfile(outfd, infd, offset, count);
    }
}