FUEL: Improved connection behaviour in presence of fuel loading errors.
							parent
							
								
									7c56b9184e
								
							
						
					
					
						commit
						0e34a6d363
					
				| 
						 | 
					@ -29,10 +29,7 @@
 | 
				
			||||||
(defun fuel-con--get-connection (buffer/proc)
 | 
					(defun fuel-con--get-connection (buffer/proc)
 | 
				
			||||||
  (if (processp buffer/proc)
 | 
					  (if (processp buffer/proc)
 | 
				
			||||||
      (fuel-con--get-connection (process-buffer buffer/proc))
 | 
					      (fuel-con--get-connection (process-buffer buffer/proc))
 | 
				
			||||||
    (with-current-buffer buffer/proc
 | 
					    (with-current-buffer buffer/proc fuel-con--connection)))
 | 
				
			||||||
      (or fuel-con--connection
 | 
					 | 
				
			||||||
          (setq fuel-con--connection
 | 
					 | 
				
			||||||
                (fuel-con--setup-connection buffer/proc))))))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;;; Request and connection datatypes:
 | 
					;;; Request and connection datatypes:
 | 
				
			||||||
| 
						 | 
					@ -126,19 +123,20 @@
 | 
				
			||||||
(defun fuel-con--setup-connection (buffer)
 | 
					(defun fuel-con--setup-connection (buffer)
 | 
				
			||||||
  (set-buffer buffer)
 | 
					  (set-buffer buffer)
 | 
				
			||||||
  (fuel-con--cleanup-connection fuel-con--connection)
 | 
					  (fuel-con--cleanup-connection fuel-con--connection)
 | 
				
			||||||
 | 
					  (setq fuel-con--connection nil)
 | 
				
			||||||
  (let ((conn (fuel-con--make-connection buffer)))
 | 
					  (let ((conn (fuel-con--make-connection buffer)))
 | 
				
			||||||
    (fuel-con--setup-comint)
 | 
					    (fuel-con--setup-comint)
 | 
				
			||||||
    (prog1
 | 
					    (fuel-con--establish-connection conn buffer)))
 | 
				
			||||||
        (setq fuel-con--connection conn)
 | 
					 | 
				
			||||||
      (fuel-con--connection-start-timer conn))))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defconst fuel-con--prompt-regex "( .+ ) ")
 | 
					(defconst fuel-con--prompt-regex "( .+ ) ")
 | 
				
			||||||
(defconst fuel-con--eot-marker "<~FUEL~>")
 | 
					(defconst fuel-con--eot-marker "<~FUEL~>")
 | 
				
			||||||
