From a697835d0fc31297014e997b250aa8a28a013ad7 Mon Sep 17 00:00:00 2001 From: Hang Zhou Date: Thu, 12 Sep 2024 18:15:24 +0800 Subject: [PATCH] resolve segment fault and Error on modbus connection --- examples/linux/platform.h | 3 ++- examples/linux/server-tcp.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/linux/platform.h b/examples/linux/platform.h index 20f037b..f315bfe 100644 --- a/examples/linux/platform.h +++ b/examples/linux/platform.h @@ -167,6 +167,7 @@ void disconnect(void* conn) { // Read/write/sleep platform functions int32_t read_fd_linux(uint8_t* buf, uint16_t count, int32_t timeout_ms, void* arg) { + if(!arg) return -1; int fd = *(int*) arg; uint16_t total = 0; @@ -192,7 +193,7 @@ int32_t read_fd_linux(uint8_t* buf, uint16_t count, int32_t timeout_ms, void* ar ssize_t r = read(fd, buf + total, 1); if (r == 0) { disconnect(arg); - return -1; + return 0; } if (r < 0) diff --git a/examples/linux/server-tcp.c b/examples/linux/server-tcp.c index 89862d2..849a770 100644 --- a/examples/linux/server-tcp.c +++ b/examples/linux/server-tcp.c @@ -218,6 +218,8 @@ int main(int argc, char* argv[]) { if (conn) { // Set the next connection handler used by the read/write platform functions nmbs_set_platform_arg(&nmbs, conn); + }else{ + continue; } err = nmbs_server_poll(&nmbs);