From d0589bf0bed29e08c87bc4f4da7b217d524f199a Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 8 Nov 2015 17:37:34 -0500 Subject: server: Allow handler to ignore messages. --- web/socket/server.scm | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'web/socket') diff --git a/web/socket/server.scm b/web/socket/server.scm index b7d541c..b8c34dc 100644 --- a/web/socket/server.scm +++ b/web/socket/server.scm @@ -56,15 +56,19 @@ string." handshake and listening for control and data frames. HANDLER is called for each complete message that is received." (define (handle-data-frame type data) - (let ((result (handler (match type - ('text (utf8->string data)) - ('binary data))))) - (write-frame (cond - ((string? result) - (make-text-frame result)) - ((bytevector? result) - (make-binary-frame result))) - client-socket))) + (let* ((result (handler (match type + ('text (utf8->string data)) + ('binary data)))) + (response (cond + ((string? result) + (make-text-frame result)) + ((bytevector? result) + (make-binary-frame result)) + ((not result) + #f)))) + + (when response + (write-frame response client-socket)))) ;; Perform the HTTP handshake and upgrade to WebSocket protocol. (let* ((request (read-handshake-request client-socket)) -- cgit v1.2.3