Skip to content
This repository
Browse code

Ensure that a sentinel for a valid proces is invoked.

* twittering-mode.el: Ensure that a sentinel is invoked when a
process is started successfully.
(twittering-start-process-with-sentinel): new function.
(twittering-send-http-request-native): ensure that the given
sentinel is invoked when the process is started successfully.
(twittering-send-http-request-curl): replace `start-process' with
`twittering-start-process-with-sentinel' in order to ensure that
the sentinel is invoked.
(twittering-send-http-request-wget): likewise.
  • Loading branch information...
commit 05d5192caba1da4f34a2f11f418c1b9facb04909 1 parent 2a9aad6
Tadashi MATSUO cvmat authored

Showing 2 changed files with 43 additions and 13 deletions. Show diff stats Hide diff stats

  1. +13 0 ChangeLog
  2. +30 13 twittering-mode.el
13 ChangeLog
... ... @@ -1,3 +1,16 @@
  1 +2011-05-16 Tadashi MATSUO <tad@mymail.twin.jp>
  2 +
  3 + * twittering-mode.el: Ensure that a sentinel is invoked when a
  4 + process is started successfully.
  5 + (twittering-process-alive-p): new function.
  6 + (twittering-start-process-with-sentinel): new function.
  7 + (twittering-send-http-request-native): ensure that the given
  8 + sentinel is invoked when the process is started successfully.
  9 + (twittering-send-http-request-curl): replace `start-process' with
  10 + `twittering-start-process-with-sentinel' in order to ensure that
  11 + the sentinel is invoked.
  12 + (twittering-send-http-request-wget): likewise.
  13 +
1 14 2011-05-08 Tadashi MATSUO <tad@mymail.twin.jp>
2 15
3 16 * test/test-twittering-mode.el: Fix and add tests of proxy
43 twittering-mode.el
@@ -525,6 +525,24 @@ StatusNet Service.")
525 525 (setq pos (match-end 0)))
526 526 (reverse result)))
527 527
  528 +(defun twittering-process-alive-p (proc)
  529 + "Return non-nil if PROC is alive."
  530 + (not (memq (process-status proc) '(nil closed exit failed signal))))
  531 +
  532 +(defun twittering-start-process-with-sentinel (name buffer program args sentinel)
  533 + "Start a program in a subprocess with a sentinel.
  534 +
  535 +This function is the same as `start-process' except that SENTINEL must
  536 +be invoked when the process is successfully started."
  537 + (let ((proc (apply 'start-process name buffer program args)))
  538 + (when (and proc (functionp sentinel))
  539 + (if (twittering-process-alive-p proc)
  540 + (set-process-sentinel proc sentinel)
  541 + ;; Ensure that the sentinel is invoked if a subprocess is
  542 + ;; successfully started.
  543 + (funcall sentinel proc "finished")))
  544 + proc))
  545 +
528 546 ;;;;
529 547 ;;;; Utility for portability
530 548 ;;;;
@@ -1489,7 +1507,10 @@ The method to perform the request is determined from
1489 1507 nil connect-host connect-port)))
1490 1508 (when proc
1491 1509 (set-process-buffer proc buffer)
1492   - (set-process-sentinel proc sentinel)
  1510 + (when (functionp sentinel)
  1511 + (if (twittering-process-alive-p proc)
  1512 + (set-process-sentinel proc sentinel)
  1513 + (funcall sentinel proc "finished")))
1493 1514 (process-send-string proc request-str)
1494 1515 proc)))
1495 1516
@@ -1631,12 +1652,10 @@ The method to perform the request is determined from
1631 1652 ;; file if you use Emacs on Cygwin.
1632 1653 (if use-ssl
1633 1654 cacert-dir
1634   - default-directory))
1635   - (proc (apply 'start-process name buffer
1636   - twittering-curl-program curl-args)))
1637   - (when (and proc (functionp sentinel))
1638   - (set-process-sentinel proc sentinel))
1639   - proc))
  1655 + default-directory)))
  1656 + (twittering-start-process-with-sentinel name buffer
  1657 + twittering-curl-program
  1658 + curl-args sentinel)))
1640 1659
1641 1660 (defun twittering-pre-process-buffer-curl (proc buffer connection-info)
1642 1661 (let ((use-ssl (cdr (assq 'use-ssl connection-info)))
@@ -1737,12 +1756,10 @@ The method to perform the request is determined from
1737 1756 `(,@(when (and use-proxy proxy-server proxy-port)
1738 1757 `(,(format "%s_proxy=%s://%s:%s/" scheme
1739 1758 scheme proxy-server proxy-port)))
1740   - ,@process-environment))
1741   - (proc
1742   - (apply 'start-process name buffer twittering-wget-program args)))
1743   - (when (and proc (functionp sentinel))
1744   - (set-process-sentinel proc sentinel))
1745   - proc))
  1759 + ,@process-environment)))
  1760 + (twittering-start-process-with-sentinel name buffer
  1761 + twittering-wget-program args
  1762 + sentinel)))
1746 1763
1747 1764 (defun twittering-pre-process-buffer-wget (proc buffer connection-info)
1748 1765 (with-current-buffer buffer

0 comments on commit 05d5192

Please sign in to comment.
Something went wrong with that request. Please try again.