Skip to content

Reuse of EthernetClient instances don't work when check connected() before stop() #3829

@Apollon77

Description

@Apollon77

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

Metadata

Metadata

Assignees

Labels

Library: EthernetThe Ethernet Arduino libraryfeature requestA request to make an enhancement (not a bug fix)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions