branch: externals/websocket
commit de26889637d3551c3024b7fe05e2c7b35f0d6d4b
Merge: e9d148fbb6 607355db44
Author: Andrew Hyatt <ahy...@gmail.com>
Commit: GitHub <nore...@github.com>

    Merge pull request #53 from yuya373/fix-for-emacs-25
    
    Ensure handshake is performed when nowait is not supported.
---
 websocket.el | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/websocket.el b/websocket.el
index b7d62f45de..77d787c9eb 100644
--- a/websocket.el
+++ b/websocket.el
@@ -730,8 +730,7 @@ to the websocket protocol.
      conn
      (websocket-sentinel url conn key protocols extensions custom-header-alist 
nowait))
     (set-process-query-on-exit-flag conn nil)
-    (unless nowait
-      (websocket-handshake url conn key protocols extensions 
custom-header-alist))
+    (websocket-ensure-handshake url conn key protocols extensions 
custom-header-alist)
     websocket))
 
 (defun websocket-sentinel (url conn key protocols extensions 
custom-header-alist nowait)
@@ -740,25 +739,26 @@ to the websocket protocol.
         (websocket-debug websocket "State change to %s" change)
         (let ((status (process-status process)))
           (when (and nowait (eq status 'open))
-            (websocket-handshake url conn key protocols extensions 
custom-header-alist))
+            (websocket-ensure-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))))))
 
-(defun websocket-handshake (url conn key protocols extensions 
custom-header-alist)
+(defun websocket-ensure-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)))
-                                   (if (> (length path) 0) path "/"))))
-    (websocket-debug websocket "Sending handshake, key: %s, acceptance: %s"
-                     key (websocket-accept-string websocket))
-    (process-send-string conn
-                         (websocket-create-headers
-                          url key protocols extensions custom-header-alist))
-    (websocket-debug websocket "Websocket opened")))
+    (when (and (eq 'connecting (websocket-ready-state websocket))
+               (eq 'open (process-status conn)))
+      (process-send-string conn
+                           (format "GET %s HTTP/1.1\r\n"
+                                   (let ((path (url-filename url-struct)))
+                                     (if (> (length path) 0) path "/"))))
+      (websocket-debug websocket "Sending handshake, key: %s, acceptance: %s"
+                       key (websocket-accept-string websocket))
+      (process-send-string conn
+                           (websocket-create-headers
+                            url key protocols extensions 
custom-header-alist)))))
 
 (defun websocket-process-headers (url headers)
   "On opening URL, process the HEADERS sent from the server."

Reply via email to