branch: externals/websocket
commit e9d148fbb6425c35dc7f76cccdec70aba7fafacf
Merge: 7d2adf2187 b3a0153c0b
Author: Andrew Hyatt <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #52 from yuya373/fix-nowait
execute handshake after connection opened
---
websocket.el | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/websocket.el b/websocket.el
index 3d83b3a950..b7d62f45de 100644
--- a/websocket.el
+++ b/websocket.el
@@ -728,14 +728,27 @@ to the websocket protocol.
(websocket-outer-filter websocket output))))
(set-process-sentinel
conn
- (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)))))
+ (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))
+
+(defun websocket-sentinel (url conn key protocols extensions
custom-header-alist nowait)
+ #'(lambda (process change)
+ (let ((websocket (process-get process :websocket)))
+ (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))
+
+ (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)
+ (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 +758,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."