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

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

commit 0111fe58a8f7708f43799ece997fe435f3e10f26
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 12 07:54:49 2026 +0100

    net/local: Let a signal end a blocked send() of a stream socket.
    
    local_fifo_write() wrote to the FIFO again after -EINTR and after a
    short write.  So a signal did not end send(), sendmsg() or write() of a
    local stream socket that waits for space in a full FIFO: the call waited
    until the reader made space.  In a kernel or protected build the signal
    handler did not run until then, and a default action that ends the
    process did not end it.
    
    POSIX: send() fails with EINTR when a signal comes before any data is
    sent.  When the signal comes after some data, send() returns the number
    of bytes sent.
    
    local_send_packet() now calls file_write() once for each segment and
    stops at an error or at a short write.  The pipe driver gives a short
    write when a signal comes while it waits after some bytes, and -EINTR
    when the signal comes before the first byte.  local_fifo_write() is
    removed.
    
    A datagram does not use local_send_packet(): local_send_frame() writes
    it with one atomic writev, and a signal ends its wait before the first
    byte.  The same code runs in flat, protected and kernel builds.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 net/local/local.h            |  6 ++--
 net/local/local_sendpacket.c | 77 ++++++++------------------------------------
 2 files changed, 17 insertions(+), 66 deletions(-)

diff --git a/net/local/local.h b/net/local/local.h
index 4d9acdb040d..60f9a5bcd4d 100644
--- a/net/local/local.h
+++ b/net/local/local.h
@@ -555,8 +555,10 @@ ssize_t local_send_frame(FAR struct local_conn_s *conn,
  *   len      Length of data to send
  *
  * Returned Value:
- *   Zero is returned on success; a negated errno value is returned on any
- *   failure.
+ *   The number of bytes sent is returned on success.  It is less than the
+ *   length of the data when the FIFO is full and does not wait, or when a
+ *   signal came while the send waited.  A negated errno value is returned
+ *   on any failure (-EINTR: a signal came before the first byte).
  *
  ****************************************************************************/
 
diff --git a/net/local/local_sendpacket.c b/net/local/local_sendpacket.c
index 6a6e3c54c38..300a284a18a 100644
--- a/net/local/local_sendpacket.c
+++ b/net/local/local_sendpacket.c
@@ -50,60 +50,6 @@
 
 #define LOCAL_FRAME_NIOV 8
 
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: local_fifo_write
- *
- * Description:
- *   Write a data on the write-only FIFO.
- *
- * Input Parameters:
- *   filep    File structure of write-only FIFO.
- *   buf      Data to send
- *   len      Length of data to send
- *
- * Returned Value:
- *   On success, the number of bytes written are returned (zero indicates
- *   nothing was written).  On any failure, a negated errno value is returned
- *
- ****************************************************************************/
-
-static ssize_t local_fifo_write(FAR struct file *filep,
-                                FAR const uint8_t *buf,
-                                size_t len)
-{
-  ssize_t nwritten = 0;
-  ssize_t ret = 0;
-
-  while (len != nwritten)
-    {
-      ret = file_write(filep, buf + nwritten, len - nwritten);
-      if (ret < 0)
-        {
-          if (ret == -EINTR)
-            {
-              continue;
-            }
-          else if (ret == -EAGAIN)
-            {
-              break;
-            }
-          else
-            {
-              nerr("ERROR: file_write failed: %zd\n", ret);
-              break;
-            }
-        }
-
-      nwritten += ret;
-    }
-
-  return nwritten > 0 ? nwritten : ret;
-}
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -248,8 +194,10 @@ ssize_t local_send_frame(FAR struct local_conn_s *conn,
  *   len      Length of data to send
  *
  * Returned Value:
- *   Packet length is returned on success; a negated errno value is returned
- *   on any failure.
+ *   The number of bytes sent is returned on success.  It is less than the
+ *   length of the data when the FIFO is full and does not wait, or when a
+ *   signal came while the send waited.  A negated errno value is returned
+ *   on any failure (-EINTR: a signal came before the first byte).
  *
  ****************************************************************************/
 
@@ -269,10 +217,10 @@ ssize_t local_send_packet(FAR struct file *filep,
 
   for (iov = buf; iov != end; iov++)
     {
-      ret = local_fifo_write(filep, iov->iov_base, iov->iov_len);
+      ret = file_write(filep, iov->iov_base, iov->iov_len);
       if (ret < 0)
         {
-          if (ret != -EAGAIN)
+          if (ret != -EAGAIN && ret != -EINTR)
             {
               nerr("ERROR: local send packet failed ret: %zd\n", ret);
             }
@@ -280,13 +228,14 @@ ssize_t local_send_packet(FAR struct file *filep,
           break;
         }
 
-      if (ret > 0)
+      /* A short write: the FIFO is full and does not wait, or a signal came
+       * while the write waited.
+       */
+
+      sendlen += ret;
+      if (ret != iov->iov_len)
         {
-          sendlen += ret;
-          if (ret != iov->iov_len)
-            {
-              break;
-            }
+          break;
         }
     }
 

Reply via email to