anchor.diff:                                        (maybe-invoke-debugger e)
                                         (log-message* :error "Websocket error: ~a" e)
                                         (throw 'websocket-done nil))))
  -              (websocket-loop stream client))))))))
  +              (websocket-loop resource stream client))))))))
   
   (defun websocket-handle-handshake (request reply)
     "Analyse REQUEST for WebSocket handshake.
  
positive.code:                                           ,resource
                                            #'(lambda () ,@body)))))
  
  
  
  ;;; Binary reading machinery
  ;;;
  
  (defun read-bytes-array (stream number)
    "Read NUMBER bytes from Chunga STREAM into array and return it."
    (let ((result (make-array number :element-type '(unsigned-byte 8))))
      (dotimes (index number result)
        (setf (aref result index)
              (char-int (read-char* stream t))))))
  
  (defun read-key3 (request)
    "Read eight bytes from REQUEST's content stream and return them as a byte
  array."
    (read-bytes-array (content-stream request) 8))
  
  (defun digest-key (key)
    "Evaluates to MD5 digest of KEY sequence."
    (digest-sequence :md5 key))
  
  (defun websocket-uri (request host &optional ssl)
    "Form WebSocket URL (ws:// or wss://) URL."
    (format nil "~:[ws~;wss~]://~a~a" ssl host (script-name request)))
  
  (defun skip-bytes (stream number)
    "Read and discard NUMBER bytes from STREAM."
    (dotimes (num number)
      (read-byte stream)))
  
  (defun send-message (message client)
    "Encode MESSAGE as UTF-8 bytes and send it across STREAM in a proper frame."
    (with-slots (stream lock) client
      (when (> (length message) 0) ; empty message would send terminator
        (log-message* :debug "Going to send websocket message ~a" message)
        (with-lock-held (lock)
          (write-byte #x00 stream)
          (write-utf-8-bytes message stream)
          (write-byte #xff stream)
          (force-output stream)))))
  
  
  ;;; Main websocket loop
  ;;; 
  (defun websocket-loop (stream client
                         &optional (version :rfc-6455))
    "Implements the main WebSocket loop for supported protocol
  versions. Framing is handled automatically, CLIENT handles the actual
  payloads."
    (declare (ignore stream client))
    (ecase version
      (:rfc-6455
       (hunchentoot-error "Not implemented yet!"))))
  
  
  ;;; Hook onto normal hunchentoot processing
  ;;;
  ;;; The `:around' specilization of `process-request' will first call
  ;;; 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.
  ;;; 2. The websocket handshake completes sucessfully
  ;;; 
  ;;; If 1 fails, normal hunchentoot processing is resumed. If 2 or 3
  ;;; fail, an error is signalled.
  
  (defmethod process-connection :around ((*acceptor* websocket-acceptor)
                                         (socket t))
  
negative.code:   (let ((*websocket-socket* socket))
      (call-next-method)))
  
  (defmethod process-request :after ((request websocket-request))
    "After HTTP processing REQUEST, maybe hijack into WebSocket loop."
    (let ((stream (content-stream request)))
      (when (= +http-switching-protocols+ (return-code*))
        (force-output stream)
  