summaryrefslogtreecommitdiff
path: root/web/socket/client.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2024-06-05 07:44:52 -0400
committerDavid Thompson <dthompson2@worcester.edu>2024-06-05 07:44:52 -0400
commit795dd67dee3dc3f5fa791a20d4b51cc4e811b5d6 (patch)
treeca0ee7b09593a0384281107cf7d2cda178708a8b /web/socket/client.scm
parent438d87675d9ef18695475685ff36ff75a5506466 (diff)
Remove timeout handling that is incompatible with suspendable ports.HEADmaster
Timeouts should be handled by a concurrency layer such as fibers.
Diffstat (limited to 'web/socket/client.scm')
-rw-r--r--web/socket/client.scm34
1 files changed, 22 insertions, 12 deletions
diff --git a/web/socket/client.scm b/web/socket/client.scm
index 966e3f7..d3a9cb8 100644
--- a/web/socket/client.scm
+++ b/web/socket/client.scm
@@ -183,15 +183,16 @@ true, verify HTTPS server certificates."
ws)
(error "not a websocket uri" uri))))
-(define* (close-websocket ws #:key (timeout 1))
- "Close the WebSocket connection for the client WS, waiting up to
-TIMEOUT seconds (default 1 second) for a graceful shutdown."
+(define (close-websocket ws)
+ "Close the WebSocket connection for the client WS."
(let ((socket (websocket-socket ws)))
(set-websocket-state! ws 'closing)
(write-frame (make-close-frame (make-bytevector 0)) socket)
- ;; Per section 5.5.1 , wait for the server to close the connection
- ;; for a reasonable amount of time.
- (read-close-frame socket #:timeout timeout)
+ ;; Per section 5.5.1, wait for the server to close the connection.
+ (let loop ()
+ (match (read-frame socket)
+ ((or #f (? close-frame?)) (values))
+ (_ (loop))))
(close-port socket)
(close-port (websocket-entropy-port ws))
(set-websocket-state! ws 'closed)
@@ -209,20 +210,29 @@ connected to."
(write-frame (make-text-frame data (generate-masking-key ws))
(websocket-socket ws)))
-(define* (websocket-receive ws #:key timeout)
+;; TODO: Close frames should be echoed back if the server initiated
+;; the disconnect.
+;;
+;; Per section 5.5.1:
+;;
+;; If an endpoint receives a Close frame and did not previously send a
+;; Close frame, the endpoint MUST send a Close frame in response.
+;; (When sending a Close frame in response, the endpoint typically
+;; echos the status code it received.) It SHOULD do so as soon as
+;; practical.
+(define (websocket-receive ws)
"Read data from the server that WS is connected to. Returns a string
if text data was received, a bytevector if binary data was received, a
-pair of (code . reason) if the WebSocket was closed, or #f if TIMEOUT
-seconds elapsed without receiving a data frame."
+pair of (code . reason) if the WebSocket was closed."
(let ((socket (websocket-socket ws)))
- ;; For server initiated disconnects and timeouts.
+ ;; For server initiated disconnects.
(define (maybe-close)
(when (port-closed? socket)
;; EOF - clean up the websocket.
(close-port (websocket-entropy-port ws))
(set-websocket-state! ws 'closed)))
- (match (read-data-frame socket #:timeout timeout)
- (#f ; timeout
+ (match (read-data-frame socket)
+ (#f ; EOF or socket closed.
(maybe-close)
#f)
((? close-frame? frame)