[slime-devel] swank-create-server (round II)

Marco Baringer mb at bese.it
Wed Jan 21 08:17:22 UTC 2004


On Mercoledì, gen 21, 2004, at 01:03 Europe/Rome, Helmut Eller wrote:

> There is a race condition if the server is executed in a separate
> thread.  I added an announce-fn argument, until we know how to best
> handle this situation.

does this not simply move the problem? now, in order to know what port 
the server was opened on i have to do:

(let ((port nil))
   (swank:create-swank-server 0 (lambda (p) (setf port p))))

haven't i now introduced a race condition in my code? to be honest i 
don't truly understand the issues, so here's my attempt, comments 
welcome.

(defun start-server (port-file)
   (announce-server-port port-file
                         (setup-server 0 *swank-in-background*)))

(defun create-swank-server (&optional (port 4005)
                             (background *swank-in-background*))
   (setup-server port background))

(defun setup-server (port background)
   (setq *write-lock* (make-lock :name "Swank write lock"))
   (let ((socket (create-socket port)))
     (prog1 (local-port socket)
       (if (eq *swank-in-background* :spawn)
           (spawn (lambda () (open-swank-connection socket nil))
                  :name "Swank")
           (open-swank-connection socket background)))))

(defun open-swank-connection (socket background)
   (let ((client (accept-connection socket)))
     (close-socket socket)
     (let ((connection (create-connection client)))
       (init-main-connection connection)
       (serve-requests client connection background))))

--
Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen





More information about the slime-devel mailing list