Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EthernetServer problems with current implementation of operator bool. #236

Open
JAndrassy opened this issue Oct 17, 2023 · 0 comments
Open
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@JAndrassy
Copy link
Contributor

Problem 1)server.available() works even without server.begin(). if available() doesn't find a listening socket, it calls begin to add it. This should not happen.

Problem 2) server's operator bool returns false if a client already connected to the listening socket. When a client connects, the socket state changes to established. The next call to available() adds a new listening socket, but until then if (server) is false so it is not possible to use op bool to detect if the server is started. It would be useful in a sketch and for Problem 1.

The documentation for operator bool says "It can also tell you when no more sockets are available to listen for more clients, because the maximum number have connected.". This is a bad attempt to make a special case of the Problem 2 a feature. Returning false from op bool if there is no more free position to add a new listening socket is not useful. available still works for connected clients and it will add a listening socket as soon as there is a free position.

One solution would be to add a field bool started, set it to true in begin and use it in op bool (and set it to false in end() PR).

Other solution would be in op bool to return true if (server_port[i] == _port) without checking the status. This will work because after begin there will always be at least one record with _port. Method available() removes disconnected clients, but always adds a new listening socket if there isn't one. This version of op bool then can be used at the beginning of available() to check if server was started with begin(). I prefer this version and I will try to a PR.

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants