Function: jsonrpc-connection-receive
jsonrpc-connection-receive is a byte-compiled function defined in
jsonrpc.el.gz.
Signature
(jsonrpc-connection-receive CONNECTION MESSAGE)
Documentation
Process MESSAGE just received from CONNECTION.
This function will destructure MESSAGE and call the appropriate dispatcher in CONNECTION.
Source Code
;; Defined in /usr/src/emacs/lisp/jsonrpc.el.gz
(defun jsonrpc-connection-receive (connection message)
"Process MESSAGE just received from CONNECTION.
This function will destructure MESSAGE and call the appropriate
dispatcher in CONNECTION."
(cl-destructuring-bind (&key method id error params result _jsonrpc)
message
(let (continuations)
(jsonrpc--log-event connection message 'server)
(setf (jsonrpc-last-error connection) error)
(cond
(;; A remote request
(and method id)
(let* ((debug-on-error (and debug-on-error (not (ert-running-test))))
(reply
(condition-case-unless-debug _ignore
(condition-case oops
`(:result ,(funcall (jsonrpc--request-dispatcher connection)
connection (intern method) params))
(jsonrpc-error
`(:error
(:code
,(or (alist-get 'jsonrpc-error-code (cdr oops)) -32603)
:message ,(or (alist-get 'jsonrpc-error-message
(cdr oops))
"Internal error")))))
(error
'(:error (:code -32603 :message "Internal error"))))))
(apply #'jsonrpc--reply connection id reply)))
(;; A remote notification
method
(funcall (jsonrpc--notification-dispatcher connection)
connection (intern method) params))
(;; A remote response
(setq continuations
(and id (gethash id (jsonrpc--request-continuations connection))))
(let ((timer (nth 2 continuations)))
(when timer (cancel-timer timer)))
(remhash id (jsonrpc--request-continuations connection))
(if error (funcall (nth 1 continuations) error)
(funcall (nth 0 continuations) result))))
(jsonrpc--call-deferred connection))))