Commit 858e4b4a authored by Peter Liljenberg's avatar Peter Liljenberg

Keep track of keep-alive timers in a global cons list instead of in a buffer...

Keep track of keep-alive timers in a global cons list instead of in a buffer local variable to be able to shut down the timer if the buffer is killed.
parent ee45a027
...@@ -2369,17 +2369,17 @@ This command accepts text number prefix arguments \(see ...@@ -2369,17 +2369,17 @@ This command accepts text number prefix arguments \(see
(def-kom-var lyskom-keep-alive-timers nil (def-kom-var lyskom-keep-alive-timers nil
"List of all active keep alive timers" "List of all active keep alive timers as (buffer . timer) conses.")
local)
(defun lyskom-keep-alive-callback (buffer) (defun lyskom-keep-alive-callback (buffer)
(condition-case nil (condition-case nil
(save-current-buffer (set-buffer buffer) (save-current-buffer (set-buffer buffer)
(if (eq (process-status lyskom-proc) 'open) (if (eq (process-status lyskom-proc) 'open)
(initiate-get-time 'keep nil) (initiate-get-time 'keep nil)
(lyskom-stop-keep-alive) (lyskom-stop-keep-alive buffer)
(message "Terminating keep-alive"))) (message "Terminating keep-alive")))
(error (message "ERROR!") (lyskom-stop-keep-alive)))) (error (message "Callback error, terminating keep-alive")
(lyskom-stop-keep-alive buffer))))
(def-kom-command kom-keep-alive () (def-kom-command kom-keep-alive ()
"Keep the LysKOM session alive by sending a request every once in a "Keep the LysKOM session alive by sending a request every once in a
...@@ -2391,20 +2391,21 @@ too long. ...@@ -2391,20 +2391,21 @@ too long.
Use `kom-stop-keep-alive' to turn off this mode." Use `kom-stop-keep-alive' to turn off this mode."
(interactive) (interactive)
(set-buffer lyskom-buffer) (set-buffer lyskom-buffer)
(lyskom-stop-keep-alive) (lyskom-stop-keep-alive lyskom-buffer)
(lyskom-keep-alive) (lyskom-keep-alive lyskom-buffer)
(unless (eq (current-buffer) lyskom-buffer) (unless (eq (current-buffer) lyskom-buffer)
(lyskom-message 'start-keep-alive kom-keep-alive-interval)) (lyskom-message 'start-keep-alive kom-keep-alive-interval))
(lyskom-format-insert 'start-keep-alive kom-keep-alive-interval) (lyskom-format-insert 'start-keep-alive kom-keep-alive-interval)
(lyskom-insert "\n")) (lyskom-insert "\n"))
(defun lyskom-keep-alive () (defun lyskom-keep-alive (buffer)
(setq lyskom-keep-alive-timers (setq lyskom-keep-alive-timers
(cons (cons
(add-timeout kom-keep-alive-interval (cons buffer
'lyskom-keep-alive-callback (add-timeout kom-keep-alive-interval
(current-buffer) 'lyskom-keep-alive-callback
kom-keep-alive-interval) (current-buffer)
kom-keep-alive-interval))
lyskom-keep-alive-timers))) lyskom-keep-alive-timers)))
(def-kom-command kom-stop-keep-alive () (def-kom-command kom-stop-keep-alive ()
...@@ -2412,16 +2413,22 @@ Use `kom-stop-keep-alive' to turn off this mode." ...@@ -2412,16 +2413,22 @@ Use `kom-stop-keep-alive' to turn off this mode."
See `kom-keep-alive' for more information." See `kom-keep-alive' for more information."
(interactive) (interactive)
(lyskom-stop-keep-alive) (lyskom-stop-keep-alive lyskom-buffer)
(unless (eq (current-buffer) lyskom-buffer) (unless (eq (current-buffer) lyskom-buffer)
(lyskom-message "%#1s" 'stop-keep-alive)) (lyskom-message "%#1s" 'stop-keep-alive))
(lyskom-insert 'stop-keep-alive) (lyskom-insert 'stop-keep-alive)
(lyskom-insert "\n")) (lyskom-insert "\n"))
(defun lyskom-stop-keep-alive () (defun lyskom-stop-keep-alive (buffer)
(mapc 'disable-timeout lyskom-keep-alive-timers) (let
(setq lyskom-keep-alive-timers nil)) ((c (assq buffer lyskom-keep-alive-timers)))
(if c
(progn
(disable-timeout (cdr c))
(setq lyskom-keep-alive-timers
(delq c lyskom-keep-alive-timers)))
)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment