Fix compiler error and warning when CONFIG_NET_SENDFILE=y

This commit is contained in:
Xiang Xiao 2018-11-09 11:17:43 -06:00 committed by Gregory Nutt
parent 9d2e6cf66a
commit d2cfd398ba
6 changed files with 42 additions and 42 deletions

View file

@ -1,8 +1,8 @@
/****************************************************************************
* fs/vfs/fs_sendfile.c
*
* Copyright (C) 2007, 2009, 2011, 2013, 2017 Gregory Nutt. All rights
* reserved.
* Copyright (C) 2007, 2009, 2011, 2013, 2017-2018 Gregory Nutt. All
* rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -103,7 +103,7 @@
ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count)
{
#if defined(CONFIG_NET_TCP) && CONFIG_NSOCKET_DESCRIPTORS > 0
#if defined(CONFIG_NET_SENDFILE) && CONFIG_NSOCKET_DESCRIPTORS > 0
/* Check the destination file descriptor: Is it a (probable) file
* descriptor? Check the source file: Is it a normal file?
*/
@ -129,17 +129,23 @@ ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count)
/* 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.
*/
ret = net_sendfile(outfd, filep, offset, count);
if (ret >= 0 || get_errno() != ENOSYS)
{
return ret;
}
return lib_sendfile(outfd, infd, offset, count);
/* Fall back to the slow path if errno equals ENOSYS,
* because net_sendfile fail to optimize this transfer.
*/
}
#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);
}
#endif /* CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_SENDFILE */

View file

@ -148,6 +148,7 @@ typedef uint8_t sockcaps_t;
* a given address family.
*/
struct file; /* Forward reference */
struct socket; /* Forward reference */
struct pollfd; /* Forward reference */

View file

@ -1284,10 +1284,13 @@ static ssize_t inet_sendfile(FAR struct socket *psock,
size_t count)
{
#if defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_TCP_NO_STACK)
return tcp_sendfile(psock, infile, offset, size_t count);
#else
return -ENOSYS;
if (psock->s_type == SOCK_STREAM)
{
return tcp_sendfile(psock, infile, offset, count);
}
#endif
return -ENOSYS;
}
#endif

View file

@ -45,6 +45,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
@ -121,18 +122,17 @@ ssize_t net_sendfile(int outfd, FAR struct file *infile, FAR off_t *offset,
size_t count)
{
FAR struct socket *psock = sockfd_socket(outfd);
ssize_t ret;
int errcode;
ssize_t ret = -ENOSYS;
DEBUGASSERT(psock->sock != NULL && infile != NULL);
DEBUGASSERT(psock != NULL && infile != NULL);
/* Verify that the sockfd corresponds to valid, allocated socket */
if (psock != NULL || psock->s_crefs <= 0)
{
nerr("ERROR: Invalid socket\n");
errcode = EBADF;
goto errout;
set_errno(EBADF);
return ERROR;
}
/* Check if the address family supports the optimized sendfile(). If not,
@ -142,30 +142,21 @@ ssize_t net_sendfile(int outfd, FAR struct file *infile, FAR off_t *offset,
* method in the socket interface.
*/
DEBUGASSERT(psock->sockif != NULL);
if (psock->sockif->s_sendfile == NULL)
{
int infd;
list = sched_getfiles();
DEBUGASSERT(list != NULL);
infd = infile - list->fl_files;
return lib_sendfile(outfd, infd, offset, count);
}
else
DEBUGASSERT(psock->s_sockif != NULL);
if (psock->s_sockif->si_sendfile != NULL)
{
/* The address family can handle the optimized file send */
ret = psock->sockif->s_sendfile(psock, offset, count);
if (ret < 0)
{
set_errno(-ret);
return ERROR;
}
return ret;
ret = psock->s_sockif->si_sendfile(psock, infile, offset, count);
}
if (ret < 0)
{
set_errno(-ret);
return ERROR;
}
return ret;
}
#endif /* CONFIG_NET_SENDFILE */

View file

@ -326,6 +326,7 @@ EXTERN struct net_driver_s *g_netdevices;
* Public Function Prototypes
****************************************************************************/
struct file; /* Forward reference */
struct sockaddr; /* Forward reference */
struct socket; /* Forward reference */
struct pollfd; /* Forward reference */

View file

@ -726,8 +726,6 @@ errout_locked:
nxsem_destroy(&state. snd_sem);
net_unlock();
errout:
if (ret < 0)
{
return ret;