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 3edb9a333231874f9155c90a404b598d4b9cce1f
Author: chao an <[email protected]>
AuthorDate: Tue Oct 27 14:08:07 2026 +0800

    drivers/net: Batch-copy telnet transmit data
    
    Fast-copy output spans that do not need CR/LF translation into the
    transmit buffer. This preserves Telnet newline expansion while reducing
    per-byte work for ordinary console output.
    
    Signed-off-by: chao an <[email protected]>
---
 drivers/net/telnet.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 2 deletions(-)

diff --git a/drivers/net/telnet.c b/drivers/net/telnet.c
index 96750271741..d227117f69d 100644
--- a/drivers/net/telnet.c
+++ b/drivers/net/telnet.c
@@ -883,7 +883,10 @@ static ssize_t telnet_write(FAR struct file *filep, FAR 
const char *buffer,
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct telnet_dev_s *priv = inode->i_private;
+  FAR const char *special;
   FAR const char *src = buffer;
+  size_t ncopy;
+  size_t nleft;
   ssize_t ret = 0;
   ssize_t nsent;
   int ncopied;
@@ -892,13 +895,66 @@ static ssize_t telnet_write(FAR struct file *filep, FAR 
const char *buffer,
 
   ninfo("len: %zd\n", len);
 
-  /* Process each character from the user buffer */
+  /* Process data from the user buffer */
 
-  for (nsent = 0, ncopied = 0; nsent < len; nsent++)
+  for (nsent = 0, ncopied = 0; nsent < len; )
     {
+      ncopy = CONFIG_TELNET_TXBUFFER_SIZE - 2 - ncopied;
+      if (ncopy > 0)
+        {
+          nleft = len - nsent;
+          if (ncopy > nleft)
+            {
+              ncopy = nleft;
+            }
+
+          special = memchr(src, TELNET_CR, ncopy);
+          if (special != NULL)
+            {
+              ncopy = special - src;
+            }
+
+          special = memchr(src, TELNET_NL, ncopy);
+          if (special != NULL)
+            {
+              ncopy = special - src;
+            }
+
+          if (ncopy > 0)
+            {
+              if (priv->td_txcr)
+                {
+                  priv->td_txbuffer[ncopied++] = TELNET_NUL;
+                  priv->td_txcr = false;
+                }
+
+              memcpy(&priv->td_txbuffer[ncopied], src, ncopy);
+              ncopied += ncopy;
+              src += ncopy;
+              nsent += ncopy;
+
+              if (ncopied > CONFIG_TELNET_TXBUFFER_SIZE - 2)
+                {
+                  ret = psock_send(&priv->td_psock, priv->td_txbuffer,
+                                   ncopied, 0);
+                  if (ret < 0)
+                    {
+                      nerr("ERROR: psock_send failed '%s': %zd\n",
+                           priv->td_txbuffer, ret);
+                      goto out;
+                    }
+
+                  ncopied = 0;
+                }
+
+              continue;
+            }
+        }
+
       /* Get the next character from the user buffer */
 
       ch = *src++;
+      nsent++;
 
       /* Add the character to the TX buffer */
 

Reply via email to