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

Added new API s to allow fragmented text to be send (IDFGH-10198) #368

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

gabsuren
Copy link
Contributor

@gabsuren gabsuren commented Sep 26, 2023

Added new APIs esp_websocket_client_send_text_partial,
esp_websocket_client_send_bin_partial
esp_websocket_client_send_cont_data
esp_websocket_client_send_fin
esp_websocket_client_send_with_exact_opcode

@CLAassistant
Copy link

CLAassistant commented Sep 26, 2023

CLA assistant check
All committers have signed the CLA.

@gabsuren gabsuren force-pushed the feature/websocket_new_api branch from 720fcfc to b7b763a Compare September 26, 2023 10:54
@gabsuren gabsuren changed the title fead(websocket): Added new API s to allow fragmented text to be send (IDFGH-10198) [WIP] fead(websocket): Added new API s to allow fragmented text to be send (IDFGH-10198) Sep 26, 2023
@gabsuren gabsuren force-pushed the feature/websocket_new_api branch 3 times, most recently from b0ca150 to 2e73302 Compare October 2, 2023 09:03
@gabsuren gabsuren changed the title [WIP] fead(websocket): Added new API s to allow fragmented text to be send (IDFGH-10198) fead(websocket): Added new API s to allow fragmented text to be send (IDFGH-10198) Oct 2, 2023
@gabsuren gabsuren requested a review from david-cermak October 2, 2023 09:03
@gabsuren gabsuren changed the title fead(websocket): Added new API s to allow fragmented text to be send (IDFGH-10198) Added new API s to allow fragmented text to be send (IDFGH-10198) Oct 2, 2023
Copy link
Collaborator

@david-cermak david-cermak left a comment

Choose a reason for hiding this comment

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

LGTM, nice work!

@david-cermak
Copy link
Collaborator

@gabsuren please fix the commit message, so it's readable (has the title and the body). Note that this commit message would be used to compose the release notes!

@gabsuren gabsuren force-pushed the feature/websocket_new_api branch 4 times, most recently from f97eed0 to 11e8526 Compare October 3, 2023 09:24
…ission

Intoduced new APIs`esp_websocket_client_send_text_partial`,
            `esp_websocket_client_send_bin_partial`
            `esp_websocket_client_send_cont_mgs`
            `esp_websocket_client_send_fin`
            `esp_websocket_client_send_with_exact_opcode`
@gabsuren gabsuren force-pushed the feature/websocket_new_api branch from 11e8526 to fae80e2 Compare October 3, 2023 14:46
@gabsuren gabsuren merged commit ea14e15 into espressif:master Oct 3, 2023
28 checks passed
widx += wlen;
need_write = len - widx;

if (esp_websocket_client_send_with_exact_opcode(client, opcode | WS_TRANSPORT_OPCODES_FIN, data, len, timeout) != true) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this is the original problem causing #460

One nitpick here (sorry, missed that) is that this API shouldn't be called with_exact_opcode() if we're changing the opcode based on the fragmentation.
So after the prefix, we should at least mention it in the comments.
I'd suggest though adding one extra boolean parameter append_fin to make it cleaner.

@@ -1092,17 +1128,33 @@ int esp_websocket_client_send_text(esp_websocket_client_handle_t client, const c
return esp_websocket_client_send_with_opcode(client, WS_TRANSPORT_OPCODES_TEXT, (const uint8_t *)data, len, timeout);
}

int esp_websocket_client_send_text_partial(esp_websocket_client_handle_t client, const char *data, int len, TickType_t timeout)
{
return esp_websocket_client_send_with_exact_opcode(client, WS_TRANSPORT_OPCODES_TEXT, (const uint8_t *)data, len, timeout);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now, this is another potential problem, we're sending something with the "exact" opcode, but the last frame should contain FIN (which is apparently missing)

and I think it's actually missing even after #461 merged

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to mark the last frame I added esp_websocket_client_send_fin API.
And documented for esp_websocket_client_send_text_partial
- To mark the end of fragmented data, you should use the 'esp_websocket_client_send_fin(...)' API. This sends a FIN frame.
https://github.com/espressif/esp-protocols/blob/f62db5cfa2e64a27828a90c42ce92c2d2cb4ae89/components/esp_websocket_client/include/esp_websocket_client.h#L284C1-L289C128

Copy link
Collaborator

Choose a reason for hiding this comment

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

Plus we're not locking the client and perform the usually API parameters check?

{
return esp_websocket_client_send_with_exact_opcode(client, WS_TRANSPORT_OPCODES_CONT, (const uint8_t *)data, len, timeout);
}

int esp_websocket_client_send_bin(esp_websocket_client_handle_t client, const char *data, int len, TickType_t timeout)
{
return esp_websocket_client_send_with_opcode(client, WS_TRANSPORT_OPCODES_BINARY, (const uint8_t *)data, len, timeout);
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

4 participants