Skip to content

Commit

Permalink
Extensible handle-message
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontone committed Dec 18, 2024
1 parent 961b87f commit 3b27576
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions source/clog-connection-websockets.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down

0 comments on commit 3b27576

Please sign in to comment.