imho swank-create-server is much more convient if it returns the port number it has opened. 4 line patch follows.
p.s. - am i the only one actually using create-swank-server?
-- 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
Marco Baringer mb@bese.it writes:
imho swank-create-server is much more convient if it returns the port number it has opened. 4 line patch follows.
[...]
(defun create-swank-server (&optional (port 4005) (background *swank-in-background*))
- (setup-server port #'simple-announce-function background))
- (let ((real-port nil))
- (setup-server port
(lambda (port)
(setf real-port port))
background)
- real-port))
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.
p.s. - am i the only one actually using create-swank-server?
Apparently :-)
Helmut.
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
Marco Baringer mb@bese.it writes:
does this not simply move the problem? now, in order to know what port the server was opened on i have to do:
Yes, your right. I confused the thread that opens the socket with the thread that handles request. create-swank-server returns now the port number.
Helmut.