aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorPaul Eggert2016-03-22 01:17:56 -0700
committerPaul Eggert2016-03-22 01:19:03 -0700
commit780a605e1d2de4b975e6f1f29b491c9af419dcff (patch)
treeabbfb59c66e8a7cd50819a7bbe0e5e658d40ae54 /src/process.c
parent7dba17670f42cdaa73424a2bf60925ef49671fad (diff)
downloademacs-780a605e1d2de4b975e6f1f29b491c9af419dcff.tar.gz
emacs-780a605e1d2de4b975e6f1f29b491c9af419dcff.zip
Assume NON_BLOCKING_CONNECT (Bug#22946)
* lisp/proced.el (proced-signal-list): Omit comment about obsolete systems that do not support POSIX 1003.1-2001 signals. * src/process.c (NON_BLOCKING_CONNECT): Remove, since we can now assume POSIX 1003.1-2001 or better here. Assume it’s defined. (connect_network_socket): Assume EINPROGRESS is defined, as that’s portable too now. (Fmake_network_process): Use bool for boolean.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c53
1 files changed, 5 insertions, 48 deletions
diff --git a/src/process.c b/src/process.c
index a518c2bffb8..198e7de3990 100644
--- a/src/process.c
+++ b/src/process.c
@@ -193,16 +193,6 @@ static EMACS_INT process_tick;
193/* Number of events for which the user or sentinel has been notified. */ 193/* Number of events for which the user or sentinel has been notified. */
194static EMACS_INT update_tick; 194static EMACS_INT update_tick;
195 195
196/* Define NON_BLOCKING_CONNECT if we can support non-blocking connects.
197 The code can be simplified by assuming NON_BLOCKING_CONNECT once
198 Emacs starts assuming POSIX 1003.1-2001 or later. */
199
200#if (defined HAVE_SELECT \
201 && (defined GNU_LINUX || defined HAVE_GETPEERNAME) \
202 && (defined EWOULDBLOCK || defined EINPROGRESS))
203# define NON_BLOCKING_CONNECT
204#endif
205
206/* Define DATAGRAM_SOCKETS if datagrams can be used safely on 196/* Define DATAGRAM_SOCKETS if datagrams can be used safely on
207 this system. We need to read full packets, so we need a 197 this system. We need to read full packets, so we need a
208 "non-destructive" select. So we require either native select, 198 "non-destructive" select. So we require either native select,
@@ -262,7 +252,6 @@ static fd_set non_process_wait_mask;
262 252
263static fd_set write_mask; 253static fd_set write_mask;
264 254
265#ifdef NON_BLOCKING_CONNECT
266/* Mask of bits indicating the descriptors that we wait for connect to 255/* Mask of bits indicating the descriptors that we wait for connect to
267 complete on. Once they complete, they are removed from this mask 256 complete on. Once they complete, they are removed from this mask
268 and added to the input_wait_mask and non_keyboard_wait_mask. */ 257 and added to the input_wait_mask and non_keyboard_wait_mask. */
@@ -271,7 +260,6 @@ static fd_set connect_wait_mask;
271 260
272/* Number of bits set in connect_wait_mask. */ 261/* Number of bits set in connect_wait_mask. */
273static int num_pending_connects; 262static int num_pending_connects;
274#endif /* NON_BLOCKING_CONNECT */
275 263
276/* The largest descriptor currently in use for a process object; -1 if none. */ 264/* The largest descriptor currently in use for a process object; -1 if none. */
277static int max_process_desc; 265static int max_process_desc;
@@ -3133,7 +3121,6 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses)
3133 break; 3121 break;
3134#endif /* DATAGRAM_SOCKETS */ 3122#endif /* DATAGRAM_SOCKETS */
3135 3123
3136#ifdef NON_BLOCKING_CONNECT
3137 if (p->is_non_blocking_client) 3124 if (p->is_non_blocking_client)
3138 { 3125 {
3139 ret = fcntl (s, F_SETFL, O_NONBLOCK); 3126 ret = fcntl (s, F_SETFL, O_NONBLOCK);
@@ -3145,7 +3132,6 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses)
3145 continue; 3132 continue;
3146 } 3133 }
3147 } 3134 }
3148#endif
3149 3135
3150 /* Make us close S if quit. */ 3136 /* Make us close S if quit. */
3151 record_unwind_protect_int (close_file_unwind, s); 3137 record_unwind_protect_int (close_file_unwind, s);
@@ -3221,17 +3207,8 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses)
3221 break; 3207 break;
3222 } 3208 }
3223 3209
3224#ifdef NON_BLOCKING_CONNECT
3225#ifdef EINPROGRESS
3226 if (p->is_non_blocking_client && xerrno == EINPROGRESS) 3210 if (p->is_non_blocking_client && xerrno == EINPROGRESS)
3227 break; 3211 break;
3228#else
3229#ifdef EWOULDBLOCK
3230 if (p->is_non_blocking_client && xerrno == EWOULDBLOCK)
3231 break;
3232#endif
3233#endif
3234#endif
3235 3212
3236#ifndef WINDOWSNT 3213#ifndef WINDOWSNT
3237 if (xerrno == EINTR) 3214 if (xerrno == EINTR)
@@ -3366,7 +3343,6 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses)
3366 BUF_ZV (XBUFFER (p->buffer)), 3343 BUF_ZV (XBUFFER (p->buffer)),
3367 BUF_ZV_BYTE (XBUFFER (p->buffer))); 3344 BUF_ZV_BYTE (XBUFFER (p->buffer)));
3368 3345
3369#ifdef NON_BLOCKING_CONNECT
3370 if (p->is_non_blocking_client) 3346 if (p->is_non_blocking_client)
3371 { 3347 {
3372 /* We may get here if connect did succeed immediately. However, 3348 /* We may get here if connect did succeed immediately. However,
@@ -3381,7 +3357,6 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses)
3381 } 3357 }
3382 } 3358 }
3383 else 3359 else
3384#endif
3385 /* A server may have a client filter setting of Qt, but it must 3360 /* A server may have a client filter setting of Qt, but it must
3386 still listen for incoming connects unless it is stopped. */ 3361 still listen for incoming connects unless it is stopped. */
3387 if ((!EQ (p->filter, Qt) && !EQ (p->command, Qt)) 3362 if ((!EQ (p->filter, Qt) && !EQ (p->command, Qt))
@@ -3894,8 +3869,8 @@ usage: (make-network-process &rest ARGS) */)
3894 pset_command (p, Qt); 3869 pset_command (p, Qt);
3895 p->pid = 0; 3870 p->pid = 0;
3896 p->backlog = 5; 3871 p->backlog = 5;
3897 p->is_non_blocking_client = 0; 3872 p->is_non_blocking_client = false;
3898 p->is_server = 0; 3873 p->is_server = false;
3899 p->port = port; 3874 p->port = port;
3900 p->socktype = socktype; 3875 p->socktype = socktype;
3901 p->ai_protocol = ai_protocol; 3876 p->ai_protocol = ai_protocol;
@@ -3918,21 +3893,15 @@ usage: (make-network-process &rest ARGS) */)
3918 { 3893 {
3919 /* Don't support network sockets when non-blocking mode is 3894 /* Don't support network sockets when non-blocking mode is
3920 not available, since a blocked Emacs is not useful. */ 3895 not available, since a blocked Emacs is not useful. */
3921 p->is_server = 1; 3896 p->is_server = true;
3922 if (TYPE_RANGED_INTEGERP (int, tem)) 3897 if (TYPE_RANGED_INTEGERP (int, tem))
3923 p->backlog = XINT (tem); 3898 p->backlog = XINT (tem);
3924 } 3899 }
3925 3900
3926 /* :nowait BOOL */ 3901 /* :nowait BOOL */
3927 if (!p->is_server && socktype != SOCK_DGRAM 3902 if (!p->is_server && socktype != SOCK_DGRAM
3928 && (tem = Fplist_get (contact, QCnowait), !NILP (tem))) 3903 && !NILP (Fplist_get (contact, QCnowait)))
3929 { 3904 p->is_non_blocking_client = true;
3930#ifndef NON_BLOCKING_CONNECT
3931 error ("Non-blocking connect not supported");
3932#else
3933 p->is_non_blocking_client = 1;
3934#endif
3935 }
3936 3905
3937#ifdef HAVE_GETADDRINFO_A 3906#ifdef HAVE_GETADDRINFO_A
3938 /* With async address resolution, the list of addresses is empty, so 3907 /* With async address resolution, the list of addresses is empty, so
@@ -4338,7 +4307,6 @@ deactivate_process (Lisp_Object proc)
4338 chan_process[inchannel] = Qnil; 4307 chan_process[inchannel] = Qnil;
4339 FD_CLR (inchannel, &input_wait_mask); 4308 FD_CLR (inchannel, &input_wait_mask);
4340 FD_CLR (inchannel, &non_keyboard_wait_mask); 4309 FD_CLR (inchannel, &non_keyboard_wait_mask);
4341#ifdef NON_BLOCKING_CONNECT
4342 if (FD_ISSET (inchannel, &connect_wait_mask)) 4310 if (FD_ISSET (inchannel, &connect_wait_mask))
4343 { 4311 {
4344 FD_CLR (inchannel, &connect_wait_mask); 4312 FD_CLR (inchannel, &connect_wait_mask);
@@ -4346,7 +4314,6 @@ deactivate_process (Lisp_Object proc)
4346 if (--num_pending_connects < 0) 4314 if (--num_pending_connects < 0)
4347 emacs_abort (); 4315 emacs_abort ();
4348 } 4316 }
4349#endif
4350 if (inchannel == max_process_desc) 4317 if (inchannel == max_process_desc)
4351 { 4318 {
4352 /* We just closed the highest-numbered process input descriptor, 4319 /* We just closed the highest-numbered process input descriptor,
@@ -4999,11 +4966,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4999 timeout = make_timespec (0, 0); 4966 timeout = make_timespec (0, 0);
5000 if ((pselect (max (max_process_desc, max_input_desc) + 1, 4967 if ((pselect (max (max_process_desc, max_input_desc) + 1,
5001 &Atemp, 4968 &Atemp,
5002#ifdef NON_BLOCKING_CONNECT
5003 (num_pending_connects > 0 ? &Ctemp : NULL), 4969 (num_pending_connects > 0 ? &Ctemp : NULL),
5004#else
5005 NULL,
5006#endif
5007 NULL, &timeout, NULL) 4970 NULL, &timeout, NULL)
5008 <= 0)) 4971 <= 0))
5009 { 4972 {
@@ -5495,7 +5458,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
5495 list2 (Qexit, make_number (256))); 5458 list2 (Qexit, make_number (256)));
5496 } 5459 }
5497 } 5460 }
5498#ifdef NON_BLOCKING_CONNECT
5499 if (FD_ISSET (channel, &Writeok) 5461 if (FD_ISSET (channel, &Writeok)
5500 && FD_ISSET (channel, &connect_wait_mask)) 5462 && FD_ISSET (channel, &connect_wait_mask))
5501 { 5463 {
@@ -5568,7 +5530,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
5568 } 5530 }
5569 } 5531 }
5570 } 5532 }
5571#endif /* NON_BLOCKING_CONNECT */
5572 } /* End for each file descriptor. */ 5533 } /* End for each file descriptor. */
5573 } /* End while exit conditions not met. */ 5534 } /* End while exit conditions not met. */
5574 5535
@@ -7780,10 +7741,8 @@ init_process_emacs (void)
7780 max_process_desc = max_input_desc = -1; 7741 max_process_desc = max_input_desc = -1;
7781 memset (fd_callback_info, 0, sizeof (fd_callback_info)); 7742 memset (fd_callback_info, 0, sizeof (fd_callback_info));
7782 7743
7783#ifdef NON_BLOCKING_CONNECT
7784 FD_ZERO (&connect_wait_mask); 7744 FD_ZERO (&connect_wait_mask);
7785 num_pending_connects = 0; 7745 num_pending_connects = 0;
7786#endif
7787 7746
7788 process_output_delay_count = 0; 7747 process_output_delay_count = 0;
7789 process_output_skip = 0; 7748 process_output_skip = 0;
@@ -8036,9 +7995,7 @@ The variable takes effect when `start-process' is called. */);
8036#define ADD_SUBFEATURE(key, val) \ 7995#define ADD_SUBFEATURE(key, val) \
8037 subfeatures = pure_cons (pure_cons (key, pure_cons (val, Qnil)), subfeatures) 7996 subfeatures = pure_cons (pure_cons (key, pure_cons (val, Qnil)), subfeatures)
8038 7997
8039#ifdef NON_BLOCKING_CONNECT
8040 ADD_SUBFEATURE (QCnowait, Qt); 7998 ADD_SUBFEATURE (QCnowait, Qt);
8041#endif
8042#ifdef DATAGRAM_SOCKETS 7999#ifdef DATAGRAM_SOCKETS
8043 ADD_SUBFEATURE (QCtype, Qdatagram); 8000 ADD_SUBFEATURE (QCtype, Qdatagram);
8044#endif 8001#endif