resolve segment fault and Error on modbus connection
This commit is contained in:
parent
0dffd91e3d
commit
2def1aa693
@ -167,6 +167,7 @@ void disconnect(void* conn) {
|
|||||||
// Read/write/sleep platform functions
|
// Read/write/sleep platform functions
|
||||||
|
|
||||||
int32_t read_fd_linux(uint8_t* buf, uint16_t count, int32_t timeout_ms, void* arg) {
|
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;
|
int fd = *(int*) arg;
|
||||||
|
|
||||||
uint16_t total = 0;
|
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);
|
ssize_t r = read(fd, buf + total, 1);
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
disconnect(arg);
|
disconnect(arg);
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|||||||
@ -220,6 +220,8 @@ int main(int argc, char* argv[]) {
|
|||||||
if (conn) {
|
if (conn) {
|
||||||
// Set the next connection handler used by the read/write platform functions
|
// Set the next connection handler used by the read/write platform functions
|
||||||
nmbs_set_platform_arg(&nmbs, conn);
|
nmbs_set_platform_arg(&nmbs, conn);
|
||||||
|
}else{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = nmbs_server_poll(&nmbs);
|
err = nmbs_server_poll(&nmbs);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user