yangsong8-a1 commented on code in PR #21113:
URL: https://github.com/apache/nuttx/pull/21113#discussion_r4477743382
##########
drivers/serial/serial.c:
##########
@@ -1684,105 +1730,133 @@ static ssize_t uart_writev(FAR struct file *filep,
FAR struct uio *uio)
nseg = 0;
}
- /* With no output processing, copy whole runs into the TX buffer at
- * once. The bulk copy caches the head index, so it is only used
- * when this thread is provably the sole producer: ECHO makes
- * uart_readv() echo into the same buffer, and on a console
- * uart_irqwrite() produces into it from interrupt context. A full
- * TX buffer falls through to uart_putxmitchar() below, which keeps
- * the canonical blocking, disconnect and O_NONBLOCK handling.
+ /* Number of contiguous bytes remaining in the current segment. */
+
+ nsent = seglen - nseg;
+
+ /* Locate the next character in this segment that requires output
+ * post-processing.
*/
-#ifdef CONFIG_SERIAL_TXBULK
- if ((dev->tc_oflag & OPOST) == 0 && (dev->tc_lflag & ECHO) == 0 &&
- !dev->isconsole)
+ if (opost && (dev->tc_oflag & OCRNL) != 0)
+ {
+ special = memchr(&segbuf[nseg], '\r', nsent);
+ }
+
+ if (opost && (dev->tc_oflag & (ONLCR | ONLRET)) != 0)
{
- ncopy = uart_putxmitbuf(dev, segbuf + nseg, seglen - nseg);
- if (ncopy > 0)
+ FAR const char *nl = memchr(&segbuf[nseg], '\n', nsent);
+
+ if (nl != NULL && (special == NULL || nl < special))
{
- nseg += ncopy;
- buflen -= ncopy;
- continue;
+ special = nl;
}
}
-#endif
- ch = segbuf[nseg];
- ret = OK;
+ if (special != NULL)
+ {
+ nsent = special - &segbuf[nseg];
+ }
- /* Do output post-processing */
+ /* Bulk-copy the run of ordinary bytes that precede the special
+ * character (or the rest of the segment when there is none).
+ */
- if ((dev->tc_oflag & OPOST) != 0)
+ if (nsent > 0)
{
- /* Mapping CR to NL? */
-
- if ((ch == '\r') && (dev->tc_oflag & OCRNL) != 0)
+ ret = uart_putxmitbuf(dev, &segbuf[nseg], nsent, oktoblock);
+ if (ret < 0)
{
- ch = '\n';
+ break;
}
- /* Are we interested in newline processing? */
-
- if ((ch == '\n') && (dev->tc_oflag & (ONLCR | ONLRET)) != 0)
+ nseg += ret;
+ buflen -= ret;
+ if (ret < nsent)
{
- ret = uart_putxmitchar(dev, '\r', oktoblock);
+ continue;
Review Comment:
done, ths
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]