-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Feature Websocket module #1433
Feature Websocket module #1433
Conversation
I will review the code for formal aspects, but websockets is not a use case for me. We'd need someone else who can assess the overall design and fitness for typical use. |
Ok, thank you. |
static int websocketclient_onConnection(lua_State *L) { | ||
NODE_DBG("websocketclient_onConnection\n"); | ||
ws_info *ws = (ws_info *) luaL_checkudata(L, 1, METATABLE_WSCLIENT); | ||
luaL_argcheck(L, ws, 1, "Client websocket expected"); |
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.
All checks for ws
after luaL_checkudata()
are redundant since this function will effectively not return to your context in case of an error. It'll long jump to the calling Lua context instead. Ref. https://www.lua.org/manual/5.1/manual.html#lua_error.
Also applies to similar instances below.
As a general remark: your code bases on espconn which will vanish sooner or later. There are already efforts ongoing to re-base networking to LWIP in #1379. Don't know if it's worth considering this here already from the beginning. |
I really propose to reject new modules that use espconn layer. It's very bad and bugous. |
My use case is websocket server which doesn't appear to be in here. |
Thanks for reviewing @devsaurus. I also feel that espconn layer is bad, so I understand the need to remove it. It would be nice to continue to work on this so it uses LWIP, but on my next MR. That wouldn't make me feel that I wasted so much time battling the espconn! @creationix: Yes, you're right. But it would be mostly the same except from having a new method: |
96687c4
to
73a01ce
Compare
7eae658
to
262b29c
Compare
case 0: | ||
NODE_DBG("connection\n"); | ||
|
||
if (data->onConnection != LUA_NOREF) { |
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.
As mentioned earlier, luaL_unref()
handles LUA_NOREF
. You can skip the "if" here and below.
Apart from cosmetic topics, the final gating question IMO is: shall we accept a new module that's based on espconn? |
262b29c
to
6febca9
Compare
👍 from my side if we have the commitment from the author / maintainer to port it to lwIP once that's ready - and we've got that here. |
Btw Luís, since you just created your first NodeMCU module (I believe) can I invite you to edit / amend "How to write a C module" if you have any feedback. |
Thanks for merging this! Ok, I'll work on that. But I'd say that as it stands now, it is already helpful. |
@marcelstoer I've added a small section for debugging and change the start a tiny bit, feel free to adjust as you see fit. |
Fixes #1425.
docs/en/*
.Websockets allow a two-way communication with servers which is better suited for realtime applications. Existing Lua impementations are not as fast and take over 10KB of heap for a single connection.
Since it has been a several years without programming in C or C++, I'm sure my code could be improved. Please let me know where. Also, I'd like some additional testing to other websockets servers (I've mainly tested against Pushers and websocket.org).
Committers supporting this PR: .