fix: support fragmented websocket frames, resolves #77#79
Open
KarimAziev wants to merge 2 commits intoalpha22jp:masterfrom
Open
fix: support fragmented websocket frames, resolves #77#79KarimAziev wants to merge 2 commits intoalpha22jp:masterfrom
KarimAziev wants to merge 2 commits intoalpha22jp:masterfrom
Conversation
This commit introduces handling for fragmented websocket frames in the atomic-chrome Emacs extension. A new hash table, `atomic-chrome-frame-socket-incomplete-buffers-hash`, maps websocket sockets to buffers that accumulate payload fragments from incomplete websocket frames. This allows for efficient handling and concatenation of large and/or fragented messages. The `atomic-chrome-on-message` function has been updated to accumulate payload fragments in a dedicated buffer when frames are marked as incomplete or a previous incomplete frame exists for the socket. Upon receiving the final fragment, the full payload is reconstructed, decoded, and processed as a JSON object to either create or update associated Emacs buffers for editing. Additionally, the `atomic-chrome-on-close` function now removes the associated buffer from the hash table when a websocket socket is closed.
This commit adjusts the buffer generation in `atomic-chrome.el` to ensure compatibility with Emacs versions below 28.1 by conditionally adding the second argument to `generate-new-buffer` based on the Emacs version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request addresses the issue #77, where
atomic-chrome-on-messagefunction failed to handle incomplete frames, leading to JSON parsing errors for concatenated frames. The problem was initially outlined by @ahyatt while investigating a related issue in theemacs-websocketrepository.To resolve this, the following changes have been made in
atomic-chrome.el:Introduction of a hash table,
atomic-chrome-frame-socket-incomplete-buffers-hash, to keep track of incomplete frame payloads associated with a specific websocket connection. This enhancement ensures that payloads from incomplete frames are accumulated efficiently until the final fragment is received.Modification of the
atomic-chrome-on-messagefunction to support the handling of incomplete frames. The function now checks if a given frame is complete and, if not, appends its payload to a buffer designated for that socket's incomplete messages. Upon receiving the final fragment, it reconstructs the full payload, decodes it, and processes it as a JSON object. This process allows for the creation or update of Emacs buffers associated with the editing session.Cleanup logic in the
atomic-chrome-on-closefunction to remove any stored incomplete frame payloads once a websocket connection is closed.Looking forward to your feedback and hoping for a merge into the main repository.