diff options
| author | Paul Eggert | 2013-08-06 07:17:25 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-08-06 07:17:25 -0700 |
| commit | 2878ba7ef3225a7946c72ef6346467f35c453347 (patch) | |
| tree | febff738d1357d6f4426fc708881bc905ad16fb4 /src/process.c | |
| parent | a6933dccd7ac7f5dcae6fe590b3fea68bad7f767 (diff) | |
| download | emacs-2878ba7ef3225a7946c72ef6346467f35c453347.tar.gz emacs-2878ba7ef3225a7946c72ef6346467f35c453347.zip | |
* process.c: Fix minor off-by-one issues in descriptor counts.
This shouldn't fix any real bugs, but it cleans up the code a bit.
(max_process_desc, max_input_desc): -1, not 0, means none.
All uses changed.
(delete_input_desc): New function.
(delete_write_fd, delete_keyboard_wait_descriptor): Use it.
(deactivate_process): Scan backwards when recomuting max_process_desc;
that should be faster.
(init_process_emacs): Initialize max_input_desc.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/process.c b/src/process.c index d87a1803fe2..85d07028c59 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -323,10 +323,10 @@ static SELECT_TYPE connect_wait_mask; | |||
| 323 | static int num_pending_connects; | 323 | static int num_pending_connects; |
| 324 | #endif /* NON_BLOCKING_CONNECT */ | 324 | #endif /* NON_BLOCKING_CONNECT */ |
| 325 | 325 | ||
| 326 | /* The largest descriptor currently in use for a process object. */ | 326 | /* The largest descriptor currently in use for a process object; -1 if none. */ |
| 327 | static int max_process_desc; | 327 | static int max_process_desc; |
| 328 | 328 | ||
| 329 | /* The largest descriptor currently in use for input. */ | 329 | /* The largest descriptor currently in use for input; -1 if none. */ |
| 330 | static int max_input_desc; | 330 | static int max_input_desc; |
| 331 | 331 | ||
| 332 | /* Indexed by descriptor, gives the process (if any) for that descriptor */ | 332 | /* Indexed by descriptor, gives the process (if any) for that descriptor */ |
| @@ -500,13 +500,27 @@ add_write_fd (int fd, fd_callback func, void *data) | |||
| 500 | fd_callback_info[fd].condition |= FOR_WRITE; | 500 | fd_callback_info[fd].condition |= FOR_WRITE; |
| 501 | } | 501 | } |
| 502 | 502 | ||
| 503 | /* FD is no longer an input descriptor; update max_input_desc accordingly. */ | ||
| 504 | |||
| 505 | static void | ||
| 506 | delete_input_desc (int fd) | ||
| 507 | { | ||
| 508 | if (fd == max_input_desc) | ||
| 509 | { | ||
| 510 | do | ||
| 511 | fd--; | ||
| 512 | while (0 <= fd && ! (FD_ISSET (fd, &input_wait_mask) | ||
| 513 | || FD_ISSET (fd, &write_mask))); | ||
| 514 | |||
| 515 | max_input_desc = fd; | ||
| 516 | } | ||
| 517 | } | ||
| 518 | |||
| 503 | /* Stop monitoring file descriptor FD for when write is possible. */ | 519 | /* Stop monitoring file descriptor FD for when write is possible. */ |
| 504 | 520 | ||
| 505 | void | 521 | void |
| 506 | delete_write_fd (int fd) | 522 | delete_write_fd (int fd) |
| 507 | { | 523 | { |
| 508 | int lim = max_input_desc; | ||
| 509 | |||
| 510 | eassert (fd < MAXDESC); | 524 | eassert (fd < MAXDESC); |
| 511 | FD_CLR (fd, &write_mask); | 525 | FD_CLR (fd, &write_mask); |
| 512 | fd_callback_info[fd].condition &= ~FOR_WRITE; | 526 | fd_callback_info[fd].condition &= ~FOR_WRITE; |
| @@ -514,15 +528,7 @@ delete_write_fd (int fd) | |||
| 514 | { | 528 | { |
| 515 | fd_callback_info[fd].func = 0; | 529 | fd_callback_info[fd].func = 0; |
| 516 | fd_callback_info[fd].data = 0; | 530 | fd_callback_info[fd].data = 0; |
| 517 | 531 | delete_input_desc (fd); | |
| 518 | if (fd == max_input_desc) | ||
| 519 | for (fd = lim; fd >= 0; fd--) | ||
| 520 | if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask)) | ||
| 521 | { | ||
| 522 | max_input_desc = fd; | ||
| 523 | break; | ||
| 524 | } | ||
| 525 | |||
| 526 | } | 532 | } |
| 527 | } | 533 | } |
| 528 | 534 | ||
| @@ -3831,13 +3837,14 @@ deactivate_process (Lisp_Object proc) | |||
| 3831 | #endif | 3837 | #endif |
| 3832 | if (inchannel == max_process_desc) | 3838 | if (inchannel == max_process_desc) |
| 3833 | { | 3839 | { |
| 3834 | int i; | ||
| 3835 | /* We just closed the highest-numbered process input descriptor, | 3840 | /* We just closed the highest-numbered process input descriptor, |
| 3836 | so recompute the highest-numbered one now. */ | 3841 | so recompute the highest-numbered one now. */ |
| 3837 | max_process_desc = 0; | 3842 | int i = inchannel; |
| 3838 | for (i = 0; i < MAXDESC; i++) | 3843 | do |
| 3839 | if (!NILP (chan_process[i])) | 3844 | i--; |
| 3840 | max_process_desc = i; | 3845 | while (0 <= i && NILP (chan_process[i])); |
| 3846 | |||
| 3847 | max_process_desc = i; | ||
| 3841 | } | 3848 | } |
| 3842 | } | 3849 | } |
| 3843 | } | 3850 | } |
| @@ -6763,16 +6770,9 @@ void | |||
| 6763 | delete_keyboard_wait_descriptor (int desc) | 6770 | delete_keyboard_wait_descriptor (int desc) |
| 6764 | { | 6771 | { |
| 6765 | #ifdef subprocesses | 6772 | #ifdef subprocesses |
| 6766 | int fd; | ||
| 6767 | int lim = max_input_desc; | ||
| 6768 | |||
| 6769 | FD_CLR (desc, &input_wait_mask); | 6773 | FD_CLR (desc, &input_wait_mask); |
| 6770 | FD_CLR (desc, &non_process_wait_mask); | 6774 | FD_CLR (desc, &non_process_wait_mask); |
| 6771 | 6775 | delete_input_desc (desc); | |
| 6772 | if (desc == max_input_desc) | ||
| 6773 | for (fd = 0; fd < lim; fd++) | ||
| 6774 | if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask)) | ||
| 6775 | max_input_desc = fd; | ||
| 6776 | #endif | 6776 | #endif |
| 6777 | } | 6777 | } |
| 6778 | 6778 | ||
| @@ -7037,7 +7037,7 @@ init_process_emacs (void) | |||
| 7037 | FD_ZERO (&non_keyboard_wait_mask); | 7037 | FD_ZERO (&non_keyboard_wait_mask); |
| 7038 | FD_ZERO (&non_process_wait_mask); | 7038 | FD_ZERO (&non_process_wait_mask); |
| 7039 | FD_ZERO (&write_mask); | 7039 | FD_ZERO (&write_mask); |
| 7040 | max_process_desc = 0; | 7040 | max_process_desc = max_input_desc = -1; |
| 7041 | memset (fd_callback_info, 0, sizeof (fd_callback_info)); | 7041 | memset (fd_callback_info, 0, sizeof (fd_callback_info)); |
| 7042 | 7042 | ||
| 7043 | #ifdef NON_BLOCKING_CONNECT | 7043 | #ifdef NON_BLOCKING_CONNECT |