You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1323 lines
34 KiB

​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
4 months ago
​
​
4 months ago
​
​
4 months ago
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
  1. #include "deviceNodeEthernet2Serial.h"
  2. #include "../../data/protocol/protocol.h"
  3. #include "hardwareManager.h"
  4. #include <atomic>
  5. #include <netinet/tcp.h>
  6. #include <poll.h>
  7. #include <time.h>
  8. // #define DEBUG_EXTRA
  9. // #define DEBUG_SERIAL_COMMUNICATION
  10. #define LOG(X) deviceNode::m_pLog->Log("E2UART", this, X)
  11. #ifdef DEBUG
  12. #define LOG_ERROR(X) \
  13. { \
  14. char _tBfrErrMSG2w34[1024]; \
  15. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  16. deviceNode::m_pLog->Log("E2UART", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  17. }
  18. #else
  19. #define LOG_ERROR(X) deviceNode::m_pLog->Log("E2UART", this, _LOG_ERROR, X);
  20. #endif
  21. deviceETH2UART::deviceETH2UART(uint32_t nodeID) :
  22. deviceNode(nodeID),
  23. hardwareResource(),
  24. basicTransport(),
  25. #ifdef SERIAL_PING_PONG
  26. basicThread()
  27. #else
  28. basicDualThread()
  29. #endif
  30. {
  31. // m_pLog = basicLogCollection::getInstance();
  32. memset(&m_sUartData, 0, sizeof(m_sUartData));
  33. #ifdef SERIAL_PING_PONG
  34. #else
  35. m_nInputBufferSize = 0;
  36. m_nOutputBufferSize = 0;
  37. #endif
  38. m_iDeviceFD = -1;
  39. m_iMasterFD = -1;
  40. m_iInFID = -1;
  41. m_iOutFID = -1;
  42. m_bRegistered = false;
  43. m_bLastPingOk = true;
  44. m_nNextPingMs = 0;
  45. m_nNextConnectMs = 0;
  46. m_nConnectBackoffMs = 0;
  47. hardwareResource::create(m_sNodeData.aux_parameter, HARDWARE_PROVIDER_SERIAL);
  48. }
  49. // Status of the I/O thread (sender thread in the dual-thread variant)
  50. #ifdef SERIAL_PING_PONG
  51. #define E2U_IO_STATUS m_bThreadStatus
  52. #else
  53. #define E2U_IO_STATUS m_bThreadAStatus
  54. #endif
  55. static uint64_t e2uNowMs(void)
  56. {
  57. struct timespec ts;
  58. clock_gettime(CLOCK_MONOTONIC, &ts);
  59. return (uint64_t) ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
  60. }
  61. deviceETH2UART::~deviceETH2UART()
  62. {
  63. // Leave the hardware manager first: its validate() loop holds the resource list locked while it
  64. // calls validate() / create() on us, so once this returns it no longer uses this object
  65. hardwareManager * tH = hardwareManager::getInstance();
  66. if (tH)
  67. {
  68. tH->resignResource(this);
  69. }
  70. std::lock_guard<std::recursive_mutex> tLock(m_mConnLock);
  71. closePort();
  72. }
  73. bool deviceETH2UART::create(void)
  74. {
  75. std::lock_guard<std::recursive_mutex> tLock(m_mConnLock);
  76. DBC_UART_DATA * tDATA = NULL;
  77. if (m_sResourceSettings.id == 0)
  78. {
  79. return false;
  80. }
  81. if (m_sResourceSettings.aux_id == 0)
  82. {
  83. return false;
  84. }
  85. tDATA = deviceNode::m_pDBC->getUartData(m_sResourceSettings.aux_id);
  86. if (tDATA != NULL)
  87. {
  88. memcpy(&m_sUartData, tDATA, sizeof(DBC_UART_DATA));
  89. #ifdef DEBUG
  90. LOG(m_sUartData.path);
  91. #endif
  92. free(tDATA);
  93. // Also called by the hardware manager to re-create the resource: obeys the back-off
  94. m_bValid = connectSOL();
  95. };
  96. if (m_bValid && ! m_bRegistered)
  97. {
  98. // Once only: the hardware manager calls create() again with its resource list locked -
  99. // assigning from there locked the (non recursive) list mutex twice and added us twice
  100. hardwareManager * tH = hardwareManager::getInstance();
  101. if (tH)
  102. {
  103. tH->assignResource(this);
  104. m_bRegistered = true;
  105. }
  106. };
  107. return m_bValid;
  108. }
  109. /*
  110. Is the link to the gateway still up?
  111. - TCP (SOL_TCP_SERVER: we are the client): the TCP connection itself (socket, I/O thread and
  112. keepalive). ICMP is not used: gateways reached over the Internet (mobile networks, firewalls)
  113. often do not answer ping although the TCP port works - the working connection was closed every
  114. second ("No Ping to device!").
  115. - UDP: no connection state, ICMP echo (at most every E2UART_PING_INTERVAL_MS).
  116. */
  117. bool deviceETH2UART::linkAlive(void)
  118. {
  119. if (m_sUartData.mode == SOL_TCP_SERVER)
  120. {
  121. if (m_iDeviceFD < 0 || m_eConnectionStatus != CS_CONNECTED || E2U_IO_STATUS == TH_PRE_INIT || E2U_IO_STATUS >= TH_ENDED)
  122. {
  123. LOG_ERROR("TCP connection to the gateway lost");
  124. return false;
  125. };
  126. int tErr = 0;
  127. socklen_t tLen = sizeof(tErr);
  128. if (getsockopt(m_iDeviceFD, SOL_SOCKET, SO_ERROR, &tErr, &tLen) == 0 && tErr != 0)
  129. {
  130. char tB[160];
  131. snprintf(tB, sizeof(tB), "TCP connection to the gateway failed: %s", strerror(tErr));
  132. LOG_ERROR(tB);
  133. return false;
  134. };
  135. return true;
  136. };
  137. uint64_t tNow = e2uNowMs();
  138. if (tNow < m_nNextPingMs)
  139. {
  140. return m_bLastPingOk;
  141. };
  142. m_bLastPingOk = pingDevice();
  143. m_nNextPingMs = e2uNowMs() + E2UART_PING_INTERVAL_MS;
  144. return m_bLastPingOk;
  145. }
  146. bool deviceETH2UART::connectSOL(void)
  147. {
  148. uint64_t tNow = e2uNowMs();
  149. if (tNow < m_nNextConnectMs)
  150. {
  151. return false; // waiting for the next attempt (a gateway that is down is not hammered)
  152. };
  153. if (create_SOL())
  154. {
  155. m_nConnectBackoffMs = 0;
  156. m_nNextConnectMs = 0;
  157. m_nNextPingMs = 0;
  158. m_bLastPingOk = true;
  159. return true;
  160. };
  161. m_nConnectBackoffMs = (m_nConnectBackoffMs == 0) ? E2UART_RECONNECT_MIN_MS : m_nConnectBackoffMs * 2;
  162. if (m_nConnectBackoffMs > E2UART_RECONNECT_MAX_MS)
  163. {
  164. m_nConnectBackoffMs = E2UART_RECONNECT_MAX_MS;
  165. };
  166. m_nNextConnectMs = e2uNowMs() + m_nConnectBackoffMs;
  167. return false;
  168. }
  169. bool deviceETH2UART::validate(void)
  170. {
  171. std::lock_guard<std::recursive_mutex> tLock(m_mConnLock);
  172. if (m_bValid)
  173. {
  174. m_bValid = linkAlive();
  175. if (! m_bValid)
  176. {
  177. LOG_ERROR("No connection to the device!");
  178. closePort();
  179. };
  180. };
  181. #ifdef DEBUG_EXTRA
  182. LOG("Check Settings For Changes");
  183. #endif
  184. DBC_UART_DATA * tDATA = deviceNode::m_pDBC->getUartData(m_sResourceSettings.aux_id);
  185. if (tDATA != NULL)
  186. {
  187. bool bFlag = true;
  188. if (strcmp(tDATA->path, m_sUartData.path) != 0)
  189. {
  190. bFlag = false;
  191. }
  192. // if( bFlag && ( m_sUartData.speed != tDATA->speed ) ) bFlag = false; //Speed for SOL port Erelevant
  193. if (bFlag && (m_sUartData.mode != tDATA->mode))
  194. {
  195. bFlag = false;
  196. }
  197. if (bFlag && (m_sUartData.port != tDATA->port))
  198. {
  199. bFlag = false;
  200. }
  201. if (! bFlag)
  202. {
  203. #ifdef DEBUG
  204. LOG("Settings Has been Changed!");
  205. #endif
  206. closePort(); // create_SOL() closes too; also stops the I/O thread of the old settings
  207. // Apply new settings
  208. memcpy(&m_sUartData, tDATA, sizeof(DBC_UART_DATA));
  209. #ifdef DEBUG
  210. LOG("Reconect with new settings");
  211. #endif
  212. m_nNextConnectMs = 0; // new address: no back-off
  213. m_bValid = connectSOL();
  214. };
  215. free(tDATA);
  216. }
  217. else
  218. {
  219. LOG_ERROR("Error Fetch DB Data!");
  220. };
  221. // Finally in any case If Not Connected -> try to Connect (after the back-off)
  222. if (! m_bValid && e2uNowMs() >= m_nNextConnectMs)
  223. {
  224. #ifdef DEBUG
  225. LOG("Try to Conncet");
  226. #endif
  227. m_bValid = connectSOL();
  228. };
  229. if (m_bValid)
  230. {
  231. m_bValid = deviceNode::validate();
  232. }
  233. return m_bValid;
  234. }
  235. #include <netinet/ip_icmp.h>
  236. // Define the Packet Constants
  237. // ping packet size
  238. #define PING_PKT_S 64
  239. // Automatic port number
  240. #define PORT_NO 0
  241. // Automatic port number
  242. #define PING_SLEEP_RATE 1000000
  243. // Gives the timeout delay for receiving packets
  244. // in seconds
  245. #define RECV_TIMEOUT 1
  246. // ping packet structure
  247. struct ping_pkt
  248. {
  249. struct icmphdr hdr;
  250. char msg[PING_PKT_S - sizeof(struct icmphdr)];
  251. };
  252. /*
  253. ICMP echo to the gateway: up to E2UART_PING_ATTEMPTS requests, each waiting E2UART_PING_TIMEOUT_MS.
  254. Before: one request and one recvfrom() (3 s - the 300 ms set first was overwritten). A single lost
  255. packet failed the check, a signal (EINTR) ended the wait at once, and ANY ICMP packet received by
  256. the raw socket (e.g. the reply to another gateway's ping) counted as the answer.
  257. Now only an echo reply from the gateway with our id and sequence number counts.
  258. */
  259. bool deviceETH2UART::pingDevice()
  260. {
  261. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
  262. if (sockfd < 0)
  263. {
  264. char tB[160];
  265. snprintf(tB, sizeof(tB), "ICMP socket failed: %s (needs root / CAP_NET_RAW)", strerror(errno));
  266. LOG_ERROR(tB);
  267. return false;
  268. };
  269. int ttl_val = 64;
  270. if (setsockopt(sockfd, SOL_IP, IP_TTL, &ttl_val, sizeof(ttl_val)) != 0)
  271. {
  272. LOG_ERROR("Setting socket options to TTL failed!");
  273. close(sockfd);
  274. return false;
  275. };
  276. static std::atomic<uint16_t> s_nSequence(0);
  277. uint16_t tId = (uint16_t) (getpid() & 0xFFFF);
  278. char tReason[96] = "no reply";
  279. bool RetVal = false;
  280. for (int tAttempt = 0; tAttempt < E2UART_PING_ATTEMPTS && ! RetVal; tAttempt++)
  281. {
  282. RetVal = pingOnce(sockfd, tId, ++s_nSequence, tReason, sizeof(tReason));
  283. };
  284. close(sockfd);
  285. if (! RetVal)
  286. {
  287. char tB[256];
  288. snprintf(tB, sizeof(tB), "No ICMP reply from %.64s: %s (%d x %d ms)", m_sUartData.path, tReason, E2UART_PING_ATTEMPTS, E2UART_PING_TIMEOUT_MS);
  289. LOG_ERROR(tB);
  290. };
  291. return RetVal;
  292. }
  293. bool deviceETH2UART::pingOnce(int sockfd, uint16_t id, uint16_t seq, char * reason, size_t reasonSize)
  294. {
  295. struct ping_pkt pckt;
  296. struct sockaddr_in ping_addr;
  297. memset(&ping_addr, 0, sizeof(ping_addr));
  298. ping_addr.sin_family = AF_INET;
  299. ping_addr.sin_addr.s_addr = inet_addr(m_sUartData.path);
  300. memset(&pckt, 0, sizeof(pckt));
  301. pckt.hdr.type = ICMP_ECHO;
  302. pckt.hdr.un.echo.id = htons(id);
  303. pckt.hdr.un.echo.sequence = htons(seq);
  304. size_t i;
  305. for (i = 0; i < sizeof(pckt.msg) - 1; i++)
  306. {
  307. pckt.msg[i] = (char) i + '0';
  308. }
  309. pckt.msg[i] = 0;
  310. pckt.hdr.checksum = checksumPing(&pckt, sizeof(pckt));
  311. if (sendto(sockfd, &pckt, sizeof(pckt), 0, (struct sockaddr *) &ping_addr, sizeof(ping_addr)) <= 0)
  312. {
  313. snprintf(reason, reasonSize, "send failed: %s", strerror(errno));
  314. return false;
  315. };
  316. uint64_t tDeadline = e2uNowMs() + E2UART_PING_TIMEOUT_MS;
  317. for (;;)
  318. {
  319. uint64_t tNow = e2uNowMs();
  320. if (tNow >= tDeadline)
  321. {
  322. snprintf(reason, reasonSize, "timeout");
  323. return false;
  324. };
  325. struct pollfd tPfd;
  326. tPfd.fd = sockfd;
  327. tPfd.events = POLLIN;
  328. int tRc = poll(&tPfd, 1, (int) (tDeadline - tNow));
  329. if (tRc < 0)
  330. {
  331. if (errno == EINTR)
  332. {
  333. continue; // a signal is not a missing reply
  334. };
  335. snprintf(reason, reasonSize, "poll failed: %s", strerror(errno));
  336. return false;
  337. };
  338. if (tRc == 0)
  339. {
  340. continue; // deadline check above
  341. };
  342. uint8_t tBuf[1024];
  343. struct sockaddr_in r_addr;
  344. socklen_t addr_len = sizeof(r_addr);
  345. ssize_t tLen = recvfrom(sockfd, tBuf, sizeof(tBuf), MSG_DONTWAIT, (struct sockaddr *) &r_addr, &addr_len);
  346. if (tLen <= 0)
  347. {
  348. continue;
  349. };
  350. // A raw socket returns the IP header too and gets every ICMP packet of the host
  351. size_t tIpLen = (size_t) (tBuf[0] & 0x0F) * 4;
  352. if ((size_t) tLen < tIpLen + sizeof(struct icmphdr))
  353. {
  354. continue;
  355. };
  356. struct icmphdr * tIcmp = (struct icmphdr *) (tBuf + tIpLen);
  357. if (r_addr.sin_addr.s_addr == ping_addr.sin_addr.s_addr && tIcmp->type == ICMP_ECHOREPLY && ntohs(tIcmp->un.echo.id) == id && ntohs(tIcmp->un.echo.sequence) == seq)
  358. {
  359. #ifdef DEBUG_EXTRA
  360. LOG("Device Is OK!");
  361. #endif
  362. return true;
  363. };
  364. };
  365. }
  366. bool deviceETH2UART::create_SOL()
  367. {
  368. /*
  369. if( m_sUartData.mode == SOL_NOT_DEFINED ) {
  370. LOG_ERROR("No Connection Type Defined!");
  371. return false;
  372. };
  373. */
  374. if (m_sUartData.port == 0)
  375. {
  376. LOG_ERROR("No Port Defined!");
  377. return false;
  378. };
  379. if (m_sUartData.speed == 0)
  380. {
  381. LOG_ERROR("No Speed Defined!");
  382. return false;
  383. };
  384. if (m_sUartData.path[0] == (char) 0)
  385. {
  386. LOG_ERROR("No Adress Defined!");
  387. return false;
  388. };
  389. // A previous connection / I/O thread is closed first. Before, the socket number was overwritten
  390. // (the connection leaked) and init() failed while the old thread ran: every reconnect left an open
  391. // TCP connection at the gateway and the node stayed invalid although "Connected".
  392. if (m_iDeviceFD != -1 || E2U_IO_STATUS != TH_PRE_INIT)
  393. {
  394. closePort();
  395. };
  396. switch (m_sUartData.mode)
  397. {
  398. case SOL_UDP_CLIENT:
  399. {
  400. #ifdef DEBUG
  401. LOG("PORT IS CLIENT - Create UDP Server");
  402. #endif
  403. #ifdef __linux__
  404. // Creating socket file descriptor
  405. if ((m_iDeviceFD = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  406. {
  407. LOG_ERROR("UDP Socket Creation Failed!");
  408. return false;
  409. };
  410. fcntl(m_iDeviceFD, F_SETFL, O_NONBLOCK);
  411. // Filling server information
  412. struct sockaddr_in tServerAddr;
  413. memset(&tServerAddr, 0, sizeof(tServerAddr));
  414. tServerAddr.sin_family = AF_INET; // IPv4
  415. tServerAddr.sin_addr.s_addr = INADDR_ANY;
  416. tServerAddr.sin_port = htons(m_sUartData.port);
  417. // Bind the socket with the server address
  418. if (bind(m_iDeviceFD, (const struct sockaddr *) &tServerAddr, sizeof(tServerAddr)) < 0)
  419. {
  420. LOG_ERROR("UDP Bind Failed");
  421. return false;
  422. };
  423. #else
  424. WSADATA wsaData;
  425. // Initialize Winsock version 2.2
  426. char tBuff[128];
  427. if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
  428. {
  429. sprintf(tBuff, "WSAStartup failed with error %ld", WSAGetLastError());
  430. LOG_ERROR(tBuff);
  431. return false;
  432. }
  433. else
  434. {
  435. sprintf(tBuff, "The Winsock DLL status is %s.", wsaData.szSystemStatus);
  436. LOG(tBuff);
  437. };
  438. // Set up a SOCKADDR_IN structure that will tell bind that we
  439. // want to receive datagrams from all interfaces using port 5150.
  440. // The IPv4 family
  441. ReceiverAddr.sin_family = AF_INET;
  442. // Port no. 5150
  443. ReceiverAddr.sin_port = htons(m_nPort);
  444. // From all interface (0.0.0.0)
  445. ReceiverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  446. // Associate the address information with the socket using bind.
  447. // At this point you can receive datagrams on your bound socket.
  448. if (bind(m_sSocket, (SOCKADDR *) &ReceiverAddr, sizeof(ReceiverAddr)) == SOCKET_ERROR)
  449. {
  450. sprintf(tBuff, "Server: bind() failed!Error : %ld.", WSAGetLastError());
  451. // Close the socket
  452. closesocket(m_sSocket);
  453. // Do the clean up
  454. WSACleanup();
  455. // and exit with error
  456. LOG_ERROR(tBuff);
  457. return false;
  458. }
  459. else
  460. {
  461. LOG("UDP Server: bind() is OK!");
  462. };
  463. // Some info on the receiver side...
  464. SOCKADDR_IN tAddr;
  465. int tLen = sizeof(SOCKADDR_IN);
  466. getsockname(m_sSocket, (SOCKADDR *) &tAddr, &tLen);
  467. sprintf(tBuff, "Receiving IP(s) used : %s", inet_ntoa(tAddr.sin_addr));
  468. LOG(tBuff);
  469. sprintf(tBuff, "Receiving port used : %d", htons(tAddr.sin_port));
  470. LOG(tBuff);
  471. SelectTiming = recvfromTimeOutUDP(m_sSocket, 10, 0);
  472. #endif
  473. break;
  474. };
  475. case SOL_TCP_CLIENT:
  476. {
  477. #ifdef DEBUG
  478. LOG("PORT IS CLIENT - Create TCP Server");
  479. #endif
  480. break;
  481. };
  482. case SOL_UDP_SERVER:
  483. {
  484. #ifdef DEBUG
  485. LOG("PORT IS SERVER - Create UDP Client");
  486. #endif
  487. #ifdef __linux__
  488. // Creating socket file descriptor
  489. if ((m_iDeviceFD = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  490. {
  491. LOG_ERROR("Socket Creation Failed!");
  492. return false;
  493. };
  494. fcntl(m_iDeviceFD, F_SETFL, O_NONBLOCK);
  495. // Filling server information
  496. struct sockaddr_in tServerAddr;
  497. memset(&tServerAddr, 0, sizeof(tServerAddr));
  498. tServerAddr.sin_family = AF_INET;
  499. tServerAddr.sin_addr.s_addr = INADDR_ANY;
  500. tServerAddr.sin_port = htons(m_sUartData.port);
  501. #else
  502. #endif
  503. break;
  504. };
  505. case SOL_TCP_SERVER:
  506. {
  507. #ifdef DEBUG
  508. LOG("PORT IS SERVER - Create TCP Client");
  509. #endif
  510. // socket create and varification
  511. m_iDeviceFD = socket(AF_INET, SOCK_STREAM, 0);
  512. if (m_iDeviceFD == -1)
  513. {
  514. LOG_ERROR("Socket creation failed!");
  515. return false;
  516. }
  517. #ifdef DEBUG
  518. else
  519. {
  520. LOG("Socket successfully created");
  521. }
  522. #endif
  523. // Set non-blocking
  524. int arg;
  525. if ((arg = fcntl(m_iDeviceFD, F_GETFL, NULL)) < 0)
  526. {
  527. char tBuf[512];
  528. sprintf(tBuf, "Error fcntl(..., F_GETFL) (%s)", strerror(errno));
  529. LOG_ERROR(tBuf);
  530. return false;
  531. };
  532. arg |= O_NONBLOCK;
  533. if (fcntl(m_iDeviceFD, F_SETFL, arg) < 0)
  534. {
  535. char tBuf[512];
  536. sprintf(tBuf, "Error fcntl(..., F_SETFL) (%s)", strerror(errno));
  537. LOG_ERROR(tBuf);
  538. return false;
  539. };
  540. // Keepalive: a gateway that disappears (no FIN, e.g. mobile link lost) is detected
  541. {
  542. int tOn = 1, tIdle = E2UART_KEEPALIVE_IDLE_S, tIntvl = E2UART_KEEPALIVE_INTVL_S, tCnt = E2UART_KEEPALIVE_CNT;
  543. setsockopt(m_iDeviceFD, SOL_SOCKET, SO_KEEPALIVE, &tOn, sizeof(tOn));
  544. setsockopt(m_iDeviceFD, IPPROTO_TCP, TCP_KEEPIDLE, &tIdle, sizeof(tIdle));
  545. setsockopt(m_iDeviceFD, IPPROTO_TCP, TCP_KEEPINTVL, &tIntvl, sizeof(tIntvl));
  546. setsockopt(m_iDeviceFD, IPPROTO_TCP, TCP_KEEPCNT, &tCnt, sizeof(tCnt));
  547. }
  548. // assign IP, PORT
  549. struct sockaddr_in tServerAddr;
  550. memset(&tServerAddr, 0, sizeof(tServerAddr));
  551. tServerAddr.sin_family = AF_INET;
  552. tServerAddr.sin_addr.s_addr = inet_addr(m_sUartData.path);
  553. tServerAddr.sin_port = htons(m_sUartData.port);
  554. // connect the client socket to server socket
  555. int retVal = connect(m_iDeviceFD, (struct sockaddr *) &tServerAddr, sizeof(tServerAddr));
  556. if (retVal < 0)
  557. {
  558. if (errno == EINPROGRESS)
  559. {
  560. #ifdef DEBUG
  561. LOG("EINPROGRESS in connect() - selecting");
  562. #endif
  563. // Over the Internet a connect takes longer than on a LAN (the timeout was 1 s)
  564. uint64_t tDeadline = e2uNowMs() + E2UART_CONNECT_TIMEOUT_MS;
  565. do
  566. {
  567. uint64_t tNow = e2uNowMs();
  568. uint64_t tLeft = (tNow < tDeadline) ? tDeadline - tNow : 0;
  569. fd_set myset;
  570. struct timeval tv;
  571. tv.tv_sec = tLeft / 1000;
  572. tv.tv_usec = (tLeft % 1000) * 1000;
  573. FD_ZERO(&myset);
  574. FD_SET(m_iDeviceFD, &myset);
  575. retVal = select(m_iDeviceFD + 1, NULL, &myset, NULL, &tv);
  576. if (retVal < 0 && errno == EINTR && e2uNowMs() < tDeadline)
  577. {
  578. continue; // interrupted by a signal: wait the rest of the time
  579. }
  580. if (retVal < 0 && errno != EINTR)
  581. {
  582. char cBuffer[512];
  583. sprintf(cBuffer, "ERROR connect to [%s:%d] %d (%s)", m_sUartData.path, m_sUartData.port, errno, strerror(errno));
  584. LOG_ERROR(cBuffer);
  585. close(m_iDeviceFD);
  586. m_iDeviceFD = -1;
  587. return false;
  588. }
  589. else if (retVal > 0)
  590. {
  591. int valopt;
  592. // Socket selected for write
  593. socklen_t lon = sizeof(int);
  594. if (getsockopt(m_iDeviceFD, SOL_SOCKET, SO_ERROR, (void *) (&valopt), &lon) < 0)
  595. {
  596. char cBuffer[512];
  597. sprintf(cBuffer, "ERROR connect to [%s:%d] %d (%s) in getsockopt", m_sUartData.path, m_sUartData.port, errno, strerror(errno));
  598. LOG_ERROR(cBuffer);
  599. close(m_iDeviceFD);
  600. m_iDeviceFD = -1;
  601. return false;
  602. };
  603. // Check the value returned...
  604. if (valopt)
  605. {
  606. char cBuffer[512];
  607. sprintf(cBuffer, "ERROR in delayed connection() %d - %s\n", valopt, strerror(valopt));
  608. LOG_ERROR(cBuffer);
  609. close(m_iDeviceFD);
  610. m_iDeviceFD = -1;
  611. return false;
  612. };
  613. break;
  614. }
  615. else
  616. {
  617. char cBuffer[160];
  618. snprintf(cBuffer, sizeof(cBuffer), "Timeout (%d ms) connecting to [%.64s:%d] - Cancelling!", E2UART_CONNECT_TIMEOUT_MS, m_sUartData.path, m_sUartData.port);
  619. LOG_ERROR(cBuffer);
  620. close(m_iDeviceFD);
  621. m_iDeviceFD = -1;
  622. return false;
  623. };
  624. }
  625. while (1);
  626. }
  627. else
  628. {
  629. char cBuffer[512];
  630. sprintf(cBuffer, "ERROR connect to [%s:%d] %d (%s)", m_sUartData.path, m_sUartData.port, errno, strerror(errno));
  631. LOG_ERROR(cBuffer);
  632. close(m_iDeviceFD);
  633. m_iDeviceFD = -1;
  634. return false;
  635. };
  636. };
  637. #ifdef DEBUG
  638. {
  639. char cBuffer[512];
  640. sprintf(cBuffer, "Connected to [%s:%d]", m_sUartData.path, m_sUartData.port);
  641. LOG(cBuffer);
  642. }
  643. #endif
  644. setConnectionStatus(CS_CONNECTED);
  645. break;
  646. };
  647. };
  648. if (! init())
  649. {
  650. LOG_ERROR("Can not start the I/O thread - closing the connection");
  651. closePort();
  652. return false;
  653. };
  654. return true;
  655. }
  656. /*
  657. from https://stackoverflow.com/questions/2597608/c-socket-connection-timeout
  658. void connect_w_to(void) {
  659. int res;
  660. struct sockaddr_in addr;
  661. long arg;
  662. fd_set myset;
  663. struct timeval tv;
  664. int valopt;
  665. socklen_t lon;
  666. // Create socket
  667. soc = socket(AF_INET, SOCK_STREAM, 0);
  668. if (soc < 0) {
  669. fprintf(stderr, "Error creating socket (%d %s)\n", errno, strerror(errno));
  670. exit(0);
  671. }
  672. addr.sin_family = AF_INET;
  673. addr.sin_port = htons(2000);
  674. addr.sin_addr.s_addr = inet_addr("192.168.0.1");
  675. // Set non-blocking
  676. if( (arg = fcntl(soc, F_GETFL, NULL)) < 0) {
  677. fprintf(stderr, "Error fcntl(..., F_GETFL) (%s)\n", strerror(errno));
  678. exit(0);
  679. }
  680. arg |= O_NONBLOCK;
  681. if( fcntl(soc, F_SETFL, arg) < 0) {
  682. fprintf(stderr, "Error fcntl(..., F_SETFL) (%s)\n", strerror(errno));
  683. exit(0);
  684. }
  685. // Trying to connect with timeout
  686. res = connect(soc, (struct sockaddr *)&addr, sizeof(addr));
  687. if (res < 0) {
  688. if (errno == EINPROGRESS) {
  689. fprintf(stderr, "EINPROGRESS in connect() - selecting\n");
  690. do {
  691. tv.tv_sec = 15;
  692. tv.tv_usec = 0;
  693. FD_ZERO(&myset);
  694. FD_SET(soc, &myset);
  695. res = select(soc+1, NULL, &myset, NULL, &tv);
  696. if (res < 0 && errno != EINTR) {
  697. fprintf(stderr, "Error connecting %d - %s\n", errno, strerror(errno));
  698. exit(0);
  699. }
  700. else if (res > 0) {
  701. // Socket selected for write
  702. lon = sizeof(int);
  703. if (getsockopt(soc, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon) < 0) {
  704. fprintf(stderr, "Error in getsockopt() %d - %s\n", errno, strerror(errno));
  705. exit(0);
  706. }
  707. // Check the value returned...
  708. if (valopt) {
  709. fprintf(stderr, "Error in delayed connection() %d - %s\n", valopt, strerror(valopt)
  710. );
  711. exit(0);
  712. }
  713. break;
  714. }
  715. else {
  716. fprintf(stderr, "Timeout in select() - Cancelling!\n");
  717. exit(0);
  718. }
  719. } while (1);
  720. }
  721. else {
  722. fprintf(stderr, "Error connecting %d - %s\n", errno, strerror(errno));
  723. exit(0);
  724. }
  725. }
  726. // Set to blocking mode again...
  727. if( (arg = fcntl(soc, F_GETFL, NULL)) < 0) {
  728. fprintf(stderr, "Error fcntl(..., F_GETFL) (%s)\n", strerror(errno));
  729. exit(0);
  730. }
  731. arg &= (~O_NONBLOCK);
  732. if( fcntl(soc, F_SETFL, arg) < 0) {
  733. fprintf(stderr, "Error fcntl(..., F_SETFL) (%s)\n", strerror(errno));
  734. exit(0);
  735. }
  736. // I hope that is all
  737. }
  738. */
  739. bool deviceETH2UART::closePort()
  740. {
  741. //char tBuff[128];
  742. setConnectionStatus(CS_DISCONNECTED);
  743. #ifdef SERIAL_PING_PONG
  744. if (m_bThreadStatus != TH_PRE_INIT)
  745. #else
  746. if (m_bThreadAStatus != TH_PRE_INIT && m_bThreadBStatus != TH_PRE_INIT)
  747. #endif
  748. {
  749. uninit();
  750. };
  751. if (m_iDeviceFD != -1)
  752. {
  753. switch (m_sUartData.mode)
  754. {
  755. case SOL_UDP_CLIENT:
  756. case SOL_TCP_CLIENT:
  757. case SOL_UDP_SERVER:
  758. {
  759. #ifdef __linux__
  760. if (m_iDeviceFD > -1)
  761. {
  762. close(m_iDeviceFD);
  763. };
  764. #else
  765. // When your application is finished receiving datagrams close the socket.
  766. LOG("Server: Finished receiving.Closing the listening socket...");
  767. if (closesocket(m_sSocket) != 0)
  768. {
  769. sprintf(tBuff, "closesocket() failed!Error code : %ld", WSAGetLastError());
  770. LOG_ERROR(tBuff);
  771. }
  772. else
  773. {
  774. LOG("closesocket() is OK...");
  775. };
  776. // When your application is finished call WSACleanup.
  777. LOG("Server: Cleaning up...");
  778. if (WSACleanup() != 0)
  779. {
  780. sprintf(tBuff, "WSACleanup() failed!Error code : %ld", WSAGetLastError());
  781. LOG_ERROR(tBuff);
  782. }
  783. else
  784. {
  785. LOG("WSACleanup() is OK");
  786. };
  787. #endif
  788. break;
  789. };
  790. case SOL_TCP_SERVER:
  791. {
  792. if (m_iDeviceFD > -1)
  793. {
  794. close(m_iDeviceFD);
  795. };
  796. break;
  797. };
  798. };
  799. m_iDeviceFD = -1;
  800. };
  801. return true;
  802. }
  803. #ifdef SERIAL_PING_PONG
  804. void deviceETH2UART::m_fThreadProc(void)
  805. {
  806. int index;
  807. int RetVal;
  808. m_bThreadStatus = TH_WORKING;
  809. #ifdef DEBUG
  810. LOG("Sender Thread Started!");
  811. #endif
  812. pthread_setname_np( pthread_self(), "E2S IO" );
  813. while (m_bThreadStatus < TH_ENDED){
  814. m_mBufferProtectorMutex.lock();
  815. if (! m_qIO.empty()){
  816. SIO_TZ * tIOData;
  817. tIOData = m_qIO.front();
  818. m_mBufferProtectorMutex.unlock();
  819. if( tIOData ){
  820. // Remove from Queue
  821. m_mBufferProtectorMutex.lock();
  822. m_qIO.pop();
  823. m_mBufferProtectorMutex.unlock();
  824. index = 0;
  825. //Sending Data to line
  826. while ((index < tIOData->out_size) && (m_bThreadStatus < TH_ENDED)){
  827. #ifdef DEBUG_COMMUNICATION
  828. char TT[128];
  829. sprintf(TT, "Send \t%d bytes for \t%p", ( tIOData->out_size - index ), tIOData->boundParser );
  830. LOG(TT);
  831. #endif
  832. RetVal = sendBlock(tIOData->out_buffer + index, tIOData->out_size - index);
  833. if (RetVal > 0){
  834. index += RetVal;
  835. } else {
  836. // if 0 or -(error)
  837. if (RetVal == 0) {
  838. usleep(100);
  839. } else {
  840. setConnectionStatus(CS_DISCONNECTED);
  841. // m_nOutputBufferSize = 0;
  842. tIOData->out_size = 0;
  843. m_bThreadStatus = TH_ENDED;
  844. LOG_ERROR("Connection Droped on Sending Data");
  845. };
  846. };
  847. };
  848. //Try to receive data from line
  849. tIOData->out_size = 0;
  850. bool tDataOnline = false;
  851. uint8_t tTOCounter = 20;
  852. do {
  853. RetVal = recptBlock( tIOData->inp_buffer, &tIOData->inp_size );
  854. if( RetVal == -1 ){
  855. setConnectionStatus(CS_DISCONNECTED);
  856. tIOData->inp_size = 0;
  857. m_bThreadStatus = TH_ENDED;
  858. LOG_ERROR("Connection Droped on Reception Data");
  859. } else if( tIOData->inp_size ){
  860. tDataOnline = true;
  861. if( tIOData->boundParser == NULL ){
  862. } else {
  863. #ifdef DEBUG_COMMUNICATION
  864. char tB[128];
  865. sprintf( tB, "Read \t%d bytes for \t%p", tIOData->inp_size, tIOData->boundParser );
  866. LOG( tB );
  867. #endif
  868. tDataOnline = tIOData->boundParser->parse( tIOData->inp_buffer, tIOData->inp_size );
  869. };
  870. } else {
  871. if (tTOCounter) {
  872. tTOCounter--;
  873. SLEEP(5);
  874. #ifdef DEBUG_COMMUNICATION
  875. } else {
  876. LOG_ERROR("PACK TIMEOUT!");
  877. #endif
  878. };
  879. };
  880. } while ((m_bThreadStatus < TH_ENDED) && tTOCounter && ! (tDataOnline && RetVal == 0)); // Pack1 conditions -> White Space after Data.
  881. // Free Package
  882. #ifdef DEBUG_COMMUNICATION
  883. LOG("Finishing Read Package");
  884. #endif
  885. free(tIOData);
  886. } else {
  887. // Mutex already unlocked!
  888. SLEEP(5);
  889. };
  890. } else {
  891. m_mBufferProtectorMutex.unlock();
  892. SLEEP(5);
  893. };
  894. };
  895. }
  896. bool deviceETH2UART::sendData(uint8_t * Data, int DataSize, protocolParser *src ){
  897. if ( m_bThreadStatus != TH_WORKING ) {
  898. if( m_bThreadStatus < TH_WORKING ) {
  899. LOG_ERROR("Trying to Send Data Before Thread is Started!");
  900. } else {
  901. LOG_ERROR("Trying to Send Data After Thread is Dead!");
  902. }
  903. return false;
  904. };
  905. if (DataSize > MAXIMAL_SERIAL_IO_BUFFER_LENGTH) {
  906. LOG_ERROR("Data Too BIG");
  907. } else {
  908. SIO_TZ * tData = (SIO_TZ *) malloc(sizeof(SIO_TZ));
  909. if (tData) {
  910. memset( tData, 0, sizeof(SIO_TZ) );
  911. tData->out_size = DataSize;
  912. tData->boundParser = src;
  913. memcpy( tData->out_buffer, Data, DataSize );
  914. m_mBufferProtectorMutex.lock();
  915. m_qIO.push(tData);
  916. m_mBufferProtectorMutex.unlock();
  917. return true;
  918. } else {
  919. LOG_ERROR("MemAlloc Error!");
  920. };
  921. };
  922. return false;
  923. }
  924. #else // !SERIAL_PING_PONG
  925. void deviceETH2UART::m_fThreadAProc(void)
  926. {
  927. int index;
  928. int RetVal;
  929. m_bThreadAStatus = TH_WORKING;
  930. #ifdef DEBUG
  931. LOG("Sender Thread Started!");
  932. #endif
  933. pthread_setname_np( pthread_self(), "E2S Sender" );
  934. while (m_bThreadAStatus < TH_ENDED)
  935. {
  936. m_mBufferProtectorMutex.lock();
  937. if (m_nOutputBufferSize > 0)
  938. {
  939. index = 0;
  940. while ((index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED))
  941. {
  942. RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index);
  943. if (RetVal > 0)
  944. {
  945. index += RetVal;
  946. }
  947. if (RetVal == -1)
  948. {
  949. setConnectionStatus(CS_DISCONNECTED);
  950. m_nOutputBufferSize = 0;
  951. m_bThreadBStatus = TH_ENDED;
  952. m_bThreadAStatus = TH_ENDED;
  953. LOG_ERROR("Connection Droped on Sending Data");
  954. };
  955. };
  956. m_nOutputBufferSize = 0;
  957. m_mBufferProtectorMutex.unlock();
  958. }
  959. else
  960. {
  961. m_mBufferProtectorMutex.unlock();
  962. SLEEP(5);
  963. };
  964. };
  965. }
  966. void deviceETH2UART::m_fThreadBProc(void)
  967. {
  968. m_bThreadBStatus = TH_WORKING;
  969. int RetVal;
  970. #ifdef DEBUG
  971. LOG("Recipient Thread Started!");
  972. #endif
  973. pthread_setname_np( pthread_self(), "E2S Receiver" );
  974. while (m_bThreadBStatus < TH_ENDED)
  975. {
  976. RetVal = recptBlock(m_pInputBuffer, &m_nInputBufferSize);
  977. if (RetVal == -1)
  978. {
  979. setConnectionStatus(CS_DISCONNECTED);
  980. m_nInputBufferSize = 0;
  981. // if(!getStatus()) {
  982. m_bThreadBStatus = TH_ENDED;
  983. m_bThreadAStatus = TH_ENDED;
  984. //} else SLEEP(100);
  985. LOG_ERROR("Connection Droped on Reception Data");
  986. }
  987. else if (m_nInputBufferSize > 0)
  988. {
  989. do
  990. {
  991. m_mQueueProtectorMutex.lock();
  992. if (m_vParsers.size())
  993. {
  994. for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++)
  995. {
  996. (*index)->parse(m_pInputBuffer, m_nInputBufferSize);
  997. }
  998. m_nInputBufferSize = 0;
  999. m_mQueueProtectorMutex.unlock();
  1000. }
  1001. else
  1002. {
  1003. m_nInputBufferSize = 0;
  1004. m_mQueueProtectorMutex.unlock();
  1005. #ifdef DEBUG_EXTRA
  1006. LOG_ERROR("Try to parse data but No Parsers Assigned!");
  1007. #endif
  1008. SLEEP(100);
  1009. };
  1010. }
  1011. while ((m_vParsers.size() == 0) && (m_bThreadBStatus < TH_ENDED) && (m_bThreadBStatus < TH_ENDED));
  1012. }
  1013. else
  1014. {
  1015. SLEEP(5);
  1016. };
  1017. };
  1018. }
  1019. bool deviceETH2UART::sendData(uint8_t * Data, int DataSize)
  1020. {
  1021. if (m_bThreadAStatus != TH_WORKING)
  1022. {
  1023. if (m_bThreadAStatus < TH_WORKING)
  1024. {
  1025. LOG_ERROR("Trying to Send Data Before Thread is Started!");
  1026. }
  1027. else
  1028. {
  1029. LOG_ERROR("Trying to Send Data After Thread is Dead!");
  1030. }
  1031. return false;
  1032. };
  1033. m_mBufferProtectorMutex.lock();
  1034. if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_IO_BUFFER_LENGTH)
  1035. {
  1036. m_mBufferProtectorMutex.unlock();
  1037. LOG_ERROR("Data Too BIG");
  1038. return false;
  1039. };
  1040. memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize);
  1041. m_nOutputBufferSize += DataSize;
  1042. m_mBufferProtectorMutex.unlock();
  1043. return true;
  1044. }
  1045. #endif // !SERIAL_PING_PONG
  1046. bool deviceETH2UART::reconnect(void)
  1047. {
  1048. std::lock_guard<std::recursive_mutex> tLock(m_mConnLock);
  1049. m_bValid = create_SOL(); // closes the old connection first
  1050. return m_bValid;
  1051. }
  1052. int deviceETH2UART::recptBlock(unsigned char * Buffer, int * BufferLength)
  1053. {
  1054. #ifdef __linux__
  1055. int RetVal = 0;
  1056. #else
  1057. DWORD RetVal = 0;
  1058. #endif
  1059. if (m_eConnectionStatus == CS_CONNECTED)
  1060. {
  1061. #ifdef __linux__
  1062. if (m_iDeviceFD > -1)
  1063. {
  1064. struct sockaddr ClientAddress;
  1065. socklen_t addr_len = sizeof(ClientAddress); // len is value/resuslt
  1066. // RetVal = recvfrom( m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_WAITALL, ( struct sockaddr *) &m_sClientAddr, &addr_len );
  1067. RetVal = recvfrom(m_iDeviceFD, (char *) Buffer, MAXIMAL_SOCKET_IO_BUFFER_LENGTH, MSG_DONTWAIT, (struct sockaddr *) &ClientAddress, &addr_len);
  1068. // TCP: 0 = the gateway closed the connection (errno is not set then: the old check read a
  1069. // stale errno and could keep a closed connection forever). < 0: an error unless EAGAIN/EINTR
  1070. if ((RetVal == 0 && m_sUartData.mode == SOL_TCP_SERVER) || RetVal < 0)
  1071. {
  1072. if (RetVal == 0 || (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR))
  1073. {
  1074. LOG_ERROR("Peer Closes Connection!");
  1075. shutdown(m_iDeviceFD, 2);
  1076. close(m_iDeviceFD);
  1077. *BufferLength = 0;
  1078. m_iDeviceFD = -1;
  1079. setConnectionStatus(CS_DISCONNECTED);
  1080. return -1;
  1081. };
  1082. };
  1083. }
  1084. else
  1085. {
  1086. LOG_ERROR("Not Connected!");
  1087. *BufferLength = 0;
  1088. setConnectionStatus(CS_DISCONNECTED);
  1089. return -1;
  1090. };
  1091. #else
  1092. switch (m_eType)
  1093. {
  1094. case SOL_UDP_CLIENT:
  1095. case SOL_TCP_CLIENT:
  1096. case SOL_UDP_SERVER:
  1097. {
  1098. SOCKADDR_IN tAddr;
  1099. int tLen = sizeof(SOCKADDR_IN);
  1100. RetVal = recvfrom(m_sSocket, (char *) Buffer, MAXIMAL_SOCKET_IO_BUFFER_LENGTH, 0, (struct sockaddr *) &tAddr, &tLen);
  1101. if (RetVal == SOCKET_ERROR)
  1102. {
  1103. char cBuffer[165];
  1104. sprintf(cBuffer, "recvfrom() failed with error code : %d", WSAGetLastError());
  1105. LOG_ERROR(cBuffer);
  1106. };
  1107. break;
  1108. };
  1109. };
  1110. #endif
  1111. }
  1112. else
  1113. {
  1114. // make prep for connection SOL_TCP_SERVER
  1115. if (m_sUartData.mode == SOL_TCP_CLIENT)
  1116. {
  1117. // ACCEPT
  1118. struct sockaddr ClientAddress;
  1119. socklen_t size = (socklen_t) sizeof(struct sockaddr_in);
  1120. // int ClientSocket;
  1121. m_iDeviceFD = accept(m_iMasterFD, &ClientAddress, &size);
  1122. if (m_iDeviceFD < 0)
  1123. {
  1124. setConnectionStatus(CS_DISCONNECTED);
  1125. LOG_ERROR("Connection Accept Failure!");
  1126. };
  1127. }
  1128. else
  1129. {
  1130. LOG_ERROR("RCPT ON not connected!");
  1131. shutdown(m_iDeviceFD, 2);
  1132. close(m_iDeviceFD);
  1133. *BufferLength = 0;
  1134. m_iDeviceFD = -1;
  1135. setConnectionStatus(CS_DISCONNECTED);
  1136. };
  1137. return -1; // Exit after unsuccess reconnect
  1138. };
  1139. if (RetVal > 0)
  1140. {
  1141. #ifdef DEBUG_SERIAL_COMMUNICATION
  1142. char MsgBuffer[CLOG];
  1143. if (RetVal > 1 || RetVal == 0)
  1144. {
  1145. sprintf(MsgBuffer, "Received %d bytes", RetVal);
  1146. }
  1147. else
  1148. {
  1149. sprintf(MsgBuffer, "Received 1 byte");
  1150. };
  1151. LOG(MsgBuffer);
  1152. for (int i = 0; i < RetVal; i++)
  1153. {
  1154. sprintf(MsgBuffer, "0x%02X", Buffer[i]);
  1155. LOG(MsgBuffer);
  1156. };
  1157. #endif
  1158. *BufferLength = RetVal;
  1159. return RetVal;
  1160. };
  1161. *BufferLength = 0;
  1162. if (RetVal == -1)
  1163. {
  1164. return 0;
  1165. }
  1166. if (RetVal == 0)
  1167. {
  1168. errno = 0;
  1169. return 0;
  1170. };
  1171. /* r < -1, should never happen. */
  1172. errno = EIO;
  1173. return 0;
  1174. }
  1175. int deviceETH2UART::sendBlock(unsigned char * Data, int DataSize)
  1176. {
  1177. #ifdef __linux__
  1178. int RetVal = 0;
  1179. #else
  1180. DWORD RetVal = 0;
  1181. #endif
  1182. if (m_eConnectionStatus == CS_CONNECTED)
  1183. {
  1184. #ifdef __linux__
  1185. if (m_iDeviceFD > -1)
  1186. {
  1187. #ifdef DEBUG_EXTRA
  1188. char cBuffer[256];
  1189. sprintf(cBuffer, "Write into Port %d bytes", DataSize);
  1190. LOG(cBuffer);
  1191. #endif
  1192. struct sockaddr ClientAddress;
  1193. socklen_t addr_len = sizeof(ClientAddress);
  1194. RetVal = sendto(m_iDeviceFD, (const char *) Data, DataSize, MSG_CONFIRM, (const struct sockaddr *) &ClientAddress, addr_len);
  1195. if ((RetVal == -1) && (errno != EINTR) && (errno != EWOULDBLOCK))
  1196. {
  1197. LOG_ERROR("Error acures while writing data into the Socket");
  1198. shutdown(m_iDeviceFD, 2);
  1199. close(m_iDeviceFD);
  1200. m_iDeviceFD = -1;
  1201. setConnectionStatus(CS_DISCONNECTED);
  1202. return -1;
  1203. };
  1204. if (RetVal < 0)
  1205. {
  1206. RetVal = 0;
  1207. }
  1208. #ifdef DEBUG_EXTRA
  1209. sprintf(cBuffer, "Bytes Sent: %ld", RetVal);
  1210. LOG(cBuffer);
  1211. #ifdef DEBUG_SERIAL_COMMUNICATION
  1212. for (int zz = 0; zz < RetVal; zz++)
  1213. {
  1214. sprintf(cBuffer, "SD: 0x%02X", (uint8_t) Data[zz]);
  1215. LOG(cBuffer);
  1216. };
  1217. #endif
  1218. #endif
  1219. }
  1220. else
  1221. {
  1222. LOG_ERROR("Not Connected!");
  1223. // m_bConnected = false;
  1224. setConnectionStatus(CS_DISCONNECTED);
  1225. return -1;
  1226. };
  1227. #else // Windows
  1228. if (sendto(m_sSocket, (char *) Data, DataSize, 0, (struct sockaddr *) &ReceiverAddr, sizeof(ReceiverAddr)) == SOCKET_ERROR)
  1229. {
  1230. char cBuffer[256];
  1231. sprintf(cBuffer, "sendto() failed with error code : %d", WSAGetLastError());
  1232. LOG_ERROR(cBuffer);
  1233. return -1;
  1234. };
  1235. #endif
  1236. }
  1237. else
  1238. {
  1239. #ifdef DEBUG
  1240. LOG("Port is not Ready to Send");
  1241. #endif
  1242. return -1;
  1243. };
  1244. return RetVal;
  1245. }
  1246. #undef E2U_IO_STATUS
  1247. #undef LOG_ERROR
  1248. #undef LOG