Squashed commit of the following:

psock_close() and net_close() are internal OS functions and should not set the errno variable.

    psock_ioctl() and netdev_ioctl() are internal OS functions and should not set the errno variable.

    net_dupsd() and net_dupsd2() are internal OS functions and should not set the errno variable.

    net/ and fs/: net_vfcntl(), file_fcntl(), file_dup(), and file_dup2() are all internal OS interfaces and should not modify the errno value.
This commit is contained in:
Gregory Nutt
2017-09-30 10:41:21 -06:00
parent 2c2aa94b7d
commit e4dd33280d
18 changed files with 251 additions and 180 deletions
+2 -3
View File
@@ -124,9 +124,8 @@ static void aio_write_worker(FAR void *arg)
oflags = file_fcntl(aioc->u.aioc_filep, F_GETFL); oflags = file_fcntl(aioc->u.aioc_filep, F_GETFL);
if (oflags < 0) if (oflags < 0)
{ {
int errcode = get_errno(); ferr("ERROR: file_fcntl failed: %d\n", oflags);
ferr("ERROR: fcntl failed: %d\n", errcode); aiocbp->aio_result = oflags;
aiocbp->aio_result = -errcode;
goto errout; goto errout;
} }
+12 -10
View File
@@ -190,19 +190,25 @@ void files_releaselist(FAR struct filelist *list)
* Assign an inode to a specific files structure. This is the heart of * Assign an inode to a specific files structure. This is the heart of
* dup2. * dup2.
* *
* Equivalent to the non-standard fs_dupfd2() function except that it
* accepts struct file instances instead of file descriptors and it does
* not set the errno variable.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is return on
* any failure.
*
****************************************************************************/ ****************************************************************************/
int file_dup2(FAR struct file *filep1, FAR struct file *filep2) int file_dup2(FAR struct file *filep1, FAR struct file *filep2)
{ {
FAR struct filelist *list; FAR struct filelist *list;
FAR struct inode *inode; FAR struct inode *inode;
int errcode;
int ret; int ret;
if (!filep1 || !filep1->f_inode || !filep2) if (!filep1 || !filep1->f_inode || !filep2)
{ {
errcode = EBADF; return -EBADF;
goto errout;
} }
list = sched_getfiles(); list = sched_getfiles();
@@ -228,7 +234,7 @@ int file_dup2(FAR struct file *filep1, FAR struct file *filep2)
{ {
/* An error occurred while closing the driver */ /* An error occurred while closing the driver */
goto errout_with_ret; goto errout_with_sem;
} }
/* Increment the reference count on the contained inode */ /* Increment the reference count on the contained inode */
@@ -286,17 +292,13 @@ errout_with_inode:
filep2->f_pos = 0; filep2->f_pos = 0;
filep2->f_inode = NULL; filep2->f_inode = NULL;
errout_with_ret: errout_with_sem:
errcode = -ret;
if (list != NULL) if (list != NULL)
{ {
_files_semgive(list); _files_semgive(list);
} }
errout: return ret;
set_errno(errcode);
return ERROR;
} }
/**************************************************************************** /****************************************************************************
+6
View File
@@ -102,6 +102,12 @@ int close(int fd)
if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS))
{ {
ret = net_close(fd); ret = net_close(fd);
if (ret < 0)
{
errcode = -ret;
goto errout;
}
leave_cancellation_point(); leave_cancellation_point();
return ret; return ret;
} }
+12 -4
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_dup.c * fs/vfs/fs_dup.c
* *
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2017 Gregory Nutt. All 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
@@ -69,7 +69,8 @@ int dup(int fd)
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS) if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
{ {
/* Its a valid file descriptor.. dup the file descriptor using any /* Its a valid file descriptor.. dup the file descriptor using any
* other file descriptor * other file descriptor. fd_dupfd() sets the errno value in the
* event of any failures.
*/ */
ret = fs_dupfd(fd, 0); ret = fs_dupfd(fd, 0);
@@ -82,7 +83,7 @@ int dup(int fd)
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS))
{ {
/* Yes.. dup the socket descriptor */ /* Yes.. dup the socket descriptor. The errno value is not set. */
ret = net_dupsd(fd, CONFIG_NFILE_DESCRIPTORS); ret = net_dupsd(fd, CONFIG_NFILE_DESCRIPTORS);
} }
@@ -91,7 +92,14 @@ int dup(int fd)
{ {
/* No.. then it is a bad descriptor number */ /* No.. then it is a bad descriptor number */
set_errno(EBADF); ret = -EBADF;
}
/* Set the errno value on failures */
if (ret < 0)
{
set_errno(-ret);
ret = ERROR; ret = ERROR;
} }
} }
+19 -6
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_dup2.c * fs/vfs/fs_dup2.c
* *
* Copyright (C) 2007-2009, 2011, 2013 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011, 2013, 2017 Gregory Nutt. All 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
@@ -73,25 +73,38 @@ int dup2(int fd1, int fd2)
if ((unsigned int)fd1 >= CONFIG_NFILE_DESCRIPTORS) if ((unsigned int)fd1 >= CONFIG_NFILE_DESCRIPTORS)
{ {
int ret;
/* Not a valid file descriptor. Did we get a valid socket descriptor? */ /* Not a valid file descriptor. Did we get a valid socket descriptor? */
if ((unsigned int)fd1 < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) if ((unsigned int)fd1 < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS))
{ {
/* Yes.. dup the socket descriptor */ /* Yes.. dup the socket descriptor. The errno value is not set. */
return net_dupsd2(fd1, fd2); ret = net_dupsd2(fd1, fd2);
} }
else else
{ {
/* No.. then it is a bad descriptor number */ /* No.. then it is a bad descriptor number */
set_errno(EBADF); ret = -EBADF;
return ERROR;
} }
/* Set the errno value on failures */
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
return ret;
} }
else else
{ {
/* Its a valid file descriptor.. dup the file descriptor */ /* Its a valid file descriptor.. dup the file descriptor. fd_dupfd()
* sets the errno value in the event of any failures.
*/
return fs_dupfd2(fd1, fd2); return fs_dupfd2(fd1, fd2);
} }
+23 -8
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_dupfd.c * fs/vfs/fs_dupfd.c
* *
* Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011-2014, 2017 Gregory Nutt. All 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
@@ -68,8 +68,12 @@
* *
* Description: * Description:
* Equivalent to the non-standard fs_dupfd() function except that it * Equivalent to the non-standard fs_dupfd() function except that it
* accepts a struct file instance instead of a file descriptor. Currently * accepts a struct file instance instead of a file descriptor and does
* used only by file_vfcntl(); * not set the errno variable.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure.
* *
****************************************************************************/ ****************************************************************************/
@@ -81,8 +85,7 @@ int file_dup(FAR struct file *filep, int minfd)
if (!DUP_ISOPEN(filep)) if (!DUP_ISOPEN(filep))
{ {
set_errno(EBADF); return -EBADF;
return ERROR;
} }
/* Increment the reference count on the contained inode */ /* Increment the reference count on the contained inode */
@@ -94,9 +97,8 @@ int file_dup(FAR struct file *filep, int minfd)
fd2 = files_allocate(filep->f_inode, filep->f_oflags, filep->f_pos, minfd); fd2 = files_allocate(filep->f_inode, filep->f_oflags, filep->f_pos, minfd);
if (fd2 < 0) if (fd2 < 0)
{ {
set_errno(EMFILE);
inode_release(filep->f_inode); inode_release(filep->f_inode);
return ERROR; return -EMFILE;
} }
return fd2; return fd2;
@@ -112,11 +114,17 @@ int file_dup(FAR struct file *filep, int minfd)
* descriptors. If socket descriptors are not implemented, then this * descriptors. If socket descriptors are not implemented, then this
* function IS dup(). * function IS dup().
* *
* Returned Value:
* fs_dupfd is sometimes an OS internal function and sometimes is a direct
* substitute for dup(). So it must return an errno value as though it
* were dup().
*
****************************************************************************/ ****************************************************************************/
int fs_dupfd(int fd, int minfd) int fs_dupfd(int fd, int minfd)
{ {
FAR struct file *filep; FAR struct file *filep;
int ret;
/* Get the file structure corresponding to the file descriptor. */ /* Get the file structure corresponding to the file descriptor. */
@@ -130,7 +138,14 @@ int fs_dupfd(int fd, int minfd)
/* Let file_dup() do the real work */ /* Let file_dup() do the real work */
return file_dup(filep, minfd); ret = file_dup(filep, minfd);
if (ret < 0)
{
set_errno(-ret);
return ERROR;
}
return OK;
} }
#endif /* CONFIG_NFILE_DESCRIPTORS > 0 */ #endif /* CONFIG_NFILE_DESCRIPTORS > 0 */
+14 -1
View File
@@ -70,6 +70,11 @@
* case of file descriptors. If socket descriptors are not implemented, * case of file descriptors. If socket descriptors are not implemented,
* then this function IS dup2(). * then this function IS dup2().
* *
* Returned Value:
* fs_dupfd is sometimes an OS internal function and sometimes is a direct
* substitute for dup2(). So it must return an errno value as though it
* were dup2().
*
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
@@ -80,6 +85,7 @@ int dup2(int fd1, int fd2)
{ {
FAR struct file *filep1; FAR struct file *filep1;
FAR struct file *filep2; FAR struct file *filep2;
int ret;
/* Get the file structures corresponding to the file descriptors. */ /* Get the file structures corresponding to the file descriptors. */
@@ -110,7 +116,14 @@ int dup2(int fd1, int fd2)
/* Perform the dup2 operation */ /* Perform the dup2 operation */
return file_dup2(filep1, filep2); ret = file_dup2(filep1, filep2);
if (ret < 0)
{
set_errno(-ret);
return ERROR;
}
return OK;
} }
#endif /* CONFIG_NFILE_DESCRIPTORS > 0 */ #endif /* CONFIG_NFILE_DESCRIPTORS > 0 */
+49 -21
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* fs/vfs/fs_fcntl.c * fs/vfs/fs_fcntl.c
* *
* Copyright (C) 2009, 2012-2014, 2016 Gregory Nutt. All rights reserved. * Copyright (C) 2009, 2012-2014, 2016-2017 Gregory Nutt. All 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
@@ -60,23 +60,30 @@
* *
* Description: * Description:
* Similar to the standard vfcntl function except that is accepts a struct * Similar to the standard vfcntl function except that is accepts a struct
* struct file instance instead of a file descriptor. Currently used * struct file instance instead of a file descriptor.
* only by aio_fcntl(); *
* Input Parameters:
* filep - Instance for struct file for the opened file.
* cmd - Indentifies the operation to be performed.
* ap - Variable argument following the command.
*
* Returned Value:
* The nature of the return value depends on the command. Non-negative
* values indicate success. Failures are reported as negated errno
* values.
* *
****************************************************************************/ ****************************************************************************/
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
int file_vfcntl(FAR struct file *filep, int cmd, va_list ap) int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
{ {
int errcode = 0; int ret;
int ret = OK;
/* Was this file opened ? */ /* Was this file opened ? */
if (!filep->f_inode) if (!filep->f_inode)
{ {
errcode = EBADF; return -EBADF;
goto errout;
} }
switch (cmd) switch (cmd)
@@ -93,6 +100,8 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
*/ */
{ {
/* Does not set the errno variable in the event of a failure */
ret = file_dup(filep, va_arg(ap, int)); ret = file_dup(filep, va_arg(ap, int));
} }
break; break;
@@ -112,7 +121,7 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
* successful execution of one of the exec functions. * successful execution of one of the exec functions.
*/ */
errcode = ENOSYS; ret = -ENOSYS;
break; break;
case F_GETFL: case F_GETFL:
@@ -162,7 +171,7 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
* fd does not refer to a socket, the results are unspecified. * fd does not refer to a socket, the results are unspecified.
*/ */
errcode = EBADF; /* Only valid on socket descriptors */ ret = -EBADF; /* Only valid on socket descriptors */
break; break;
case F_GETLK: case F_GETLK:
@@ -192,27 +201,35 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
* not be done. * not be done.
*/ */
errcode = ENOSYS; /* Not implemented */ ret = -ENOSYS; /* Not implemented */
break; break;
default: default:
errcode = EINVAL; ret = -EINVAL;
break; break;
} }
errout:
if (errcode != 0)
{
set_errno(errcode);
return ERROR;
}
return ret; return ret;
} }
#endif /* CONFIG_NFILE_DESCRIPTORS > 0 */ #endif /* CONFIG_NFILE_DESCRIPTORS > 0 */
/**************************************************************************** /****************************************************************************
* Name: fcntl * Name: fcntl
*
* Description:
* fcntl() will perform the operation specified by 'cmd' on an open file.
*
* Input Parameters:
* fd - File descriptor of the open file
* cmd - Identifies the operation to be performed. Command specific
* arguments may follow.
*
* Returned Value:
* The returned value depends on the nature of the command but for all
* commands the return value of -1 (ERROR) indicates that an error has
* occurred and, in this case, the errno variable will be set
* appropriately
*
****************************************************************************/ ****************************************************************************/
int fcntl(int fd, int cmd, ...) int fcntl(int fd, int cmd, ...)
@@ -246,7 +263,9 @@ int fcntl(int fd, int cmd, ...)
return ERROR; return ERROR;
} }
/* Let file_vfcntl() do the real work */ /* Let file_vfcntl() do the real work. The errno is not set on
* failures.
*/
ret = file_vfcntl(filep, cmd, ap); ret = file_vfcntl(filep, cmd, ap);
} }
@@ -258,7 +277,9 @@ int fcntl(int fd, int cmd, ...)
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS))
{ {
/* Yes.. defer socket descriptor operations to net_vfcntl() */ /* Yes.. defer socket descriptor operations to net_vfcntl(). The
* errno is not set on failures.
*/
ret = net_vfcntl(fd, cmd, ap); ret = net_vfcntl(fd, cmd, ap);
} }
@@ -267,11 +288,18 @@ int fcntl(int fd, int cmd, ...)
{ {
/* No.. this descriptor number is out of range */ /* No.. this descriptor number is out of range */
ret = EBADF; ret = -EBADF;
} }
} }
va_end(ap); va_end(ap);
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
leave_cancellation_point(); leave_cancellation_point();
return ret; return ret;
} }
+8 -1
View File
@@ -164,7 +164,14 @@ int ioctl(int fd, int req, unsigned long arg)
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS))
{ {
return netdev_ioctl(fd, req, arg); int ret = netdev_ioctl(fd, req, arg);
if (ret < 0)
{
errcode = -ret;
goto errout;
}
return ret;
} }
else else
#endif #endif
+41 -2
View File
@@ -606,6 +606,14 @@ void files_releaselist(FAR struct filelist *list);
* Assign an inode to a specific files structure. This is the heart of * Assign an inode to a specific files structure. This is the heart of
* dup2. * dup2.
* *
* Equivalent to the non-standard fs_dupfd2() function except that it
* accepts struct file instances instead of file descriptors and it does
* not set the errno variable.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is return on
* any failure.
*
****************************************************************************/ ****************************************************************************/
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
@@ -625,6 +633,11 @@ int file_dup2(FAR struct file *filep1, FAR struct file *filep2);
* This alternative naming is used when dup could operate on both file and * This alternative naming is used when dup could operate on both file and
* socket descriptors to avoid drawing unused socket support into the link. * socket descriptors to avoid drawing unused socket support into the link.
* *
* Returned Value:
* fs_dupfd is sometimes an OS internal function and sometimes is a direct
* substitute for dup(). So it must return an errno value as though it
* were dup().
*
****************************************************************************/ ****************************************************************************/
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
@@ -639,6 +652,18 @@ int fs_dupfd(int fd, int minfd);
* accepts a struct file instance instead of a file descriptor. Currently * accepts a struct file instance instead of a file descriptor. Currently
* used only by file_vfcntl(); * used only by file_vfcntl();
* *
/****************************************************************************
* Name: file_dup
*
* Description:
* Equivalent to the non-standard fs_dupfd() function except that it
* accepts a struct file instance instead of a file descriptor and does
* not set the errno variable.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure.
*
****************************************************************************/ ****************************************************************************/
int file_dup(FAR struct file *filep, int minfd); int file_dup(FAR struct file *filep, int minfd);
@@ -655,6 +680,11 @@ int file_dup(FAR struct file *filep, int minfd);
* This alternative naming is used when dup2 could operate on both file and * This alternative naming is used when dup2 could operate on both file and
* socket descritors to avoid drawing unused socket support into the link. * socket descritors to avoid drawing unused socket support into the link.
* *
* Returned Value:
* fs_dupfd2 is sometimes an OS internal function and sometimes is a direct
* substitute for dup2(). So it must return an errno value as though it
* were dup2().
*
****************************************************************************/ ****************************************************************************/
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
@@ -965,8 +995,17 @@ int file_ioctl(FAR struct file *filep, int req, unsigned long arg);
* *
* Description: * Description:
* Similar to the standard vfcntl function except that is accepts a struct * Similar to the standard vfcntl function except that is accepts a struct
* struct file instance instead of a file descriptor. Currently used * struct file instance instead of a file descriptor.
* only by aio_fcntl(); *
* Input Parameters:
* filep - Instance for struct file for the opened file.
* cmd - Indentifies the operation to be performed.
* ap - Variable argument following the command.
*
* Returned Value:
* The nature of the return value depends on the command. Non-negative
* values indicate success. Failures are reported as negated errno
* values.
* *
****************************************************************************/ ****************************************************************************/
+18 -12
View File
@@ -459,7 +459,8 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock);
* sockfd Socket descriptor of socket * sockfd Socket descriptor of socket
* *
* Returned Value: * Returned Value:
* 0 on success; -1 on error with errno set appropriately. * Returns zero (OK) on success. On failure, it returns a negated errno
* value to indicate the nature of the error.
* *
* Assumptions: * Assumptions:
* *
@@ -477,9 +478,8 @@ int net_close(int sockfd);
* psock Socket instance * psock Socket instance
* *
* Returned Value: * Returned Value:
* 0 on success; -1 on error with errno set appropriately. * Returns zero (OK) on success. On failure, it returns a negated errno
* * value to indicate the nature of the error.
* Assumptions:
* *
****************************************************************************/ ****************************************************************************/
@@ -994,8 +994,8 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option,
* arg The argument of the ioctl cmd * arg The argument of the ioctl cmd
* *
* Return: * Return:
* >=0 on success (positive non-zero values are cmd-specific) * A non-negative value is returned on success; a negated errno value is
* On a failure, -1 is returned with errno set appropriately * returned on any failure to indicate the nature of the failure:
* *
* EBADF * EBADF
* 'psock' is not a valid, connected socket structure. * 'psock' is not a valid, connected socket structure.
@@ -1027,8 +1027,8 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg);
* arg The argument of the ioctl cmd * arg The argument of the ioctl cmd
* *
* Return: * Return:
* >=0 on success (positive non-zero values are cmd-specific) * A non-negative value is returned on success; a negated errno value is
* On a failure, -1 is returned with errno set appropriately * returned on any failure to indicate the nature of the failure:
* *
* EBADF * EBADF
* 'sockfd' is not a valid socket descriptor. * 'sockfd' is not a valid socket descriptor.
@@ -1103,6 +1103,10 @@ int net_poll(int sockfd, struct pollfd *fds, bool setup);
* of socket file descriptors. If file descriptors are not implemented, * of socket file descriptors. If file descriptors are not implemented,
* then this function IS dup(). * then this function IS dup().
* *
* Returned Value:
* On success, returns the number of characters sent. On any error,
* a negated errno value is returned:.
*
****************************************************************************/ ****************************************************************************/
int net_dupsd(int sockfd, int minsd); int net_dupsd(int sockfd, int minsd);
@@ -1116,6 +1120,10 @@ int net_dupsd(int sockfd, int minsd);
* of socket file descriptors. If file descriptors are not implemented, * of socket file descriptors. If file descriptors are not implemented,
* then this function IS dup2(). * then this function IS dup2().
* *
* Returned Value:
* On success, returns the number of characters sent. On any error,
* a negated errno value is returned:.
*
****************************************************************************/ ****************************************************************************/
int net_dupsd2(int sockfd1, int sockfd2); int net_dupsd2(int sockfd1, int sockfd2);
@@ -1190,8 +1198,6 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2);
* In this case the process will also receive a SIGPIPE unless * In this case the process will also receive a SIGPIPE unless
* MSG_NOSIGNAL is set. * MSG_NOSIGNAL is set.
* *
* Assumptions:
*
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_SENDFILE #ifdef CONFIG_NET_SENDFILE
@@ -1211,8 +1217,8 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, size_t count
* ap - Command-specific arguments * ap - Command-specific arguments
* *
* Returned Value: * Returned Value:
* Zero (OK) is returned on success; -1 (ERROR) is returned on failure and * Zero (OK) is returned on success; a negated errno value is returned on
* the errno value is set appropriately. * any failure to indicate the nature of the failure.
* *
****************************************************************************/ ****************************************************************************/
+6 -18
View File
@@ -1323,8 +1323,8 @@ static int netdev_rt_ioctl(FAR struct socket *psock, int cmd,
* arg The argument of the ioctl cmd * arg The argument of the ioctl cmd
* *
* Return: * Return:
* >=0 on success (positive non-zero values are cmd-specific) * A non-negative value is returned on success; a negated errno value is
* On a failure, -1 is returned with errno set appropriately * returned on any failure to indicate the nature of the failure:
* *
* EBADF * EBADF
* 'psock' is not a valid, connected socket structure. * 'psock' is not a valid, connected socket structure.
@@ -1350,8 +1350,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
if (psock == NULL || psock->s_crefs <= 0) if (psock == NULL || psock->s_crefs <= 0)
{ {
ret = -EBADF; return -EBADF;
goto errout;
} }
/* Execute the command. First check for a standard network IOCTL command. */ /* Execute the command. First check for a standard network IOCTL command. */
@@ -1419,18 +1418,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
} }
#endif #endif
/* Check for success or failure */ return ret;
if (ret >= 0)
{
return ret;
}
/* On failure, set the errno and return -1 */
errout:
set_errno(-ret);
return ERROR;
} }
/**************************************************************************** /****************************************************************************
@@ -1445,8 +1433,8 @@ errout:
* arg The argument of the ioctl cmd * arg The argument of the ioctl cmd
* *
* Return: * Return:
* >=0 on success (positive non-zero values are cmd-specific) * A non-negative value is returned on success; a negated errno value is
* On a failure, -1 is returned with errno set appropriately * returned on any failure to indicate the nature of the failure:
* *
* EBADF * EBADF
* 'sockfd' is not a valid socket descriptor. * 'sockfd' is not a valid socket descriptor.
+7 -12
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* net/socket/net_close.c * net/socket/net_close.c
* *
* Copyright (C) 2007-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2017 Gregory Nutt. All 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
@@ -67,7 +67,8 @@
* psock Socket instance * psock Socket instance
* *
* Returned Value: * Returned Value:
* 0 on success; -1 on error with errno set appropriately. * Returns zero (OK) on success. On failure, it returns a negated errno
* value to indicate the nature of the error.
* *
* Assumptions: * Assumptions:
* *
@@ -75,15 +76,13 @@
int psock_close(FAR struct socket *psock) int psock_close(FAR struct socket *psock)
{ {
int errcode;
int ret; int ret;
/* Verify that the sockfd corresponds to valid, allocated socket */ /* Verify that the sockfd corresponds to valid, allocated socket */
if (!psock || psock->s_crefs <= 0) if (!psock || psock->s_crefs <= 0)
{ {
errcode = EBADF; return -EBADF;
goto errout;
} }
/* We perform the close operation only if this is the last count on /* We perform the close operation only if this is the last count on
@@ -105,8 +104,7 @@ int psock_close(FAR struct socket *psock)
if (ret < 0) if (ret < 0)
{ {
errcode = -ret; return ret;
goto errout;
} }
} }
@@ -114,10 +112,6 @@ int psock_close(FAR struct socket *psock)
sock_release(psock); sock_release(psock);
return OK; return OK;
errout:
set_errno(errcode);
return ERROR;
} }
/**************************************************************************** /****************************************************************************
@@ -130,7 +124,8 @@ errout:
* sockfd Socket descriptor of socket * sockfd Socket descriptor of socket
* *
* Returned Value: * Returned Value:
* 0 on success; -1 on error with errno set appropriately. * Returns zero (OK) on success. On failure, it returns a negated errno
* value to indicate the nature of the error.
* *
* Assumptions: * Assumptions:
* *
+14 -11
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* net/socket/net_dupsd.c * net/socket/net_dupsd.c
* *
* Copyright (C) 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2009, 2017 Gregory Nutt. All 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
@@ -61,6 +61,10 @@
* of socket file descriptors. If file descriptors are not implemented, * of socket file descriptors. If file descriptors are not implemented,
* then this function IS dup(). * then this function IS dup().
* *
* Returned Value:
* On success, returns the number of characters sent. On any error,
* a negated errno value is returned:.
*
****************************************************************************/ ****************************************************************************/
int net_dupsd(int sockfd, int minsd) int net_dupsd(int sockfd, int minsd)
@@ -68,7 +72,6 @@ int net_dupsd(int sockfd, int minsd)
FAR struct socket *psock1; FAR struct socket *psock1;
FAR struct socket *psock2; FAR struct socket *psock2;
int sockfd2; int sockfd2;
int errcode;
int ret; int ret;
/* Make sure that the minimum socket descriptor is within the legal range. /* Make sure that the minimum socket descriptor is within the legal range.
@@ -99,7 +102,7 @@ int net_dupsd(int sockfd, int minsd)
if (!psock1 || psock1->s_crefs <= 0) if (!psock1 || psock1->s_crefs <= 0)
{ {
errcode = EBADF; ret = -EBADF;
goto errout; goto errout;
} }
@@ -108,7 +111,7 @@ int net_dupsd(int sockfd, int minsd)
sockfd2 = sockfd_allocate(minsd); sockfd2 = sockfd_allocate(minsd);
if (sockfd2 < 0) if (sockfd2 < 0)
{ {
errcode = ENFILE; ret = -ENFILE;
goto errout; goto errout;
} }
@@ -117,8 +120,8 @@ int net_dupsd(int sockfd, int minsd)
psock2 = sockfd_socket(sockfd2); psock2 = sockfd_socket(sockfd2);
if (!psock2) if (!psock2)
{ {
errcode = ENOSYS; /* should not happen */ ret = -ENOSYS; /* Should not happen */
goto errout; goto errout_with_sockfd;
} }
/* Duplicate the socket state */ /* Duplicate the socket state */
@@ -126,18 +129,18 @@ int net_dupsd(int sockfd, int minsd)
ret = net_clone(psock1, psock2); ret = net_clone(psock1, psock2);
if (ret < 0) if (ret < 0)
{ {
errcode = -ret; goto errout_with_sockfd;
goto errout;
} }
sched_unlock(); sched_unlock();
return sockfd2; return sockfd2;
errout_with_sockfd:
sockfd_release(sockfd2);
errout: errout:
sched_unlock(); sched_unlock();
set_errno(errcode); return ret;
return ERROR;
} }
#endif /* defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 */ #endif /* defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 */
+9 -13
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* net/socket/net_dupsd2.c * net/socket/net_dupsd2.c
* *
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2009, 2011, 2017 Gregory Nutt. All 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
@@ -44,6 +44,8 @@
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
#include <nuttx/net/net.h>
#include "socket/socket.h" #include "socket/socket.h"
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
@@ -61,6 +63,10 @@
* of socket file descriptors. If file descriptors are not implemented, * of socket file descriptors. If file descriptors are not implemented,
* then this function IS dup2(). * then this function IS dup2().
* *
* Returned Value:
* On success, returns the number of characters sent. On any error,
* a negated errno value is returned:.
*
****************************************************************************/ ****************************************************************************/
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
@@ -71,7 +77,6 @@ int dup2(int sockfd1, int sockfd2)
{ {
FAR struct socket *psock1; FAR struct socket *psock1;
FAR struct socket *psock2; FAR struct socket *psock2;
int errcode;
int ret; int ret;
/* Lock the scheduler throughout the following */ /* Lock the scheduler throughout the following */
@@ -89,7 +94,7 @@ int dup2(int sockfd1, int sockfd2)
if (!psock1 || !psock2 || psock1->s_crefs <= 0) if (!psock1 || !psock2 || psock1->s_crefs <= 0)
{ {
errcode = EBADF; ret = -EBADF;
goto errout; goto errout;
} }
@@ -105,19 +110,10 @@ int dup2(int sockfd1, int sockfd2)
/* Duplicate the socket state */ /* Duplicate the socket state */
ret = net_clone(psock1, psock2); ret = net_clone(psock1, psock2);
if (ret < 0)
{
errcode = -ret;
goto errout;
}
sched_unlock();
return OK;
errout: errout:
sched_unlock(); sched_unlock();
set_errno(errcode); return ret;
return ERROR;
} }
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS > 0 */ #endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS > 0 */
-2
View File
@@ -115,8 +115,6 @@
* In this case the process will also receive a SIGPIPE unless * In this case the process will also receive a SIGPIPE unless
* MSG_NOSIGNAL is set. * MSG_NOSIGNAL is set.
* *
* Assumptions:
*
****************************************************************************/ ****************************************************************************/
ssize_t net_sendfile(int outfd, FAR struct file *infile, FAR off_t *offset, ssize_t net_sendfile(int outfd, FAR struct file *infile, FAR off_t *offset,
+11 -20
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* net/socket/net_vfcntl.c * net/socket/net_vfcntl.c
* *
* Copyright (C) 2009, 2012-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2009, 2012-2015, 2017 Gregory Nutt. All 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
@@ -70,16 +70,15 @@
* ap - Command-specific arguments * ap - Command-specific arguments
* *
* Returned Value: * Returned Value:
* Zero (OK) is returned on success; -1 (ERROR) is returned on failure and * Zero (OK) is returned on success; a negated errno value is returned on
* the errno value is set appropriately. * any failure to indicate the nature of the failure.
* *
****************************************************************************/ ****************************************************************************/
int net_vfcntl(int sockfd, int cmd, va_list ap) int net_vfcntl(int sockfd, int cmd, va_list ap)
{ {
FAR struct socket *psock = sockfd_socket(sockfd); FAR struct socket *psock = sockfd_socket(sockfd);
int errcode = 0; int ret;
int ret = 0;
ninfo("sockfd=%d cmd=%d\n", sockfd, cmd); ninfo("sockfd=%d cmd=%d\n", sockfd, cmd);
@@ -87,8 +86,7 @@ int net_vfcntl(int sockfd, int cmd, va_list ap)
if (psock == NULL || psock->s_crefs <= 0) if (psock == NULL || psock->s_crefs <= 0)
{ {
errcode = EBADF; return -EBADF;
goto errout;
} }
/* Interrupts must be disabled in order to perform operations on socket structures */ /* Interrupts must be disabled in order to perform operations on socket structures */
@@ -108,6 +106,8 @@ int net_vfcntl(int sockfd, int cmd, va_list ap)
*/ */
{ {
/* Does not set the errno value on failure */
ret = net_dupsd(sockfd, va_arg(ap, int)); ret = net_dupsd(sockfd, va_arg(ap, int));
} }
break; break;
@@ -127,7 +127,7 @@ int net_vfcntl(int sockfd, int cmd, va_list ap)
* successful execution of one of the exec functions. * successful execution of one of the exec functions.
*/ */
errcode = ENOSYS; /* F_GETFD and F_SETFD not implemented */ ret = -ENOSYS; /* F_GETFD and F_SETFD not implemented */
break; break;
case F_GETFL: case F_GETFL:
@@ -245,25 +245,16 @@ int net_vfcntl(int sockfd, int cmd, va_list ap)
* not be done. * not be done.
*/ */
errcode = ENOSYS; /* F_GETOWN, F_SETOWN, F_GETLK, F_SETLK, F_SETLKW */ ret = -ENOSYS; /* F_GETOWN, F_SETOWN, F_GETLK, F_SETLK, F_SETLKW */
break; break;
default: default:
errcode = EINVAL; ret = -EINVAL;
break; break;
}
net_unlock();
errout:
if (errcode != 0)
{
set_errno(errcode);
return ERROR;
} }
net_unlock();
return ret; return ret;
} }
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS > 0 */ #endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS > 0 */
-36
View File
@@ -231,42 +231,6 @@ FAR struct socket *sockfd_socket(int sockfd);
FAR const struct sock_intf_s *net_sockif(sa_family_t family); FAR const struct sock_intf_s *net_sockif(sa_family_t family);
/****************************************************************************
* Name: psock_close
*
* Description:
* Performs the close operation on a socket instance
*
* Parameters:
* psock Socket instance
*
* Returned Value:
* 0 on success; -1 on error with errno set appropriately.
*
* Assumptions:
*
****************************************************************************/
int psock_close(FAR struct socket *psock);
/****************************************************************************
* Name: net_close
*
* Description:
* Performs the close operation on socket descriptors
*
* Parameters:
* sockfd Socket descriptor of socket
*
* Returned Value:
* 0 on success; -1 on error with errno set appropriately.
*
* Assumptions:
*
****************************************************************************/
int net_close(int sockfd);
/**************************************************************************** /****************************************************************************
* Name: net_timeo * Name: net_timeo
* *