Merge pull request #401 from mmontone/extensible-handle-message

Extensible handle-message
This commit is contained in:
David Botton 2024-12-18 10:57:00 -05:00 committed by GitHub
commit 5fcf8c7e06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -89,11 +89,20 @@
;; handle-message ;;
;;;;;;;;;;;;;;;;;;;;
(defvar *message-handlers* '()
"List of message handling functions.
Each entry in the list should be a FUNCTION-DESIGNATOR that will receive
a splitted message and a connection id and should return something
other than NIL iff it handled the message.")
(defun handle-message (connection message)
"Handle incoming websocket MESSAGE on CONNECTION. (Private)"
(handler-case
(let ((connection-id (gethash connection *connections*))
(ml (ppcre:split ":" message :limit 2)))
(dolist (message-handler *message-handlers*)
(when (funcall message-handler ml connection-id)
(return-from handle-message)))
(cond ((null connection-id)
;; a zombie connection
(when *verbose-output*