static SELECT_TYPE non_process_wait_mask;
+#ifdef NON_BLOCKING_CONNECT
/* Mask of bits indicating the descriptors that we wait for connect to
complete on. Once they complete, they are removed from this mask
and added to the input_wait_mask and non_keyboard_wait_mask. */
/* Number of bits set in connect_wait_mask. */
static int num_pending_connects;
+#define IF_NON_BLOCKING_CONNECT(s) s
+#else
+#define IF_NON_BLOCKING_CONNECT(s)
+#endif
+
/* The largest descriptor currently in use for a process object. */
static int max_process_desc;
int xerrno = 0;
int s = -1, outch, inch;
struct gcpro gcpro1;
- int retry = 0;
int count = SPECPDL_INDEX ();
int count1;
Lisp_Object QCaddress; /* one of QClocal or QCremote */
{
int optn, optbits;
+ retry_connect:
+
s = socket (lres->ai_family, lres->ai_socktype, lres->ai_protocol);
if (s < 0)
{
break;
}
- retry_connect:
-
immediate_quit = 1;
QUIT;
immediate_quit = 0;
- if (xerrno == EINTR)
- goto retry_connect;
- if (xerrno == EADDRINUSE && retry < 20)
- {
- /* A delay here is needed on some FreeBSD systems,
- and it is harmless, since this retrying takes time anyway
- and should be infrequent. */
- Fsleep_for (make_number (1), Qnil);
- retry++;
- goto retry_connect;
- }
-
/* Discard the unwind protect closing S. */
specpdl_ptr = specpdl + count1;
emacs_close (s);
s = -1;
+
+ if (xerrno == EINTR)
+ goto retry_connect;
}
if (s >= 0)
chan_process[inchannel] = Qnil;
FD_CLR (inchannel, &input_wait_mask);
FD_CLR (inchannel, &non_keyboard_wait_mask);
+#ifdef NON_BLOCKING_CONNECT
if (FD_ISSET (inchannel, &connect_wait_mask))
{
FD_CLR (inchannel, &connect_wait_mask);
if (--num_pending_connects < 0)
abort ();
}
+#endif
if (inchannel == max_process_desc)
{
int i;
seconds = NILP (process) ? -1 : 0;
return
- (wait_reading_process_input (seconds, useconds, 0, 0,
- Qnil,
- !NILP (process) ? XPROCESS (process) : NULL,
- NILP (just_this_one) ? 0 :
- !INTEGERP (just_this_one) ? 1 : -1)
+ (wait_reading_process_output (seconds, useconds, 0, 0,
+ Qnil,
+ !NILP (process) ? XPROCESS (process) : NULL,
+ NILP (just_this_one) ? 0 :
+ !INTEGERP (just_this_one) ? 1 : -1)
? Qt : Qnil);
}
lisp code is being evalled.
This is also used in record_asynch_buffer_change.
For that purpose, this must be 0
- when not inside wait_reading_process_input. */
+ when not inside wait_reading_process_output. */
static int waiting_for_user_input_p;
/* This is here so breakpoints can be put on it. */
static void
-wait_reading_process_input_1 ()
+wait_reading_process_output_1 ()
{
}
Otherwise, return true iff we received input from any process. */
int
-wait_reading_process_input (time_limit, microsecs, read_kbd, do_display,
- wait_for_cell, wait_proc, just_wait_proc)
+wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
+ wait_for_cell, wait_proc, just_wait_proc)
int time_limit, microsecs, read_kbd, do_display;
Lisp_Object wait_for_cell;
struct Lisp_Process *wait_proc;
{
register int channel, nfds;
SELECT_TYPE Available;
+#ifdef NON_BLOCKING_CONNECT
SELECT_TYPE Connecting;
- int check_connect, check_delay, no_avail;
+ int check_connect;
+#endif
+ int check_delay, no_avail;
int xerrno;
Lisp_Object proc;
EMACS_TIME timeout, end_time;
int saved_waiting_for_user_input_p = waiting_for_user_input_p;
FD_ZERO (&Available);
+#ifdef NON_BLOCKING_CONNECT
FD_ZERO (&Connecting);
+#endif
/* If wait_proc is a process to watch, set wait_channel accordingly. */
if (wait_proc != NULL)
else if (time_limit != -1)
{
/* This is so a breakpoint can be put here. */
- wait_reading_process_input_1 ();
+ wait_reading_process_output_1 ();
}
}
timeout to get our attention. */
if (update_tick != process_tick && do_display)
{
- SELECT_TYPE Atemp, Ctemp;
+ SELECT_TYPE Atemp;
+#ifdef NON_BLOCKING_CONNECT
+ SELECT_TYPE Ctemp;
+#endif
Atemp = input_wait_mask;
#if 0
*/
FD_CLR (0, &Atemp);
#endif
- Ctemp = connect_wait_mask;
+ IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask);
+
EMACS_SET_SECS_USECS (timeout, 0, 0);
if ((select (max (max_process_desc, max_keyboard_desc) + 1,
&Atemp,
+#ifdef NON_BLOCKING_CONNECT
(num_pending_connects > 0 ? &Ctemp : (SELECT_TYPE *)0),
+#else
+ (SELECT_TYPE *)0,
+#endif
(SELECT_TYPE *)0, &timeout)
<= 0))
{
if (XINT (wait_proc->infd) < 0) /* Terminated */
break;
FD_SET (XINT (wait_proc->infd), &Available);
- check_connect = check_delay = 0;
+ check_delay = 0;
+ IF_NON_BLOCKING_CONNECT (check_connect = 0);
}
else if (!NILP (wait_for_cell))
{
Available = non_process_wait_mask;
- check_connect = check_delay = 0;
+ check_delay = 0;
+ IF_NON_BLOCKING_CONNECT (check_connect = 0);
}
else
{
Available = non_keyboard_wait_mask;
else
Available = input_wait_mask;
- check_connect = (num_pending_connects > 0);
+ IF_NON_BLOCKING_CONNECT (check_connect = (num_pending_connects > 0));
check_delay = wait_channel >= 0 ? 0 : process_output_delay_count;
}
}
else
{
+#ifdef NON_BLOCKING_CONNECT
if (check_connect)
Connecting = connect_wait_mask;
+#endif
#ifdef ADAPTIVE_READ_BUFFERING
if (process_output_skip && check_delay > 0)
nfds = select (max (max_process_desc, max_keyboard_desc) + 1,
&Available,
+#ifdef NON_BLOCKING_CONNECT
(check_connect ? &Connecting : (SELECT_TYPE *)0),
+#else
+ (SELECT_TYPE *)0,
+#endif
(SELECT_TYPE *)0, &timeout);
}
if (no_avail)
{
FD_ZERO (&Available);
- check_connect = 0;
+ IF_NON_BLOCKING_CONNECT (check_connect = 0);
}
#if defined(sun) && !defined(USG5_4)
/* If we are using polling for input,
and we see input available, make it get read now.
Otherwise it might not actually get read for a second.
- And on hpux, since we turn off polling in wait_reading_process_input,
+ And on hpux, since we turn off polling in wait_reading_process_output,
it might never get read at all if we don't spend much time
- outside of wait_reading_process_input. */
+ outside of wait_reading_process_output. */
if (read_kbd && interrupt_input
&& keyboard_bit_set (&Available)
&& input_polling_used ())
SIGTYPE
send_process_trap ()
{
+ SIGNAL_THREAD_CHECK (SIGPIPE);
#ifdef BSD4_1
sigrelse (SIGPIPE);
sigrelse (SIGALRM);
object = p->encoding_buf;
encode_coding (coding, (char *) buf, SDATA (object),
len, SBYTES (object));
+ coding_free_composition_data (coding);
len = coding->produced;
buf = SDATA (object);
}
offset = buf - SDATA (object);
#ifdef EMACS_HAS_USECS
- wait_reading_process_input (0, 20000, 0, 0, Qnil, NULL, 0);
+ wait_reading_process_output (0, 20000, 0, 0, Qnil, NULL, 0);
#else
- wait_reading_process_input (1, 0, 0, 0, Qnil, NULL, 0);
+ wait_reading_process_output (1, 0, 0, 0, Qnil, NULL, 0);
#endif
if (BUFFERP (object))
}
if (sig_char && *sig_char != CDISABLE)
- send_process (proc, sig_char, 1, Qnil);
- return;
+ {
+ send_process (proc, sig_char, 1, Qnil);
+ return;
+ }
+ /* If we can't send the signal with a character,
+ fall through and send it another way. */
#else /* ! HAVE_TERMIOS */
/* On Berkeley descendants, the following IOCTL's retrieve the
you'd better be using one of the alternatives above! */
#endif /* ! defined (TCGETA) */
#endif /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
-#endif /* ! defined HAVE_TERMIOS */
+ /* In this case, the code above should alway returns. */
abort ();
- /* The code above always returns from the function. */
+#endif /* ! defined HAVE_TERMIOS */
+
+ /* The code above may fall through if it can't
+ handle the signal. */
#endif /* defined (SIGNALS_VIA_CHARACTERS) */
#ifdef TIOCGPGRP
register struct Lisp_Process *p;
extern EMACS_TIME *input_available_clear_time;
+ SIGNAL_THREAD_CHECK (signo);
+
#ifdef BSD4_1
extern int sigheld;
sigheld |= sigbit (SIGCHLD);
FD_CLR (XINT (p->infd), &non_keyboard_wait_mask);
}
- /* Tell wait_reading_process_input that it needs to wake up and
+ /* Tell wait_reading_process_output that it needs to wake up and
look around. */
if (input_available_clear_time)
EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
else if (WIFSIGNALED (w))
synch_process_termsig = WTERMSIG (w);
- /* Tell wait_reading_process_input that it needs to wake up and
+ /* Tell wait_reading_process_output that it needs to wake up and
look around. */
if (input_available_clear_time)
EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
FD_ZERO (&non_process_wait_mask);
max_process_desc = 0;
+#ifdef NON_BLOCKING_CONNECT
+ FD_ZERO (&connect_wait_mask);
+ num_pending_connects = 0;
+#endif
+
#ifdef ADAPTIVE_READ_BUFFERING
process_output_delay_count = 0;
process_output_skip = 0;
Return true iff we received input from any process. */
int
-wait_reading_process_input (time_limit, microsecs, read_kbd, do_display,
- wait_for_cell, wait_proc, just_wait_proc)
+wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
+ wait_for_cell, wait_proc, just_wait_proc)
int time_limit, microsecs, read_kbd, do_display;
Lisp_Object wait_for_cell;
struct Lisp_Process *wait_proc;