aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer1995-01-23 23:26:29 +0000
committerKarl Heuer1995-01-23 23:26:29 +0000
commit86d1f23addb6df5f0b64b9ae93d699e24a06070c (patch)
treea7806cca399d7664dded784ab78031022580a461 /src
parent5886acf9ae69668883973a39db9176fa99c1d1c0 (diff)
downloademacs-86d1f23addb6df5f0b64b9ae93d699e24a06070c.tar.gz
emacs-86d1f23addb6df5f0b64b9ae93d699e24a06070c.zip
(sys_select): Renamed from select. Use SELECT_TYPE instead of int. Defer to
native select if that function is usable.
Diffstat (limited to 'src')
-rw-r--r--src/sysdep.c58
1 files changed, 39 insertions, 19 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index e4ef51e519f..8dfb60d59ea 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2197,9 +2197,12 @@ init_system_name ()
2197} 2197}
2198 2198
2199#ifndef VMS 2199#ifndef VMS
2200#ifndef HAVE_SELECT 2200#if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2201 2201
2202#ifdef HAVE_X_WINDOWS 2202#include "sysselect.h"
2203#undef select
2204
2205#if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2203/* Cause explanatory error message at compile time, 2206/* Cause explanatory error message at compile time,
2204 since the select emulation is not good enough for X. */ 2207 since the select emulation is not good enough for X. */
2205int *x = &x_windows_lose_if_no_select_system_call; 2208int *x = &x_windows_lose_if_no_select_system_call;
@@ -2237,13 +2240,15 @@ select_alarm ()
2237#ifndef WINDOWSNT 2240#ifndef WINDOWSNT
2238/* Only rfds are checked. */ 2241/* Only rfds are checked. */
2239int 2242int
2240select (nfds, rfds, wfds, efds, timeout) 2243sys_select (nfds, rfds, wfds, efds, timeout)
2241 int nfds; 2244 int nfds;
2242 int *rfds, *wfds, *efds, *timeout; 2245 SELECT_TYPE *rfds, *wfds, *efds;
2246 EMACS_TIME *timeout;
2243{ 2247{
2244 int ravail = 0, orfds = 0, old_alarm; 2248 int ravail = 0, old_alarm;
2245 int timeoutval = timeout ? *timeout : 100000; 2249 SELECT_TYPE orfds;
2246 int *local_timeout = &timeoutval; 2250 int timeoutval;
2251 int *local_timeout;
2247 extern int proc_buffered_char[]; 2252 extern int proc_buffered_char[];
2248#ifndef subprocesses 2253#ifndef subprocesses
2249 int process_tick = 0, update_tick = 0; 2254 int process_tick = 0, update_tick = 0;
@@ -2253,43 +2258,58 @@ select (nfds, rfds, wfds, efds, timeout)
2253 SIGTYPE (*old_trap) (); 2258 SIGTYPE (*old_trap) ();
2254 unsigned char buf; 2259 unsigned char buf;
2255 2260
2261#if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2262 /* If we're using X, then the native select will work; we only need the
2263 emulation for non-X usage. */
2264 if (!NILP (Vwindow_system))
2265 return select (nfds, rfds, wfds, efds, timeout);
2266#endif
2267 timeoutval = timeout ? EMACS_SECS (*timeout) : 100000;
2268 local_timeout = &timeoutval;
2269 FD_ZERO (&orfds);
2256 if (rfds) 2270 if (rfds)
2257 { 2271 {
2258 orfds = *rfds; 2272 orfds = *rfds;
2259 *rfds = 0; 2273 FD_ZERO (rfds);
2260 } 2274 }
2261 if (wfds) 2275 if (wfds)
2262 *wfds = 0; 2276 FD_ZERO (wfds);
2263 if (efds) 2277 if (efds)
2264 *efds = 0; 2278 FD_ZERO (efds);
2265 2279
2266 /* If we are looking only for the terminal, with no timeout, 2280 /* If we are looking only for the terminal, with no timeout,
2267 just read it and wait -- that's more efficient. */ 2281 just read it and wait -- that's more efficient. */
2268 if (orfds == 1 && *local_timeout == 100000 && process_tick == update_tick) 2282 if (*local_timeout == 100000 && process_tick == update_tick
2283 && FD_ISSET (0, &orfds))
2269 { 2284 {
2285 int fd;
2286 for (fd = 1; fd < nfds; ++fd)
2287 if (FD_ISSET (fd, &orfds))
2288 goto hardway;
2270 if (! detect_input_pending ()) 2289 if (! detect_input_pending ())
2271 read_input_waiting (); 2290 read_input_waiting ();
2272 *rfds = 1; 2291 FD_SET (0, rfds);
2273 return 1; 2292 return 1;
2274 } 2293 }
2275 2294
2295 hardway:
2276 /* Once a second, till the timer expires, check all the flagged read 2296 /* Once a second, till the timer expires, check all the flagged read
2277 * descriptors to see if any input is available. If there is some then 2297 * descriptors to see if any input is available. If there is some then
2278 * set the corresponding bit in the return copy of rfds. 2298 * set the corresponding bit in the return copy of rfds.
2279 */ 2299 */
2280 while (1) 2300 while (1)
2281 { 2301 {
2282 register int to_check, bit, fd; 2302 register int to_check, fd;
2283 2303
2284 if (rfds) 2304 if (rfds)
2285 { 2305 {
2286 for (to_check = nfds, bit = 1, fd = 0; --to_check >= 0; bit <<= 1, fd++) 2306 for (to_check = nfds, fd = 0; --to_check >= 0; fd++)
2287 { 2307 {
2288 if (orfds & bit) 2308 if (FD_ISSET (fd, &orfds))
2289 { 2309 {
2290 int avail = 0, status = 0; 2310 int avail = 0, status = 0;
2291 2311
2292 if (bit == 1) 2312 if (fd == 0)
2293 avail = detect_input_pending (); /* Special keyboard handler */ 2313 avail = detect_input_pending (); /* Special keyboard handler */
2294 else 2314 else
2295 { 2315 {
@@ -2314,7 +2334,7 @@ select (nfds, rfds, wfds, efds, timeout)
2314 } 2334 }
2315 if (status >= 0 && avail > 0) 2335 if (status >= 0 && avail > 0)
2316 { 2336 {
2317 (*rfds) |= bit; 2337 FD_SET (fd, rfds);
2318 ravail++; 2338 ravail++;
2319 } 2339 }
2320 } 2340 }
@@ -2331,13 +2351,13 @@ select (nfds, rfds, wfds, efds, timeout)
2331 && process_tick == update_tick) 2351 && process_tick == update_tick)
2332 { 2352 {
2333#ifdef MSDOS 2353#ifdef MSDOS
2334 sleep_or_kbd_hit (SELECT_PAUSE, (orfds & 1) != 0); 2354 sleep_or_kbd_hit (SELECT_PAUSE, FD_ISSET (0, &orfds) != 0);
2335 select_alarm (); 2355 select_alarm ();
2336#else /* not MSDOS */ 2356#else /* not MSDOS */
2337 /* If we are interested in terminal input, 2357 /* If we are interested in terminal input,
2338 wait by reading the terminal. 2358 wait by reading the terminal.
2339 That makes instant wakeup for terminal input at least. */ 2359 That makes instant wakeup for terminal input at least. */
2340 if (orfds & 1) 2360 if (FD_ISSET (0, &orfds))
2341 { 2361 {
2342 read_input_waiting (); 2362 read_input_waiting ();
2343 if (detect_input_pending ()) 2363 if (detect_input_pending ())