branch: externals/websocket
commit 38c1f20cb3f98a281bc2673c42a39d6bb0344959
Author: Yuya Minami <[email protected]>
Commit: Yuya Minami <[email protected]>
ensure handshake called once
after handshake successed, websocket's ready-state is open
prevent handshake is executed when process status is connect
---
websocket.el | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/websocket.el b/websocket.el
index a3e903515c..b449b5b19a 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)
- (when (eq 'open (process-status conn))
- (websocket-handshake url conn key protocols extensions
custom-header-alist))
+ (websocket-handshake url conn key protocols extensions custom-header-alist)
websocket))
(defun websocket-sentinel (url conn key protocols extensions
custom-header-alist nowait)
@@ -749,16 +748,17 @@ to the websocket protocol.
(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)))
- (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."