diff options
| author | Lars Ingebrigtsen | 2019-09-20 20:19:28 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-09-20 20:19:28 +0200 |
| commit | b8e9baac9ada62c2ea7437579df4be9d4f437fda (patch) | |
| tree | 6b91ed5b5a4f48bb47e7e12e7dc42d7d2e07fb59 | |
| parent | 385bb140de767ff59b026f5540e0e8bfae53fb55 (diff) | |
| download | emacs-b8e9baac9ada62c2ea7437579df4be9d4f437fda.tar.gz emacs-b8e9baac9ada62c2ea7437579df4be9d4f437fda.zip | |
Allow `process-contact' not to block
* doc/lispref/processes.texi (Process Information): Document it.
* lisp/simple.el (list-processes--refresh): Don't wait for contact
information for non-setup processes.
* src/process.c (Fprocess_contact): Take an optional parameter to
avoid blocking (bug#37408).
| -rw-r--r-- | doc/lispref/processes.texi | 7 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/simple.el | 2 | ||||
| -rw-r--r-- | src/process.c | 20 |
4 files changed, 26 insertions, 7 deletions
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index 61de77d0662..4c7853bae86 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi | |||
| @@ -1042,7 +1042,7 @@ this is either @code{nil}, which means the process is running or | |||
| 1042 | @end smallexample | 1042 | @end smallexample |
| 1043 | @end defun | 1043 | @end defun |
| 1044 | 1044 | ||
| 1045 | @defun process-contact process &optional key | 1045 | @defun process-contact process &optional key no-block |
| 1046 | This function returns information about how a network, a serial, or a | 1046 | This function returns information about how a network, a serial, or a |
| 1047 | pipe connection was set up. When @var{key} is @code{nil}, it returns | 1047 | pipe connection was set up. When @var{key} is @code{nil}, it returns |
| 1048 | @code{(@var{hostname} @var{service})} for a network connection, | 1048 | @code{(@var{hostname} @var{service})} for a network connection, |
| @@ -1086,6 +1086,11 @@ connection, see @code{make-pipe-process} for the list of keys. | |||
| 1086 | 1086 | ||
| 1087 | If @var{key} is a keyword, the function returns the value corresponding | 1087 | If @var{key} is a keyword, the function returns the value corresponding |
| 1088 | to that keyword. | 1088 | to that keyword. |
| 1089 | |||
| 1090 | If @var{process} is a non-blocking network stream that hasn't been | ||
| 1091 | fully set up yet, then this function will block until that has | ||
| 1092 | happened. If given the optional @var{no-block} parameter, this | ||
| 1093 | function will return @code{nil} instead of blocking. | ||
| 1089 | @end defun | 1094 | @end defun |
| 1090 | 1095 | ||
| 1091 | @defun process-id process | 1096 | @defun process-id process |
| @@ -2131,6 +2131,10 @@ valid event type. | |||
| 2131 | * Lisp Changes in Emacs 27.1 | 2131 | * Lisp Changes in Emacs 27.1 |
| 2132 | 2132 | ||
| 2133 | +++ | 2133 | +++ |
| 2134 | ** 'process-contact' now takes an optional NO-BLOCK parameter to allow | ||
| 2135 | not waiting for a process to be set up. | ||
| 2136 | |||
| 2137 | +++ | ||
| 2134 | ** The new 'quit-window-hook' is now run first when executing the | 2138 | ** The new 'quit-window-hook' is now run first when executing the |
| 2135 | 'quit-window' command. | 2139 | 'quit-window' command. |
| 2136 | 2140 | ||
diff --git a/lisp/simple.el b/lisp/simple.el index 358b6a4f200..a267200aeb9 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -4107,7 +4107,7 @@ Also, delete any process that is exited or signaled." | |||
| 4107 | (t "--"))) | 4107 | (t "--"))) |
| 4108 | (cmd | 4108 | (cmd |
| 4109 | (if (memq type '(network serial)) | 4109 | (if (memq type '(network serial)) |
| 4110 | (let ((contact (process-contact p t))) | 4110 | (let ((contact (process-contact p t t))) |
| 4111 | (if (eq type 'network) | 4111 | (if (eq type 'network) |
| 4112 | (format "(%s %s)" | 4112 | (format "(%s %s)" |
| 4113 | (if (plist-get contact :type) | 4113 | (if (plist-get contact :type) |
diff --git a/src/process.c b/src/process.c index 372277a953d..a95192d8fba 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -1456,7 +1456,7 @@ DEFUN ("process-query-on-exit-flag", | |||
| 1456 | } | 1456 | } |
| 1457 | 1457 | ||
| 1458 | DEFUN ("process-contact", Fprocess_contact, Sprocess_contact, | 1458 | DEFUN ("process-contact", Fprocess_contact, Sprocess_contact, |
| 1459 | 1, 2, 0, | 1459 | 1, 3, 0, |
| 1460 | doc: /* Return the contact info of PROCESS; t for a real child. | 1460 | doc: /* Return the contact info of PROCESS; t for a real child. |
| 1461 | For a network or serial or pipe connection, the value depends on the | 1461 | For a network or serial or pipe connection, the value depends on the |
| 1462 | optional KEY arg. If KEY is nil, value is a cons cell of the form | 1462 | optional KEY arg. If KEY is nil, value is a cons cell of the form |
| @@ -1465,9 +1465,12 @@ connection; it is t for a pipe connection. If KEY is t, the complete | |||
| 1465 | contact information for the connection is returned, else the specific | 1465 | contact information for the connection is returned, else the specific |
| 1466 | value for the keyword KEY is returned. See `make-network-process', | 1466 | value for the keyword KEY is returned. See `make-network-process', |
| 1467 | `make-serial-process', or `make-pipe-process' for the list of keywords. | 1467 | `make-serial-process', or `make-pipe-process' for the list of keywords. |
| 1468 | |||
| 1468 | If PROCESS is a non-blocking network process that hasn't been fully | 1469 | If PROCESS is a non-blocking network process that hasn't been fully |
| 1469 | set up yet, this function will block until socket setup has completed. */) | 1470 | set up yet, this function will block until socket setup has completed. |
| 1470 | (Lisp_Object process, Lisp_Object key) | 1471 | If the optional NO-BLOCK parameter is specified, return nil instead of |
| 1472 | waiting for the process to be fully set up.*/) | ||
| 1473 | (Lisp_Object process, Lisp_Object key, Lisp_Object no_block) | ||
| 1471 | { | 1474 | { |
| 1472 | Lisp_Object contact; | 1475 | Lisp_Object contact; |
| 1473 | 1476 | ||
| @@ -1476,8 +1479,15 @@ set up yet, this function will block until socket setup has completed. */) | |||
| 1476 | 1479 | ||
| 1477 | #ifdef DATAGRAM_SOCKETS | 1480 | #ifdef DATAGRAM_SOCKETS |
| 1478 | 1481 | ||
| 1479 | if (NETCONN_P (process)) | 1482 | if (NETCONN_P (process) && XPROCESS (process)->infd < 0) |
| 1480 | wait_for_socket_fds (process, "process-contact"); | 1483 | { |
| 1484 | /* Usually wait for the network process to finish being set | ||
| 1485 | * up. */ | ||
| 1486 | if (!NILP (no_block)) | ||
| 1487 | return Qnil; | ||
| 1488 | |||
| 1489 | wait_for_socket_fds (process, "process-contact"); | ||
| 1490 | } | ||
| 1481 | 1491 | ||
| 1482 | if (DATAGRAM_CONN_P (process) | 1492 | if (DATAGRAM_CONN_P (process) |
| 1483 | && (EQ (key, Qt) || EQ (key, QCremote))) | 1493 | && (EQ (key, Qt) || EQ (key, QCremote))) |