summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2016-03-25 09:14:08 -0400
committerDavid Thompson <dthompson2@worcester.edu>2016-03-25 09:14:08 -0400
commit35607c9800d99544f92966250bbdbb7a18e464d4 (patch)
treeb77f72a46433189bc146a0032e8f976556c83b28 /web
parentbb002f95851befc2d5830294685b526703923e99 (diff)
client: Wait for server to close connection.
* web/socket/client.scm (close-websocket): Wait for server to close the connection for a reasonable amount of time.
Diffstat (limited to 'web')
-rw-r--r--web/socket/client.scm13
1 files changed, 12 insertions, 1 deletions
diff --git a/web/socket/client.scm b/web/socket/client.scm
index d144890..7be9c2c 100644
--- a/web/socket/client.scm
+++ b/web/socket/client.scm
@@ -26,6 +26,7 @@
(define-module (web socket client)
#:use-module (ice-9 match)
#:use-module (rnrs bytevectors)
+ #:use-module (rnrs io ports)
#:use-module (srfi srfi-9)
#:use-module (web request)
#:use-module (web response)
@@ -124,7 +125,17 @@ resource described by URI-OR-STRING."
(define (close-websocket ws)
"Close the WebSocket connection for the client WS."
- (close-port (websocket-socket ws)))
+ (let ((socket (websocket-socket ws)))
+ (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.
+ (let loop ()
+ (match (select #() (vector socket) #() 1) ; 1 second timeout
+ ((#() #(socket) #()) ; there is output to read
+ (unless (port-eof? socket)
+ (read-frame socket) ; throw it away
+ (loop)))))
+ (close-port socket)))
(define (websocket-send ws data)
"Send DATA, a string or bytevector, to the server that WS is