anchor.diff:  ;;; Hook onto normal hunchentoot processing
   ;;;
   ;;; The `:around' specilization of `process-request' will first call
  -;;; the main hunchentoot one, which will call our
  -;;; `handle-request'. That will in turn try to figure out if the
  -;;; client is requesting websockets, handshake and set
  -;;; `+http-switching-protocols+'. It will also eventually reply to the
  -;;; client, but hopefully keep the stream alive. That happens if:
  +;;; the main hunchentoot one, which eventually call our specialization
  +;;; of `acceptor-dispatch-request'. That will in turn try to figure
  +;;; out if the client is requesting websockets, handshake and set
  +;;; `+http-switching-protocols+'. Hunchentoot's `process-request' will
  +;;; also eventually reply to the client but in the stream is kept
  +;;; alive. That happens if:
   ;;;
   ;;; 1. There are suitable "Connection" and "Upgrade" headers and
   ;;;    `websocket-resource' object is found for request.
  
positive.code: ;;; fail, an error is signalled. 
  
  (defmethod process-request :around ((request websocket-request))
    "First, continue the process with HTTP 101 added to Hunchentoot's
  list of *APPROVED-RETURN-CODES*. If that status code got issued in the
  response after regular processing, hijack the connection and continue
  to process it as a WebSocket one.
  
  PS: I *do* know what I'm doing, Mister!"
    (let ((stream (call-next-method)))
      (prog1 stream
        (when (= +http-switching-protocols+ (return-code*))
          (force-output stream)
          (let ((timeout (websocket-timeout (request-acceptor request))))
            (set-timeouts *websocket-socket* timeout timeout))
          (handler-case
              (let ((*websocket-stream* stream)
                    (*websocket-stream-mutex* (make-lock)))
                (websocket-process-connection
                 stream
                 (funcall (websocket-resource request) stream
                          *websocket-stream-mutex*)))
                                          ; custom handshake
            (end-of-file ()
              (log-message* :debug "WebSocket connection terminated"))
            (websocket-illegal-frame-type (condition)
              (log-message*
               :error "WebSocket illegal frame type 0x~x encountered, terminating"
               (websocket-illegal-frame-type-of condition))))))))
  
  (defun websocket-handle-handshake (request reply)
    "Analyse REQUEST for WebSocket handshake.
  
negative.code:   (dotimes (num number)
      (read-byte stream)))
  
  (defun websocket-loop (stream message-handler
                         &optional (version :rfc-6455))
    "Implements the main WebSocket loop for supported protocol
  versions. Framing is handled automatically, MESSAGE-HANDLER ought to
  handle the actual payloads.
  