Mercurial > emacs
comparison src/process.c @ 57840:8abbe69dfdb2
(connect_wait_mask, num_pending_connects): Only
declare and use them if NON_BLOCKING_CONNECT is defined.
(IF_NON_BLOCKING_CONNECT): New helper macro.
(wait_reading_process_output): Only declare and use local vars
Connecting and check_connect when NON_BLOCKING_CONNECT is defined.
(init_process): Initialize them if NON_BLOCKING_CONNECT defined.
| author | Kim F. Storm <storm@cua.dk> |
|---|---|
| date | Mon, 01 Nov 2004 11:04:11 +0000 |
| parents | d27beaf1c61c |
| children | 4ebc52bf6429 7a0245dd1848 e24e2e78deda |
comparison
equal
deleted
inserted
replaced
| 57839:75b388c4e9e1 | 57840:8abbe69dfdb2 |
|---|---|
| 308 | 308 |
| 309 /* Mask that excludes process input descriptor (s). */ | 309 /* Mask that excludes process input descriptor (s). */ |
| 310 | 310 |
| 311 static SELECT_TYPE non_process_wait_mask; | 311 static SELECT_TYPE non_process_wait_mask; |
| 312 | 312 |
| 313 #ifdef NON_BLOCKING_CONNECT | |
| 313 /* Mask of bits indicating the descriptors that we wait for connect to | 314 /* Mask of bits indicating the descriptors that we wait for connect to |
| 314 complete on. Once they complete, they are removed from this mask | 315 complete on. Once they complete, they are removed from this mask |
| 315 and added to the input_wait_mask and non_keyboard_wait_mask. */ | 316 and added to the input_wait_mask and non_keyboard_wait_mask. */ |
| 316 | 317 |
| 317 static SELECT_TYPE connect_wait_mask; | 318 static SELECT_TYPE connect_wait_mask; |
| 318 | 319 |
| 319 /* Number of bits set in connect_wait_mask. */ | 320 /* Number of bits set in connect_wait_mask. */ |
| 320 static int num_pending_connects; | 321 static int num_pending_connects; |
| 322 | |
| 323 #define IF_NON_BLOCKING_CONNECT(s) s | |
| 324 #else | |
| 325 #define IF_NON_BLOCKING_CONNECT(s) | |
| 326 #endif | |
| 321 | 327 |
| 322 /* The largest descriptor currently in use for a process object. */ | 328 /* The largest descriptor currently in use for a process object. */ |
| 323 static int max_process_desc; | 329 static int max_process_desc; |
| 324 | 330 |
| 325 /* The largest descriptor currently in use for keyboard input. */ | 331 /* The largest descriptor currently in use for keyboard input. */ |
| 3670 } | 3676 } |
| 3671 #endif | 3677 #endif |
| 3672 chan_process[inchannel] = Qnil; | 3678 chan_process[inchannel] = Qnil; |
| 3673 FD_CLR (inchannel, &input_wait_mask); | 3679 FD_CLR (inchannel, &input_wait_mask); |
| 3674 FD_CLR (inchannel, &non_keyboard_wait_mask); | 3680 FD_CLR (inchannel, &non_keyboard_wait_mask); |
| 3681 #ifdef NON_BLOCKING_CONNECT | |
| 3675 if (FD_ISSET (inchannel, &connect_wait_mask)) | 3682 if (FD_ISSET (inchannel, &connect_wait_mask)) |
| 3676 { | 3683 { |
| 3677 FD_CLR (inchannel, &connect_wait_mask); | 3684 FD_CLR (inchannel, &connect_wait_mask); |
| 3678 if (--num_pending_connects < 0) | 3685 if (--num_pending_connects < 0) |
| 3679 abort (); | 3686 abort (); |
| 3680 } | 3687 } |
| 3688 #endif | |
| 3681 if (inchannel == max_process_desc) | 3689 if (inchannel == max_process_desc) |
| 3682 { | 3690 { |
| 3683 int i; | 3691 int i; |
| 3684 /* We just closed the highest-numbered process input descriptor, | 3692 /* We just closed the highest-numbered process input descriptor, |
| 3685 so recompute the highest-numbered one now. */ | 3693 so recompute the highest-numbered one now. */ |
| 4036 struct Lisp_Process *wait_proc; | 4044 struct Lisp_Process *wait_proc; |
| 4037 int just_wait_proc; | 4045 int just_wait_proc; |
| 4038 { | 4046 { |
| 4039 register int channel, nfds; | 4047 register int channel, nfds; |
| 4040 SELECT_TYPE Available; | 4048 SELECT_TYPE Available; |
| 4049 #ifdef NON_BLOCKING_CONNECT | |
| 4041 SELECT_TYPE Connecting; | 4050 SELECT_TYPE Connecting; |
| 4042 int check_connect, check_delay, no_avail; | 4051 int check_connect; |
| 4052 #endif | |
| 4053 int check_delay, no_avail; | |
| 4043 int xerrno; | 4054 int xerrno; |
| 4044 Lisp_Object proc; | 4055 Lisp_Object proc; |
| 4045 EMACS_TIME timeout, end_time; | 4056 EMACS_TIME timeout, end_time; |
| 4046 int wait_channel = -1; | 4057 int wait_channel = -1; |
| 4047 int got_some_input = 0; | 4058 int got_some_input = 0; |
| 4048 /* Either nil or a cons cell, the car of which is of interest and | 4059 /* Either nil or a cons cell, the car of which is of interest and |
| 4049 may be changed outside of this routine. */ | 4060 may be changed outside of this routine. */ |
| 4050 int saved_waiting_for_user_input_p = waiting_for_user_input_p; | 4061 int saved_waiting_for_user_input_p = waiting_for_user_input_p; |
| 4051 | 4062 |
| 4052 FD_ZERO (&Available); | 4063 FD_ZERO (&Available); |
| 4064 #ifdef NON_BLOCKING_CONNECT | |
| 4053 FD_ZERO (&Connecting); | 4065 FD_ZERO (&Connecting); |
| 4066 #endif | |
| 4054 | 4067 |
| 4055 /* If wait_proc is a process to watch, set wait_channel accordingly. */ | 4068 /* If wait_proc is a process to watch, set wait_channel accordingly. */ |
| 4056 if (wait_proc != NULL) | 4069 if (wait_proc != NULL) |
| 4057 wait_channel = XINT (wait_proc->infd); | 4070 wait_channel = XINT (wait_proc->infd); |
| 4058 | 4071 |
| 4185 available, notify the user of the change right away. After | 4198 available, notify the user of the change right away. After |
| 4186 this explicit check, we'll let the SIGCHLD handler zap | 4199 this explicit check, we'll let the SIGCHLD handler zap |
| 4187 timeout to get our attention. */ | 4200 timeout to get our attention. */ |
| 4188 if (update_tick != process_tick && do_display) | 4201 if (update_tick != process_tick && do_display) |
| 4189 { | 4202 { |
| 4190 SELECT_TYPE Atemp, Ctemp; | 4203 SELECT_TYPE Atemp; |
| 4204 #ifdef NON_BLOCKING_CONNECT | |
| 4205 SELECT_TYPE Ctemp; | |
| 4206 #endif | |
| 4191 | 4207 |
| 4192 Atemp = input_wait_mask; | 4208 Atemp = input_wait_mask; |
| 4193 #if 0 | 4209 #if 0 |
| 4194 /* On Mac OS X 10.0, the SELECT system call always says input is | 4210 /* On Mac OS X 10.0, the SELECT system call always says input is |
| 4195 present (for reading) at stdin, even when none is. This | 4211 present (for reading) at stdin, even when none is. This |
| 4197 status_notify not to be called. As a result output of | 4213 status_notify not to be called. As a result output of |
| 4198 subprocesses are incorrectly discarded. | 4214 subprocesses are incorrectly discarded. |
| 4199 */ | 4215 */ |
| 4200 FD_CLR (0, &Atemp); | 4216 FD_CLR (0, &Atemp); |
| 4201 #endif | 4217 #endif |
| 4202 Ctemp = connect_wait_mask; | 4218 IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask); |
| 4219 | |
| 4203 EMACS_SET_SECS_USECS (timeout, 0, 0); | 4220 EMACS_SET_SECS_USECS (timeout, 0, 0); |
| 4204 if ((select (max (max_process_desc, max_keyboard_desc) + 1, | 4221 if ((select (max (max_process_desc, max_keyboard_desc) + 1, |
| 4205 &Atemp, | 4222 &Atemp, |
| 4223 #ifdef NON_BLOCKING_CONNECT | |
| 4206 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0), | 4224 (num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0), |
| 4225 #else | |
| 4226 (SELECT_TYPE *)0, | |
| 4227 #endif | |
| 4207 (SELECT_TYPE *)0, &timeout) | 4228 (SELECT_TYPE *)0, &timeout) |
| 4208 <= 0)) | 4229 <= 0)) |
| 4209 { | 4230 { |
| 4210 /* It's okay for us to do this and then continue with | 4231 /* It's okay for us to do this and then continue with |
| 4211 the loop, since timeout has already been zeroed out. */ | 4232 the loop, since timeout has already been zeroed out. */ |
| 4261 if (wait_proc && just_wait_proc) | 4282 if (wait_proc && just_wait_proc) |
| 4262 { | 4283 { |
| 4263 if (XINT (wait_proc->infd) < 0) /* Terminated */ | 4284 if (XINT (wait_proc->infd) < 0) /* Terminated */ |
| 4264 break; | 4285 break; |
| 4265 FD_SET (XINT (wait_proc->infd), &Available); | 4286 FD_SET (XINT (wait_proc->infd), &Available); |
| 4266 check_connect = check_delay = 0; | 4287 check_delay = 0; |
| 4288 IF_NON_BLOCKING_CONNECT (check_connect = 0); | |
| 4267 } | 4289 } |
| 4268 else if (!NILP (wait_for_cell)) | 4290 else if (!NILP (wait_for_cell)) |
| 4269 { | 4291 { |
| 4270 Available = non_process_wait_mask; | 4292 Available = non_process_wait_mask; |
| 4271 check_connect = check_delay = 0; | 4293 check_delay = 0; |
| 4294 IF_NON_BLOCKING_CONNECT (check_connect = 0); | |
| 4272 } | 4295 } |
| 4273 else | 4296 else |
| 4274 { | 4297 { |
| 4275 if (! read_kbd) | 4298 if (! read_kbd) |
| 4276 Available = non_keyboard_wait_mask; | 4299 Available = non_keyboard_wait_mask; |
| 4277 else | 4300 else |
| 4278 Available = input_wait_mask; | 4301 Available = input_wait_mask; |
| 4279 check_connect = (num_pending_connects > 0); | 4302 IF_NON_BLOCKING_CONNECT (check_connect = (num_pending_connects > 0)); |
| 4280 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count; | 4303 check_delay = wait_channel >= 0 ? 0 : process_output_delay_count; |
| 4281 } | 4304 } |
| 4282 | 4305 |
| 4283 /* If frame size has changed or the window is newly mapped, | 4306 /* If frame size has changed or the window is newly mapped, |
| 4284 redisplay now, before we start to wait. There is a race | 4307 redisplay now, before we start to wait. There is a race |
| 4299 nfds = 0; | 4322 nfds = 0; |
| 4300 no_avail = 1; | 4323 no_avail = 1; |
| 4301 } | 4324 } |
| 4302 else | 4325 else |
| 4303 { | 4326 { |
| 4327 #ifdef NON_BLOCKING_CONNECT | |
| 4304 if (check_connect) | 4328 if (check_connect) |
| 4305 Connecting = connect_wait_mask; | 4329 Connecting = connect_wait_mask; |
| 4330 #endif | |
| 4306 | 4331 |
| 4307 #ifdef ADAPTIVE_READ_BUFFERING | 4332 #ifdef ADAPTIVE_READ_BUFFERING |
| 4308 if (process_output_skip && check_delay > 0) | 4333 if (process_output_skip && check_delay > 0) |
| 4309 { | 4334 { |
| 4310 int usecs = EMACS_USECS (timeout); | 4335 int usecs = EMACS_USECS (timeout); |
| 4331 } | 4356 } |
| 4332 #endif | 4357 #endif |
| 4333 | 4358 |
| 4334 nfds = select (max (max_process_desc, max_keyboard_desc) + 1, | 4359 nfds = select (max (max_process_desc, max_keyboard_desc) + 1, |
| 4335 &Available, | 4360 &Available, |
| 4361 #ifdef NON_BLOCKING_CONNECT | |
| 4336 (check_connect ? &Connecting : (SELECT_TYPE *)0), | 4362 (check_connect ? &Connecting : (SELECT_TYPE *)0), |
| 4363 #else | |
| 4364 (SELECT_TYPE *)0, | |
| 4365 #endif | |
| 4337 (SELECT_TYPE *)0, &timeout); | 4366 (SELECT_TYPE *)0, &timeout); |
| 4338 } | 4367 } |
| 4339 | 4368 |
| 4340 xerrno = errno; | 4369 xerrno = errno; |
| 4341 | 4370 |
| 4387 } | 4416 } |
| 4388 | 4417 |
| 4389 if (no_avail) | 4418 if (no_avail) |
| 4390 { | 4419 { |
| 4391 FD_ZERO (&Available); | 4420 FD_ZERO (&Available); |
| 4392 check_connect = 0; | 4421 IF_NON_BLOCKING_CONNECT (check_connect = 0); |
| 4393 } | 4422 } |
| 4394 | 4423 |
| 4395 #if defined(sun) && !defined(USG5_4) | 4424 #if defined(sun) && !defined(USG5_4) |
| 4396 if (nfds > 0 && keyboard_bit_set (&Available) | 4425 if (nfds > 0 && keyboard_bit_set (&Available) |
| 4397 && interrupt_input) | 4426 && interrupt_input) |
| 6625 | 6654 |
| 6626 FD_ZERO (&input_wait_mask); | 6655 FD_ZERO (&input_wait_mask); |
| 6627 FD_ZERO (&non_keyboard_wait_mask); | 6656 FD_ZERO (&non_keyboard_wait_mask); |
| 6628 FD_ZERO (&non_process_wait_mask); | 6657 FD_ZERO (&non_process_wait_mask); |
| 6629 max_process_desc = 0; | 6658 max_process_desc = 0; |
| 6659 | |
| 6660 #ifdef NON_BLOCKING_CONNECT | |
| 6661 FD_ZERO (&connect_wait_mask); | |
| 6662 num_pending_connects = 0; | |
| 6663 #endif | |
| 6630 | 6664 |
| 6631 #ifdef ADAPTIVE_READ_BUFFERING | 6665 #ifdef ADAPTIVE_READ_BUFFERING |
| 6632 process_output_delay_count = 0; | 6666 process_output_delay_count = 0; |
| 6633 process_output_skip = 0; | 6667 process_output_skip = 0; |
| 6634 #endif | 6668 #endif |
