Subject: | server not closing client connections |
Date: | Sat, 20 May 2017 01:06:10 +0200 |
To: | bug-Device-Modbus-TCP [...] rt.cpan.org |
From: | Olivier Colin <oliviercommelarbre [...] gmail.com> |
Dear JFRAIRE,
I've started using both the Modbus TCP client and server modules and they
work great sofar for my application, thank you!!
I found just this little annoying bug which i could correct easily with a
one line patch in Device/Modbus/TCP/Server.pm.
the problem is on the server side (Device::Modbus::TCP::Server).
when the client disconnects, or when the 5s timeout expires on reading a
modbus request on the server side, the event is well cought in the code (in
the catch block in Device/Modbus/TCP/Server.pm line#63), however the socket
does not get actually closed (even though it is inoperative or timed out),
so the code never leaves the while loop that keeps trying to read incoming
requests.
The problem is that the condition for staying in the loop
($self->socket->connected) will never return false even though the client
has left the connection. In fact, the IO::Socket->connected method returns
false only when the socket has been locally closed. I found the explanation
here: http://www.perlmonks.org/?node_id=300813.
Hence to solve the problem, it is just needed to locally close the socket
in the catch block in question with:
$self->socket->close;
I've tested and it works now like a dream, lost client connections cr idle
ones (for more than 5secs) are cleanly closed and released by the server.
I hope you can integrate in your next release on cpan,
please do not hesitate to ask more details if you need.
wishing you a good continuation and thank you again!
Olivier