You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/07 13:10:53 UTC

[incubator-nuttx] 04/07: telnet driver should return -EAGAIN if O_NONBLOCK is active

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr215
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 386b2d834ad4c1f655fa544dfc1ea6f7fa66f72b
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Feb 5 22:04:34 2020 +0800

    telnet driver should return -EAGAIN if O_NONBLOCK is active
    
    also should report -EPIPE first
    
    Change-Id: I7ad2df15377c7bec8e22d0f5d1b54f7ce33eb0db
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/net/telnet.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/drivers/net/telnet.c b/drivers/net/telnet.c
index 881abba..c8e7ad2 100644
--- a/drivers/net/telnet.c
+++ b/drivers/net/telnet.c
@@ -692,14 +692,6 @@ static int telnet_open(FAR struct file *filep)
 
   ninfo("td_crefs: %d\n", priv->td_crefs);
 
-  /* O_NONBLOCK is not supported */
-
-  if (filep->f_oflags & O_NONBLOCK)
-    {
-      ret = -ENOSYS;
-      goto errout;
-    }
-
   /* Get exclusive access to the device structures */
 
   ret = nxsem_wait(&priv->td_exclsem);
@@ -871,7 +863,7 @@ static ssize_t telnet_read(FAR struct file *filep, FAR char *buffer,
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct telnet_dev_s *priv = inode->i_private;
-  ssize_t ret;
+  ssize_t ret = 0;
 
   ninfo("len: %d\n", len);
 
@@ -888,21 +880,22 @@ static ssize_t telnet_read(FAR struct file *filep, FAR char *buffer,
 
       if (priv->td_pending == 0)
         {
+          /* poll fds.revents contains last poll status in case of error */
+
+          if ((priv->fds.revents & (POLLHUP | POLLERR)) != 0)
+            {
+              return -EPIPE;
+            }
+
           if (filep->f_oflags & O_NONBLOCK)
             {
-              return 0;
+              return -EAGAIN;
             }
 
           /* Wait for new data (or error) */
 
           nxsem_wait_uninterruptible(&priv->td_iosem);
-
-          /* poll fds.revents contains last poll status in case of error */
-
-          if ((priv->fds.revents & (POLLHUP | POLLERR)) != 0)
-            {
-              return -EPIPE;
-            }
+          continue;
         }
 
       /* Take exclusive access to data buffer */
@@ -1304,7 +1297,10 @@ static int telnet_poll(FAR struct file *filep, FAR struct pollfd *fds,
       /* Yes.. then signal the poll logic */
 
       fds->revents |= (POLLRDNORM & fds->events);
-      nxsem_post(fds->sem);
+      if (fds->revents)
+        {
+          nxsem_post(fds->sem);
+        }
     }
 
   /* Then let psock_poll() do the heavy lifting */