resolve segment fault and Error on modbus connection

This commit is contained in:
Hang Zhou 2024-09-12 18:15:24 +08:00 committed by Valerio De Benedetto
parent 0dffd91e3d
commit 2def1aa693
2 changed files with 4 additions and 1 deletions

View File

@ -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)

View File

@ -220,6 +220,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);