You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/04/19 16:52:42 UTC

[incubator-nuttx] branch master updated: net/local: correct the sendto() return length

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f8e8007  net/local: correct the sendto() return length
f8e8007 is described below

commit f8e800765c6a50f2fc90657ceebada3174cddff6
Author: chao.an <an...@xiaomi.com>
AuthorDate: Wed Mar 31 18:21:02 2021 +0800

    net/local: correct the sendto() return length
    
    return length should be data length
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/local/local_sendmsg.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/net/local/local_sendmsg.c b/net/local/local_sendmsg.c
index 745d4c7..7b71941 100644
--- a/net/local/local_sendmsg.c
+++ b/net/local/local_sendmsg.c
@@ -156,8 +156,7 @@ static ssize_t local_sendto(FAR struct socket *psock,
 #ifdef CONFIG_NET_LOCAL_DGRAM
   FAR struct local_conn_s *conn = (FAR struct local_conn_s *)psock->s_conn;
   FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)to;
-  ssize_t nsent;
-  int ret;
+  ssize_t ret;
 
   /* Verify that a valid address has been provided */
 
@@ -212,7 +211,7 @@ static ssize_t local_sendto(FAR struct socket *psock,
   ret = local_create_halfduplex(conn, unaddr->sun_path);
   if (ret < 0)
     {
-      nerr("ERROR: Failed to create FIFO for %s: %d\n",
+      nerr("ERROR: Failed to create FIFO for %s: %zd\n",
            conn->lc_path, ret);
       return ret;
     }
@@ -224,25 +223,18 @@ static ssize_t local_sendto(FAR struct socket *psock,
                           (flags & MSG_DONTWAIT) != 0);
   if (ret < 0)
     {
-      nerr("ERROR: Failed to open FIFO for %s: %d\n",
+      nerr("ERROR: Failed to open FIFO for %s: %zd\n",
            unaddr->sun_path, ret);
 
-      nsent = ret;
       goto errout_with_halfduplex;
     }
 
   /* Send the packet */
 
-  nsent = local_send_packet(&conn->lc_outfile, buf, len);
-  if (nsent < 0)
+  ret = local_send_packet(&conn->lc_outfile, buf, len);
+  if (ret < 0)
     {
-      nerr("ERROR: Failed to send the packet: %d\n", ret);
-    }
-  else
-    {
-      /* local_send_packet returns 0 if all 'len' bytes were sent */
-
-      nsent = len;
+      nerr("ERROR: Failed to send the packet: %zd\n", ret);
     }
 
   /* Now we can close the write-only socket descriptor */
@@ -255,7 +247,8 @@ errout_with_halfduplex:
   /* Release our reference to the half duplex FIFO */
 
   local_release_halfduplex(conn);
-  return nsent;
+
+  return ret;
 #else
   return -EISCONN;
 #endif /* CONFIG_NET_LOCAL_DGRAM */