From f8e800765c6a50f2fc90657ceebada3174cddff6 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Wed, 31 Mar 2021 18:21:02 +0800 Subject: [PATCH] net/local: correct the sendto() return length return length should be data length Signed-off-by: chao.an --- 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 745d4c7b95..7b71941b04 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 */