summaryrefslogtreecommitdiff
path: root/nuttx/drivers
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-18 17:30:30 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-18 17:30:30 +0000
commit1994f6983332bf79b4ea8d3f242dc710f99cf2e9 (patch)
tree414ecfd618101a507bf1b3c9263cd067b2ad7b9b /nuttx/drivers
parent3a3f46b691da1747881032dec6f5b5af2c308cdd (diff)
downloadpx4-nuttx-1994f6983332bf79b4ea8d3f242dc710f99cf2e9.tar.gz
px4-nuttx-1994f6983332bf79b4ea8d3f242dc710f99cf2e9.tar.bz2
px4-nuttx-1994f6983332bf79b4ea8d3f242dc710f99cf2e9.zip
Implement poll/select for sockets
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1277 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers')
-rw-r--r--nuttx/drivers/dev_null.c6
-rw-r--r--nuttx/drivers/dev_zero.c6
-rw-r--r--nuttx/drivers/pipe_common.c21
-rw-r--r--nuttx/drivers/pipe_common.h2
-rw-r--r--nuttx/drivers/serial.c21
5 files changed, 29 insertions, 27 deletions
diff --git a/nuttx/drivers/dev_null.c b/nuttx/drivers/dev_null.c
index 8db8c3cbb..cada981fe 100644
--- a/nuttx/drivers/dev_null.c
+++ b/nuttx/drivers/dev_null.c
@@ -56,7 +56,7 @@
static ssize_t devnull_read(FAR struct file *, FAR char *, size_t);
static ssize_t devnull_write(FAR struct file *, FAR const char *, size_t);
#ifndef CONFIG_DISABLE_POLL
-static int devnull_poll(FAR struct file *filp, FAR struct pollfd *poll);
+static int devnull_poll(FAR struct file *filp, FAR struct pollfd *fds, boolean setup);
#endif
/****************************************************************************
@@ -103,9 +103,9 @@ static ssize_t devnull_write(FAR struct file *filp, FAR const char *buffer, size
****************************************************************************/
#ifndef CONFIG_DISABLE_POLL
-static int devnull_poll(FAR struct file *filp, FAR struct pollfd *fds)
+static int devnull_poll(FAR struct file *filp, FAR struct pollfd *fds, boolean setup)
{
- if (fds)
+ if (setup)
{
fds->revents |= (fds->events & (POLLIN|POLLOUT));
if (fds->revents != 0)
diff --git a/nuttx/drivers/dev_zero.c b/nuttx/drivers/dev_zero.c
index 08815ace5..13276ca7a 100644
--- a/nuttx/drivers/dev_zero.c
+++ b/nuttx/drivers/dev_zero.c
@@ -56,7 +56,7 @@
static ssize_t devzero_read(FAR struct file *, FAR char *, size_t);
static ssize_t devzero_write(FAR struct file *, FAR const char *, size_t);
#ifndef CONFIG_DISABLE_POLL
-static int devzero_poll(FAR struct file *filp, FAR struct pollfd *fds);
+static int devzero_poll(FAR struct file *filp, FAR struct pollfd *fds, boolean setup);
#endif
/****************************************************************************
@@ -104,9 +104,9 @@ static ssize_t devzero_write(FAR struct file *filp, FAR const char *buffer, size
****************************************************************************/
#ifndef CONFIG_DISABLE_POLL
-static int devzero_poll(FAR struct file *filp, FAR struct pollfd *fds)
+static int devzero_poll(FAR struct file *filp, FAR struct pollfd *fds, boolean setup)
{
- if (fds)
+ if (setup)
{
fds->revents |= (fds->events & (POLLIN|POLLOUT));
if (fds->revents != 0)
diff --git a/nuttx/drivers/pipe_common.c b/nuttx/drivers/pipe_common.c
index 87d496f62..72fea8006 100644
--- a/nuttx/drivers/pipe_common.c
+++ b/nuttx/drivers/pipe_common.c
@@ -517,7 +517,7 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t
****************************************************************************/
#ifndef CONFIG_DISABLE_POLL
-int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds)
+int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds, boolean setup)
{
FAR struct inode *inode = filep->f_inode;
FAR struct pipe_dev_s *dev = inode->i_private;
@@ -539,7 +539,7 @@ int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds)
for (i = 0; i < CONFIG_DEV_PIPE_NPOLLWAITERS; i++)
{
/* Find the slot with the value equal to filep->f_priv. If there
- * is not previously installed poll structure, then f_priv will
+ * is no previously installed poll structure, then f_priv will
* be NULL and we will find the first unused slot. If f_priv is
* is non-NULL, then we will find the slot that was used for the
* previous setup.
@@ -547,14 +547,14 @@ int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds)
if (dev->d_fds[i] == filep->f_priv)
{
- dev->d_fds[i] = fds;
+ dev->d_fds[i] = (setup ? fds : NULL);
break;
}
}
if (i >= CONFIG_DEV_PIPE_NPOLLWAITERS)
{
- DEBUGASSERT(fds == NULL);
+ DEBUGASSERT(setup);
return -EBUSY;
}
@@ -562,13 +562,16 @@ int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds)
* private data.
*/
- filep->f_priv = fds;
+ filep->f_priv = NULL; /* Assume teardown */
+ if (setup)
+ {
+ /* Set the poll event structure reference in the 'struct file' private data. */
- /* Check if we should immediately notify on any of the requested events */
+ filep->f_priv = fds;
- if (fds)
- {
- /* Determine how many bytes are in the buffer */
+ /* Check if we should immediately notify on any of the requested events. First,
+ * Determine how many bytes are in the buffer
+ */
if (dev->d_wrndx >= dev->d_rdndx)
{
diff --git a/nuttx/drivers/pipe_common.h b/nuttx/drivers/pipe_common.h
index 05edd9ca2..0f2247766 100644
--- a/nuttx/drivers/pipe_common.h
+++ b/nuttx/drivers/pipe_common.h
@@ -123,7 +123,7 @@ EXTERN int pipecommon_close(FAR struct file *filep);
EXTERN ssize_t pipecommon_read(FAR struct file *, FAR char *, size_t);
EXTERN ssize_t pipecommon_write(FAR struct file *, FAR const char *, size_t);
#ifndef CONFIG_DISABLE_POLL
-EXTERN int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds);
+EXTERN int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds, boolean setup);
#endif
#undef EXTERN
diff --git a/nuttx/drivers/serial.c b/nuttx/drivers/serial.c
index 533675886..0effeff00 100644
--- a/nuttx/drivers/serial.c
+++ b/nuttx/drivers/serial.c
@@ -79,7 +79,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen
static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t buflen);
static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
#ifndef CONFIG_DISABLE_POLL
-static int uart_poll(FAR struct file *filep, FAR struct pollfd *fds);
+static int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, boolean setup);
#endif
/************************************************************************************
@@ -400,7 +400,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
****************************************************************************/
#ifndef CONFIG_DISABLE_POLL
-int uart_poll(FAR struct file *filep, FAR struct pollfd *fds)
+int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, boolean setup)
{
FAR struct inode *inode = filep->f_inode;
FAR uart_dev_t *dev = inode->i_private;
@@ -422,7 +422,7 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds)
for (i = 0; i < CONFIG_DEV_CONSOLE_NPOLLWAITERS; i++)
{
/* Find the slot with the value equal to filep->f_priv. If there
- * is not previously installed poll structure, then f_priv will
+ * is no previously installed poll structure, then f_priv will
* be NULL and we will find the first unused slot. If f_priv is
* is non-NULL, then we will find the slot that was used for the
* previous setup.
@@ -430,14 +430,14 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds)
if (dev->fds[i] == filep->f_priv)
{
- dev->fds[i] = fds;
+ dev->fds[i] = (setup ? fds : NULL);
break;
}
}
if (i >= CONFIG_DEV_CONSOLE_NPOLLWAITERS)
{
- DEBUGASSERT(fds == NULL);
+ DEBUGASSERT(setup);
return -EBUSY;
}
@@ -445,13 +445,12 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds)
* private data.
*/
- filep->f_priv = fds;
-
- /* Check if we should immediately notify on any of the requested events */
-
- if (fds)
+ filep->f_priv = NULL; /* Assume teardown */
+ if (setup)
{
- /* Check if the xmit buffer is full. */
+ /* Check if we should immediately notify on any of the requested events.
+ * First, check if the xmit buffer is full.
+ */
eventset = 0;