X-Git-Url: http://git.pond.sub.org/?p=eow;a=blobdiff_plain;f=web.lisp;h=127a87ecc7bb61716f5e454b96ad946b7efa1bf7;hp=68870b9571e2556f8d32e0a7cf48a2817d0ed1bd;hb=54e14006564ff34c8249b9ddb357201759d77101;hpb=827392a0b542ef62612e0e32b03a1ca4df21b2e2 diff --git a/web.lisp b/web.lisp index 68870b9..127a87e 100644 --- a/web.lisp +++ b/web.lisp @@ -68,13 +68,21 @@ (defun update () "Send stream of updates to client" (with-session - (when (update-thread *empire-session*) - (empire-log:info "~a: Killing update thread ~a." *empire-session* (update-thread *empire-session*)) - (sb-thread:terminate-thread (update-thread *empire-session*))) + ; kill previous update thread + (when (update-thread *empire-session*) + (empire-log:info "~a: Killing update thread ~a." + *empire-session* (update-thread *empire-session*)) + (sb-thread:terminate-thread (update-thread *empire-session*))) + + ; make current thread the update thread (setf (update-thread *empire-session*) sb-thread:*current-thread*) - (let ((next-update (locked-queue:dequeue (update-queue *empire-session*)))) + + (let ((next-updates (locked-queue:dequeue-all (update-queue *empire-session*)))) + ; There's a race here. The next update thread might kill this one before + ; sending the reply. (setf (update-thread *empire-session*) nil) - next-update))) + (nconc next-updates (list (parenscript:ps* '(next)))) + (apply #'concatenate 'string next-updates)))) (defmethod send ((s session) string) "Push a javascript update fragment to the client." @@ -107,16 +115,21 @@ (with-session (hunchentoot:handle-static-file (concatenate 'string +static-files-root+ +root-page-file+)))) +(defun my-request-p (script-name) + (string-starts-with script-name +web-root+)) + (defun dispatch (request) (let ((script-name (hunchentoot:script-name request))) (cond - ((not (string-starts-with script-name +web-root+)) nil) ; do not handle this request + ((not (my-request-p script-name)) nil) ; do not handle this request ((string= script-name "/eow/update") 'update) ((string= script-name "/eow/login") 'login-action) ((string= script-name "/eow/command") 'command-action) + ; go to the start page ((or (string-equal script-name +web-root-base+) - (string-equal script-name +web-root+)) 'root-page) ; go to the start page - ((string-starts-with script-name +static-web-root+) 'serve-static)))) ; serve static file + (string-equal script-name +web-root+)) 'root-page) + ; serve static file + ((string-starts-with script-name +static-web-root+) 'serve-static)))) (defun start ()