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 * fs/vfs/fs_sendfile.c
* *
* Copyright (C) 2007, 2009, 2011, 2013, 2017 Gregory Nutt. All rights * Copyright (C) 2007, 2009, 2011, 2013, 2017-2018 Gregory Nutt. All
* reserved. * rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * 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) 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 /* Check the destination file descriptor: Is it a (probable) file
* descriptor? Check the source file: Is it a normal 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. */ /* Then let net_sendfile do the work. */
return net_sendfile(outfd, filep, offset, count); ret = net_sendfile(outfd, filep, offset, count);
} if (ret >= 0 || get_errno() != ENOSYS)
else {
#endif return ret;
{ }
/* 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); /* 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 */ #endif /* CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_SENDFILE */

View File

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

View File

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

View File

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

View File

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

View File

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