Skip to content

Commit

Permalink
resolve segment fault and Error on modbus connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Hang Zhou committed Sep 12, 2024
1 parent 67bd7b2 commit a697835
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/linux/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions examples/linux/server-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a697835

Please sign in to comment.