summaryrefslogtreecommitdiff
path: root/web/socket/client.scm
diff options
context:
space:
mode:
Diffstat (limited to 'web/socket/client.scm')
-rw-r--r--web/socket/client.scm19
1 files changed, 13 insertions, 6 deletions
diff --git a/web/socket/client.scm b/web/socket/client.scm
index 6561c26..c867427 100644
--- a/web/socket/client.scm
+++ b/web/socket/client.scm
@@ -214,9 +214,16 @@ connected to."
(websocket-socket ws)))
(define (websocket-receive ws)
- "Read a response from the server that WS is connected to."
- ;; TODO: Handle fragmented frames and control frames.
- (let ((frame (read-frame (websocket-socket ws))))
- (if (binary-frame? frame)
- (frame-data frame)
- (text-frame->string frame))))
+ "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,
+or #f if the WebSocket connection was closed."
+ (let ((frame (read-data-frame (websocket-socket ws))))
+ (cond ((not frame)
+ (close-port (websocket-socket ws))
+ (close-port (websocket-entropy-port ws))
+ (set-websocket-state! ws 'closed)
+ #f)
+ ((binary-frame? frame)
+ (frame-data frame))
+ (else
+ (text-frame->string frame)))))