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

Issue 8: Handle the websocket close event #9

Merged
merged 3 commits into from
Sep 28, 2020
Merged

Conversation

JCash
Copy link
Contributor

@JCash JCash commented Sep 27, 2020

No description provided.

@JCash JCash requested a review from britzl September 27, 2020 14:58
* `0` to disable debugging (i.e. no debug output).
* `1` to display state changes.
* `2` to display the messages sent and received.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to have for the users to be able to debug what's happening.

@@ -20,10 +20,13 @@ local function websocket_callback(self, conn, data)
print("Connected " .. conn)
-- self.connection = conn
elseif data.event == websocket.EVENT_ERROR then
print("Error:", data.error)
print("Error:", data.message)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Api change: All events now have the "message".

lua_setfield(L, -2, "message");
}
lua_pushlstring(L, conn->m_Buffer + msg_offset, msg_length);
lua_setfield(L, -2, "message");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to reason about (and thus remember)

@@ -94,7 +86,7 @@ ssize_t WSL_RecvCallback(wslay_event_context_ptr ctx, uint8_t *buf, size_t len,
dmSocket::Result socket_result = Receive(conn, buf, len, &r);

if (dmSocket::RESULT_OK == socket_result && r == 0)
socket_result = dmSocket::RESULT_WOULDBLOCK;
socket_result = dmSocket::RESULT_CONNABORTED;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, when the server does an abnormal exit (1006), we don't get that message, and we'd just wait forever.

Copy link
Contributor

@britzl britzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@JCash JCash merged commit 23ba179 into master Sep 28, 2020
@JCash JCash deleted the issue-8-close-event branch September 28, 2020 07:30
@JCash JCash linked an issue Sep 28, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for websocket close event
2 participants