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

WiFiServer simple improvements #325

Open
davepruitt opened this issue Jan 14, 2022 · 0 comments
Open

WiFiServer simple improvements #325

davepruitt opened this issue Jan 14, 2022 · 0 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@davepruitt
Copy link

The WiFiServer object only contains a constructor that accepts a uint16_t for the port number. It would be nice to allow the user to use an empty constructor and then define the port later.

Additionally, the begin() function's return value is void, meaning that the user has no way of knowing whether it succeeded or not, unless they use the other form of the begin() function which takes a uint8_t as a parameter, but users may not know what to pass in for that parameter, especially when all they want to do is get the result from the begin() function.

Creating an empty constructor would be dirt simple:

WiFiServer::WiFiServer() :
    _socket(-1)
{
    //empty
}

We can then provide 2 new forms of the begin() function. For the sake of this post, I will call this new function beginWithResult because it returns the result.

One form of the function takes a uint16_t port as a parameter, allowing the user to specify the port when they call begin() rather than when they construct the object. The other form of the function assumes a port has already been defined. Here are the two new functions:

uint8_t WiFiServer::beginWithResult (uint16_t port)
{
    _port = port;
    return beginWithResult();
}

uint8_t WiFiServer::beginWithResult ()
{
    return begin(0);
}

I've already made these code changes in my own fork of the repository, and I would be happy to submit a pull request. I think these changes would really improve the usage of the WiFiServer class.

@per1234 per1234 added topic: code Related to content of the project itself type: enhancement Proposed improvement labels Jan 14, 2022
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: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

2 participants