(defconst fuel-con--init-stanza "USE: fuel fuel-retort")
 | 
					(defconst fuel-con--init-stanza "USE: fuel fuel-retort")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defconst fuel-con--comint-finished-regex
 | 
					(defconst fuel-con--comint-finished-regex-connected
 | 
				
			||||||
  (format "^%s$" fuel-con--eot-marker))
 | 
					  (format "^%s$" fuel-con--eot-marker))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defvar fuel-con--comint-finished-regex fuel-con--prompt-regex)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun fuel-con--setup-comint ()
 | 
					(defun fuel-con--setup-comint ()
 | 
				
			||||||
  (set (make-local-variable 'comint-redirect-insert-matching-regexp) t)
 | 
					  (set (make-local-variable 'comint-redirect-insert-matching-regexp) t)
 | 
				
			||||||
  (add-hook 'comint-redirect-filter-functions
 | 
					  (add-hook 'comint-redirect-filter-functions
 | 
				
			||||||
| 
						 | 
					@ -154,17 +152,43 @@
 | 
				
			||||||
    (setq comint-redirect-finished-regexp fuel-con--prompt-regex))
 | 
					    (setq comint-redirect-finished-regexp fuel-con--prompt-regex))
 | 
				
			||||||
  str)
 | 
					  str)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defun fuel-con--establish-connection (conn buffer)
 | 
				
			||||||
 | 
					  (with-current-buffer (fuel-con--comint-buffer) (erase-buffer))
 | 
				
			||||||
 | 
					  (with-current-buffer buffer
 | 
				
			||||||
 | 
					    (setq fuel-con--connection conn)
 | 
				
			||||||
 | 
					    (setq fuel-con--comint-finished-regex fuel-con--prompt-regex)
 | 
				
			||||||
 | 
					    (fuel-con--send-string/wait buffer
 | 
				
			||||||
 | 
					                                fuel-con--init-stanza
 | 
				
			||||||
 | 
					                                'fuel-con--establish-connection-cont
 | 
				
			||||||
 | 
					                                20000)
 | 
				
			||||||
 | 
					    conn))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(defun fuel-con--establish-connection-cont (ignore)
 | 
				
			||||||
 | 
					  (let ((str (with-current-buffer (fuel-con--comint-buffer) (buffer-string))))
 | 
				
			||||||
 | 
					    (if (string-match fuel-con--eot-marker str)
 | 
				
			||||||
 | 
					        (progn
 | 
				
			||||||
 | 
					          (setq fuel-con--comint-finished-regex
 | 
				
			||||||
 | 
					                fuel-con--comint-finished-regex-connected)
 | 
				
			||||||
 | 
					          (fuel-con--connection-start-timer conn)
 | 
				
			||||||
 | 
					          (message "FUEL listener up and running!"))
 | 
				
			||||||
 | 
					      (fuel-con--connection-clean-current-request fuel-con--connection)
 | 
				
			||||||
 | 
					      (setq fuel-con--connection nil)
 | 
				
			||||||
 | 
					      (message "An error occurred initialising FUEL's Factor library!")
 | 
				
			||||||
 | 
					      (pop-to-buffer (fuel-con--comint-buffer)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;;; Requests handling:
 | 
					;;; Requests handling:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defsubst fuel-con--comint-buffer ()
 | 
					(defsubst fuel-con--comint-buffer ()
 | 
				
			||||||
  (get-buffer-create " *fuel connection retort*"))
 | 
					  (get-buffer-create " *fuel connection retort*"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defsubst fuel-con--comint-buffer-form ()
 | 
					(defun fuel-con--comint-buffer-form ()
 | 
				
			||||||
  (with-current-buffer (fuel-con--comint-buffer)
 | 
					  (with-current-buffer (fuel-con--comint-buffer)
 | 
				
			||||||
    (goto-char (point-min))
 | 
					    (goto-char (point-min))
 | 
				
			||||||
    (condition-case nil
 | 
					    (condition-case nil
 | 
				
			||||||
        (read (current-buffer))
 | 
					        (let ((form (read (current-buffer))))
 | 
				
			||||||
 | 
					          (if (listp form) form
 | 
				
			||||||
 | 
					            (list 'fuel-con-error (buffer-string))))
 | 
				
			||||||
      (error (list 'fuel-con-error (buffer-string))))))
 | 
					      (error (list 'fuel-con-error (buffer-string))))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun fuel-con--process-next (con)
 | 
					(defun fuel-con--process-next (con)
 | 
				
			||||||
| 
						 | 
					@ -212,7 +236,7 @@
 | 
				
			||||||
  (save-current-buffer
 | 
					  (save-current-buffer
 | 
				
			||||||
    (let ((con (fuel-con--get-connection buffer/proc)))
 | 
					    (let ((con (fuel-con--get-connection buffer/proc)))
 | 
				
			||||||
      (unless con
 | 
					      (unless con
 | 
				
			||||||
        (error "FUEL: couldn't find connection"))
 | 
					        (error "FUEL: no connection"))
 | 
				
			||||||
      (let ((req (fuel-con--make-request str cont sender-buffer)))
 | 
					      (let ((req (fuel-con--make-request str cont sender-buffer)))
 | 
				
			||||||
        (fuel-con--connection-queue-request con req)
 | 
					        (fuel-con--connection-queue-request con req)
 | 
				
			||||||
        (fuel-con--process-next con)
 | 
					        (fuel-con--process-next con)
 | 
				
			||||||
| 
						 | 
					@ -223,22 +247,24 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun fuel-con--send-string/wait (buffer/proc str cont &optional timeout sbuf)
 | 
					(defun fuel-con--send-string/wait (buffer/proc str cont &optional timeout sbuf)
 | 
				
			||||||
  (save-current-buffer
 | 
					  (save-current-buffer
 | 
				
			||||||
    (let* ((con (fuel-con--get-connection buffer/proc))
 | 
					    (let ((con (fuel-con--get-connection buffer/proc)))
 | 
				
			||||||
           (req (fuel-con--send-string buffer/proc str cont sbuf))
 | 
					      (unless con
 | 
				
			||||||
           (id (and req (fuel-con--request-id req)))
 | 
					        (error "FUEL: no connection"))
 | 
				
			||||||
           (time (or timeout fuel-connection-timeout))
 | 
					      (let* ((req (fuel-con--send-string buffer/proc str cont sbuf))
 | 
				
			||||||
           (step 100)
 | 
					             (id (and req (fuel-con--request-id req)))
 | 
				
			||||||
           (waitsecs (/ step 1000.0)))
 | 
					             (time (or timeout fuel-connection-timeout))
 | 
				
			||||||
      (when id
 | 
					             (step 100)
 | 
				
			||||||
        (condition-case nil
 | 
					             (waitsecs (/ step 1000.0)))
 | 
				
			||||||
            (while (and (> time 0)
 | 
					        (when id
 | 
				
			||||||
                        (not (fuel-con--connection-completed-p con id)))
 | 
					          (condition-case nil
 | 
				
			||||||
              (accept-process-output nil waitsecs)
 | 
					              (while (and (> time 0)
 | 
				
			||||||
              (setq time (- time step)))
 | 
					                          (not (fuel-con--connection-completed-p con id)))
 | 
				
			||||||
          (error (setq time 0)))
 | 
					                (accept-process-output nil waitsecs)
 | 
				
			||||||
        (or (> time 0)
 | 
					                (setq time (- time step)))
 | 
				
			||||||
            (fuel-con--request-deactivate req)
 | 
					            (error (setq time 0)))
 | 
				
			||||||
            nil)))))
 | 
					          (or (> time 0)
 | 
				
			||||||
 | 
					              (fuel-con--request-deactivate req)
 | 
				
			||||||
 | 
					              nil))))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(provide 'fuel-connection)
 | 
					(provide 'fuel-connection)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,11 +78,7 @@ buffer."
 | 
				
			||||||
    (make-comint-in-buffer "fuel listener" (current-buffer) factor nil
 | 
					    (make-comint-in-buffer "fuel listener" (current-buffer) factor nil
 | 
				
			||||||
                           "-run=listener" (format "-i=%s" image))
 | 
					                           "-run=listener" (format "-i=%s" image))
 | 
				
			||||||
    (fuel-listener--wait-for-prompt 10000)
 | 
					    (fuel-listener--wait-for-prompt 10000)
 | 
				
			||||||
    (fuel-con--setup-connection (current-buffer))
 | 
					    (fuel-con--setup-connection (current-buffer))))
 | 
				
			||||||
    (fuel-con--send-string/wait (current-buffer)
 | 
					 | 
				
			||||||
                                fuel-con--init-stanza
 | 
					 | 
				
			||||||
                                '(lambda (s) (message "FUEL listener up and running!"))
 | 
					 | 
				
			||||||
                                20000)))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun fuel-listener--process (&optional start)
 | 
					(defun fuel-listener--process (&optional start)
 | 
				
			||||||
  (or (and (buffer-live-p (fuel-listener--buffer))
 | 
					  (or (and (buffer-live-p (fuel-listener--buffer))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue