2008-11-16 19:48:29 +01:00
|
|
|
/****************************************************************************
|
2014-06-29 01:25:18 +02:00
|
|
|
* net/socket/net_poll.c
|
2008-11-16 19:48:29 +01:00
|
|
|
*
|
2017-07-14 18:57:38 +02:00
|
|
|
* Copyright (C) 2008-2009, 2011-2015, 2017 Gregory Nutt. All rights reserved.
|
2012-01-30 22:29:59 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2008-11-16 19:48:29 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2017-07-14 18:57:38 +02:00
|
|
|
#include <assert.h>
|
2008-11-16 19:48:29 +01:00
|
|
|
#include <errno.h>
|
2008-11-18 23:14:25 +01:00
|
|
|
|
2017-07-14 18:57:38 +02:00
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
|
2014-06-29 01:25:18 +02:00
|
|
|
#include "socket/socket.h"
|
2008-11-16 19:48:29 +01:00
|
|
|
|
2008-11-18 18:30:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
2008-11-16 19:48:29 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: psock_poll
|
2008-11-16 19:48:29 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The standard poll() operation redirects operations on socket descriptors
|
|
|
|
* to this function.
|
|
|
|
*
|
2008-11-18 18:30:30 +01:00
|
|
|
* Input Parameters:
|
2013-01-24 20:19:38 +01:00
|
|
|
* psock - An instance of the internal socket structure.
|
2008-11-19 19:43:50 +01:00
|
|
|
* fds - The structure describing the events to be monitored, OR NULL if
|
|
|
|
* this is a request to stop monitoring events.
|
2009-12-15 16:57:25 +01:00
|
|
|
* setup - true: Setup up the poll; false: Teardown the poll
|
2008-11-16 19:48:29 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2008-11-18 18:30:30 +01:00
|
|
|
* 0: Success; Negated errno on failure
|
2008-11-16 19:48:29 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-01-24 20:19:38 +01:00
|
|
|
int psock_poll(FAR struct socket *psock, FAR struct pollfd *fds, bool setup)
|
2008-11-16 19:48:29 +01:00
|
|
|
{
|
2017-07-14 18:57:38 +02:00
|
|
|
DEBUGASSERT(psock != NULL && fds != NULL);
|
2017-03-31 16:58:14 +02:00
|
|
|
|
2017-07-14 18:57:38 +02:00
|
|
|
/* Let the address family's poll() method handle the operation */
|
2013-05-23 15:16:46 +02:00
|
|
|
|
2017-07-14 18:57:38 +02:00
|
|
|
DEBUGASSERT(psock->s_sockif != NULL && psock->s_sockif->si_poll != NULL);
|
|
|
|
return psock->s_sockif->si_poll(psock, fds, setup);
|
2013-01-24 20:19:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: net_poll
|
2013-01-24 20:19:38 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The standard poll() operation redirects operations on socket descriptors
|
|
|
|
* to this function.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* fd - The socket descriptor of interest
|
|
|
|
* fds - The structure describing the events to be monitored, OR NULL if
|
|
|
|
* this is a request to stop monitoring events.
|
|
|
|
* setup - true: Setup up the poll; false: Teardown the poll
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0: Success; Negated errno on failure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int net_poll(int sockfd, struct pollfd *fds, bool setup)
|
|
|
|
{
|
|
|
|
FAR struct socket *psock;
|
|
|
|
|
2017-07-14 18:57:38 +02:00
|
|
|
DEBUGASSERT(fds != NULL);
|
|
|
|
|
2013-01-24 20:19:38 +01:00
|
|
|
/* Get the underlying socket structure and verify that the sockfd
|
|
|
|
* corresponds to valid, allocated socket
|
|
|
|
*/
|
|
|
|
|
|
|
|
psock = sockfd_socket(sockfd);
|
|
|
|
if (!psock || psock->s_crefs <= 0)
|
|
|
|
{
|
|
|
|
return -EBADF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then let psock_poll() do the heavy lifting */
|
|
|
|
|
|
|
|
return psock_poll(psock, fds, setup);
|
2008-11-16 19:48:29 +01:00
|
|
|
}
|