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.
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.
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 atokio
socket. Thesocket2
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.