-
Notifications
You must be signed in to change notification settings - Fork 563
esp8266: share port 80 with regular webserver #575
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
Conversation
In this commit, adding missing That should be done in master until this PR is merged, I can submit a PR is desired. |
(hit-n-run comment via esp8266 gitter)
Might I suggest to also take a look at initialization overall:
Struct in question is initialized a-la C POD struct, which is probably not the thing we want :/ Since the struct already allows default values, this can be replaced with new / delete (placement or otherwise) or reset() method bound to the struct itself or just straight up copy assignment which will replace all members - edit: specifically, because of this comment by the GCC:
edit2: assignment |
thanks for the work, hope I find the time to look at this I more detail at the weekend. |
@mcspr I think the placement constructor is the best bet in this case.
Even though edit A proper constructor is missing to initialize |
Maybe not placement (my mistake mentioning it, for some reason I read the code as it was using raw memory and _clients was allocated separatly...) Also note of the recent String PR to the esp8266 core which made String SSO flag 0 instead of 1, right now it will return ptr to itself aka sso buffer containing zeroes instead of 0 / nullptr, opposite of what it done before as the result of memset zeroing out memory and String assuming it's in heap. |
Thanks ! |
will be in master soon, will do some testing and init clean up. |
@mcspr |
looks like the current platformio ESP8266 core does still miss the Webserver Hook Functions |
tested with Arduino IDE and merged to master :) |
Released with version 2.3.1 |
@d-a-v ref.
For example, this way it is possible to lose String heap buffer, which will be reset to default-0 when constructor is called a 2nd time on the same memory location and does not expect the existing object. ~String() will never be called for the 1st one, unless it is done manually. @Links2004 |
@mcspr We agree on that @Links2004 @mcspr
|
This PR can appear as huge changes, where it's not.
The goal is to allow sharing port 80 with native esp8266 arduino core webserver.
This is possible thanks to this change on esp8266 arduino core.
To summarize, the webserver is the one which accepts the new connections and reads the first line where method and URI are specified. Before going further, the webserver shows this line to optional hooks and let them take over the connection if they wish to.
For this to happen with arduinoWebSockets, the
WebSocketsServer
class has to be split into two classes:WebSocketsServerCore
which is mainly the originalWebSocketsServer
class, deprived of the TCP serverWebSocketsServer
, derived fromWebSocketsServerCore
and holding the TCP server part.and a new optional class is added:
WebSockets4WebServer
which also derives fromWebSocketsServerCore
and connects toESP8266WebServer
.The API is unchanged, the logic is not changed, examples are untouched (one is added). This PR is big because of the internal class name change and the splitting of some methods into two parts, one to
WebSocketsServerCore
and the other toWebSocketsServer
.Also to be noted:
void dropNativeClient (WSclient_t * client)
to properly close the TCP connection also when there is no more available place in the websocket array.examples/esp8266/WebSocketServerHooked
)