emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/websocket 268a0726b8 062/114: execute handshake after p


From: ELPA Syncer
Subject: [elpa] externals/websocket 268a0726b8 062/114: execute handshake after process status moved to open
Date: Wed, 15 Feb 2023 20:59:00 -0500 (EST)

branch: externals/websocket
commit 268a0726b80f04c1a08c84b0f01039b18b9c8ae0
Author: Yuya Minami <yuya373@me.com>
Commit: Yuya Minami <yuya373@me.com>

    execute handshake after process status moved to open
    
    if nowait is t, `open-network-stream` or `make-network-process`
    function returns without waiting connection opened.
    we need to wait executing handshake process until process status
    changed to `open`.
    we call `websocket-handshake` in sentinel because sentinel function is
    executed when process status changed to `open`.
    
    if nowait is nil, `open-network-stream` or `make-network-process`
    returns after connection opened.
    sentinel function is not executed when process-status changed to
    `open`, we have to call `websocket-handshake` in `websocket-open`.
---
 websocket.el | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/websocket.el b/websocket.el
index 3d83b3a950..01bbe6ea37 100644
--- a/websocket.el
+++ b/websocket.el
@@ -731,11 +731,21 @@ to the websocket protocol.
      (lambda (process change)
        (let ((websocket (process-get process :websocket)))
          (websocket-debug websocket "State change to %s" change)
-         (when (and
-                (member (process-status process) '(closed failed exit signal))
-                (not (eq 'closed (websocket-ready-state websocket))))
-           (websocket-try-callback 'websocket-on-close 'on-close websocket)))))
+         (let ((status (process-status process)))
+           (when (and nowait (eq status 'open))
+             (websocket-handshake url conn key protocols extensions 
custom-header-alist))
+
+           (when (and (member status '(closed failed exit signal))
+                      (not (eq 'closed (websocket-ready-state websocket))))
+             (websocket-try-callback 'websocket-on-close 'on-close 
websocket))))))
     (set-process-query-on-exit-flag conn nil)
+    (unless nowait
+      (websocket-handshake url conn key protocols extensions 
custom-header-alist))
+    websocket))
+
+(defun websocket-handshake (url conn key protocols extensions 
custom-header-alist)
+  (let ((url-struct (url-generic-parse-url url))
+        (websocket (process-get conn :websocket)))
     (process-send-string conn
                          (format "GET %s HTTP/1.1\r\n"
                                  (let ((path (url-filename url-struct)))
@@ -745,8 +755,7 @@ to the websocket protocol.
     (process-send-string conn
                          (websocket-create-headers
                           url key protocols extensions custom-header-alist))
-    (websocket-debug websocket "Websocket opened")
-    websocket))
+    (websocket-debug websocket "Websocket opened")))
 
 (defun websocket-process-headers (url headers)
   "On opening URL, process the HEADERS sent from the server."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]