Checking Ethernet Connection
Posted: Mon Nov 08, 2021 9:14 am
I have a websocket running on my mod54415 system that gets data sent through it a few times per second.
I'm wondering if there's an elegant way besides what I'm currently doing to check if the ethernet connection is lost (like if the cable gets yanked out) and the system isn't expecting the loss in connectivity. This might end up being needed elsewhere to detect lose of connection with an application talking to the system via TCP, there isn't currently a heartbeat check on that.
I'm currently polling the GetDHCPAddress() function before updating the websocket. So if that fails then it doesn't keep trying to send data through the websocket.
In testing once the cable is reconnected the socket closes and opens as expected. Before the function polling, the system would eventually trap and reset. I tried checking the error_fds rather than polling GetDHCPAddress() but nothing triggered when the ethernet was removed. I assume with my fairly surface level understanding of websockets that it wouldn't know that it was closed since the fd wasn't closed properly.
I'm wondering if there's an elegant way besides what I'm currently doing to check if the ethernet connection is lost (like if the cable gets yanked out) and the system isn't expecting the loss in connectivity. This might end up being needed elsewhere to detect lose of connection with an application talking to the system via TCP, there isn't currently a heartbeat check on that.
I'm currently polling the GetDHCPAddress() function before updating the websocket. So if that fails then it doesn't keep trying to send data through the websocket.
In testing once the cable is reconnected the socket closes and opens as expected. Before the function polling, the system would eventually trap and reset. I tried checking the error_fds rather than polling GetDHCPAddress() but nothing triggered when the ethernet was removed. I assume with my fairly surface level understanding of websockets that it wouldn't know that it was closed since the fd wasn't closed properly.