From ea31817f64e86478e2927f59ce21662873920e08 Mon Sep 17 00:00:00 2001 From: zhaohe <1013909206@qq.com> Date: Wed, 19 Jan 2022 10:19:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=BC=E8=87=B4cpu?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=8E=87=E9=AB=98=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- net_uart.cpp | 4 ++++ uart.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/net_uart.cpp b/net_uart.cpp index 05ebbeb..1297482 100644 --- a/net_uart.cpp +++ b/net_uart.cpp @@ -70,6 +70,10 @@ void *netclient_thread(void *arg) { char buff[4096]; int n = 0; while ((n = read(client->fd, buff, 4096)) >= 0) { + if (n == 0) { + //返回零意味着对方关闭socket,超时返回的是负数 + break; + } printf("net->uart: %d\n", n); printf_buf(buff, n); uartSend(&g_uart_device, buff, n); diff --git a/uart.cpp b/uart.cpp index 5df30b4..90b16e3 100644 --- a/uart.cpp +++ b/uart.cpp @@ -84,7 +84,7 @@ int uartStart(struct UartDevice* dev, unsigned char canonic) { /* set input mode (non-canonical, no echo,...) */ tty->c_lflag = 0; /* Do not wait for data */ - tty->c_cc[VTIME] = 0; /* inter-character timer unused */ + tty->c_cc[VTIME] = 10; /* inter-character timer unused */ tty->c_cc[VMIN] = 0; /* blocking read until 5 chars received */ }