DrMemCS / drmem

Full source tree for the DrMem control system
MIT License
3 stars 4 forks source link

:bug: driver wasn't detecting a stale TCP connection #72

Closed rneswold closed 1 year ago

rneswold commented 1 year ago

This driver was using tokio::net::TcpStream to connect to the RPi that was monitoring the sump pump. If that connection broke (due to a power outage, for instance), the driver would wait forever and would never get any data from the remote end.

This commit pulls in the socket2 crate so that we can turn on the "keep-alive" option for the socket (tokio doesn't provide this option.)

Note that we use the socket2 crate's API to build, configure, and connect the socket before converting it to a tokio socket. The socket2 API is synchronous so, for connecting, I set the timeout to 0.1 seconds. This is more than enough time to connect and it minimizes the amount of time taken away from other async tasks.

rneswold commented 1 year ago

I pulled the Ethernet from the RPi that the driver talks to and, after a few seconds, the driver reported a socket problem. Plugging the Ethernet back in restored the connection.