|
|
@ -9,24 +9,26 @@
|
|
|
|
;; wrappers
|
|
|
|
;; wrappers
|
|
|
|
|
|
|
|
|
|
|
|
(defun bind (file)
|
|
|
|
(defun bind (file)
|
|
|
|
"bind to the AF_UNIX socket `file'"
|
|
|
|
"bind to the AF_UNIX socket `file'
|
|
|
|
"returns the sd on success, nil on failure"
|
|
|
|
returns the sd on success, nil on failure
|
|
|
|
"(remember it has to be deleted first!)"
|
|
|
|
(remember it has to be deleted first!)
|
|
|
|
|
|
|
|
"
|
|
|
|
(let ((rc (si-bind file)))
|
|
|
|
(let ((rc (si-bind file)))
|
|
|
|
(if (< rc 0) ;error
|
|
|
|
(if (< rc 0) ;error
|
|
|
|
nil
|
|
|
|
nil
|
|
|
|
rc)))
|
|
|
|
rc)))
|
|
|
|
|
|
|
|
|
|
|
|
(defun hook (sd on-err on-msg)
|
|
|
|
(defun hook (sd on-err on-msg)
|
|
|
|
"listen on socket `sd'"
|
|
|
|
"listen on socket `sd'
|
|
|
|
"on error call the callback `on-err' with args (error)"
|
|
|
|
on error call the callback `on-err' with args (error)
|
|
|
|
"on message call the callback `on-msg' with args (type message)"
|
|
|
|
on message call the callback `on-msg' with args (type message)
|
|
|
|
"type can be:
|
|
|
|
type can be:
|
|
|
|
:string - a string
|
|
|
|
:string - a string
|
|
|
|
:binary - (TODO) a foreign pointer
|
|
|
|
:binary - (TODO) a foreign pointer
|
|
|
|
:close - a close request"
|
|
|
|
:close - a close request
|
|
|
|
"returns rc on success (1), and nil on failure"
|
|
|
|
returns rc on success (1), and nil on failure
|
|
|
|
"(note: this function blocks until the connection closes)"
|
|
|
|
(note: this function blocks until the connection closes)
|
|
|
|
|
|
|
|
"
|
|
|
|
(let ((*on-message* on-msg)
|
|
|
|
(let ((*on-message* on-msg)
|
|
|
|
(*on-err* on-err))
|
|
|
|
(*on-err* on-err))
|
|
|
|
(let ((rc (si-listen sd (callback si-error-callback) (callback si-callback))))
|
|
|
|
(let ((rc (si-listen sd (callback si-error-callback) (callback si-callback))))
|
|
|
@ -40,9 +42,10 @@
|
|
|
|
t)
|
|
|
|
t)
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro with-bound-socket (desc &body body)
|
|
|
|
(defmacro with-bound-socket (desc &body body)
|
|
|
|
"bind socket, run `body', then close the socket"
|
|
|
|
"bind socket, run `body', then close the socket
|
|
|
|
"example: (with-bound-socket (socket \"file.socket\") (hook socket ...))"
|
|
|
|
example: (with-bound-socket (socket \"file.socket\") (hook socket ...))
|
|
|
|
"returns the last value from body on success, returns NIL without running body if the socket failed to bind"
|
|
|
|
returns the last value from body on success, returns NIL without running body if the socket failed to bind
|
|
|
|
|
|
|
|
"
|
|
|
|
`(let* ((,(first desc) (bind ,(second desc)))
|
|
|
|
`(let* ((,(first desc) (bind ,(second desc)))
|
|
|
|
(return-value
|
|
|
|
(return-value
|
|
|
|
(if (null ,(first desc)) ;;bind failed
|
|
|
|
(if (null ,(first desc)) ;;bind failed
|
|
|
|