-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Additions to WiFiClient and WiFiServer #404
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#include <lwip/netdb.h> | ||
|
||
#undef write | ||
#undef close | ||
|
||
int WiFiServer::setTimeout(uint32_t seconds){ | ||
struct timeval tv; | ||
|
@@ -103,8 +104,16 @@ bool WiFiServer::hasClient() { | |
} | ||
|
||
void WiFiServer::end(){ | ||
close(sockfd); | ||
lwip_close_r(sockfd); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh breaks with the other close... |
||
sockfd = -1; | ||
_listening = false; | ||
} | ||
|
||
void WiFiServer::close(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should go with one or the other ;) What's the official API for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ESP8266WiFiServer has close() and stop(). ESP32 WiFiServer has end(). ESP8266WebServer calls close. I chose to put all three for maximum backwards compatibility. void WebServer::close() {
#ifdef ESP8266
_server.close();
#else
// TODO add ESP32 WiFiServer::close()
_server.end();
#endif
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ESP32 should actually always use stop() as that is the official Arduino API. close and end should e deprecated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I can remove close and end. |
||
end(); | ||
} | ||
|
||
void WiFiServer::stop(){ | ||
end(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not official Arduino API is it? We do not really have _P anything ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESP8266WebServer has *_P methods so I added support for them in the ESP32 version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_P methods imply PROGMEM an we do not have PROGMEM on esp32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copercini Compare pgmspace.h on ESP32 vs. ESP8266. There is no support for PROGMEM on ESP32 so pgmspace.h neuters the _P functions to their non _P equivalents.
But to avoid breaking lots of apps and libraries is would be good to translate _P functions to something that works on ESP32. Instead of making this change, libs and apps would have to do this.
#ifdef ESP8266
_currentClient.write_P(content, size);
#else
_currentClient.write(content, size);
#endif
If there are many occurrences, perhaps
#define write_P write
would do the job. But it would be less work and fewer breakage issues if write_P() is added even though it does the same thing as write().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not agree to bloat the classes unnecessary just for the sake of compatibility with everything. We have to add all of the _P methods then to Print, Stream and whatever else has them on ESP8266... bad idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What approach would you suggest library authors take when it comes to writing code which supports both the ESP8266 and the ESP32?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if we separate code like it's with WiFi? will all of the source files be included even if not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At link time, only the functions which were referenced will be left in the program, if -ffunction-section and -gc-sections options are used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding write_P, how about adding
#define write_P write
to pgmspace.h?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#define write_P write
will not lead to proper client.write_P. @igrr correct me if I'm wrong, but that is what I believe the result will be