Skip to content

Conversation

@KarimAziev
Copy link

This pull request addresses the issue #77, where atomic-chrome-on-message function 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 the emacs-websocket repository.

To resolve this, the following changes have been made in atomic-chrome.el:

  1. 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.

  2. Modification of the atomic-chrome-on-message function 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.

  3. Cleanup logic in the atomic-chrome-on-close function 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.

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.
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.

1 participant