-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
Hey,
I use a library where the EthernetClient instance is created once and then reused.
This was not really working - the first call worked, then it did not connect for addtional uses.
I tracked it down to the following:
The library did the following:
/if (udata->client->theClient->connected())
{
udata->client->theClient->stop();
}/
And this was the reason! After all data was received the called server closed the connection. So the socket was in status "CLOSE_WAIT" and "available" returned 0 because all data was already read. That's why "stop" was never called.
And that's why the "conenct" method found a still set "_sock" to a valid number and returned false.
I found the advice to use "if connected() then stop()" in several sources in the internet, but this brings big problems as seen here ...
I think the fix should be to change the check in "connected": All Sockets that are in CLOSE_WAIT are reused in any case ... so a call to "connect" should check also "connected" and call stop or simply reuse that socket also when _sock is a value < MAX_SOCK_NUM