Adding forgotten file
[lambdamundo.git] / repl.lisp
blob1bb1b37847a17ed5a44aa0202ceda0a32fd558e3
2 (in-package :lambdamundo)
4 ;; (unless (find-package :swank)
5 ;; (swank-loader:init))
8 (defparameter *swank-port* nil)
9 (defparameter *service-slime* t)
11 (in-package :swank)
13 (defun start-session (port)
14 "starts a swank session and returns "
15 (let* ((announce-fn #'simple-announce-function)
16 (external-format (find-external-format-or-lose *coding-system*))
17 (socket (create-socket *loopback-interface* port))
18 (local-port (local-port socket)))
19 (declare (type function announce-fn))
20 (funcall announce-fn local-port)
21 (format *debug-io* "Swank on port ~A " local-port)
22 (initialize-multiprocessing
23 (lambda ()
24 (spawn (lambda ()
25 (loop do
26 (ignore-errors
27 (serve-connection socket :spawn t external-format))
28 while lambdamundo::*service-slime*))
29 :name
30 (concatenate 'string "Swank "
31 (princ-to-string port)))))
32 (setf (getf *listener-sockets* port) (list :sigio socket))
33 local-port))
35 (defun end-session (port)
36 "Stop server running on PORT. Equivalent to swank::stop-server"
37 (let* ((socket-description (getf *listener-sockets* port))
38 (socket (second socket-description)))
39 (let ((thread-position
40 (position-if
41 (lambda (x)
42 (string-equal (second x)
43 (concatenate 'string "Swank "
44 (princ-to-string port))))
45 (list-threads))))
46 (when thread-position
47 (kill-nth-thread thread-position)
48 (close-socket socket)
49 (remf *listener-sockets* port)))))