comparison src/sysdep.c @ 10528:e020d8d5dc2c

(sys_select): Renamed from select. Use SELECT_TYPE instead of int. Defer to native select if that function is usable.
author Karl Heuer <kwzh@gnu.org>
date Mon, 23 Jan 1995 23:26:29 +0000
parents 0028c532b70b
children aa943e2ea495
comparison
equal deleted inserted replaced
10527:68b8191091a7 10528:e020d8d5dc2c
2195 *p = '-'; 2195 *p = '-';
2196 } 2196 }
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. */
2205 int *x = &x_windows_lose_if_no_select_system_call; 2208 int *x = &x_windows_lose_if_no_select_system_call;
2206 #endif 2209 #endif
2207 2210
2235 } 2238 }
2236 2239
2237 #ifndef WINDOWSNT 2240 #ifndef WINDOWSNT
2238 /* Only rfds are checked. */ 2241 /* Only rfds are checked. */
2239 int 2242 int
2240 select (nfds, rfds, wfds, efds, timeout) 2243 sys_select (nfds, rfds, wfds, efds, timeout)
2241 int nfds; 2244 int nfds;
2242 int *rfds, *wfds, *efds, *timeout; 2245 SELECT_TYPE *rfds, *wfds, *efds;
2243 { 2246 EMACS_TIME *timeout;
2244 int ravail = 0, orfds = 0, old_alarm; 2247 {
2245 int timeoutval = timeout ? *timeout : 100000; 2248 int ravail = 0, old_alarm;
2246 int *local_timeout = &timeoutval; 2249 SELECT_TYPE orfds;
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;
2250 #else 2255 #else
2251 extern int process_tick, update_tick; 2256 extern int process_tick, update_tick;
2252 #endif 2257 #endif
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
2269 { 2283 && FD_ISSET (0, &orfds))
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 {
2296 #ifdef FIONREAD 2316 #ifdef FIONREAD
2297 status = ioctl (fd, FIONREAD, &avail); 2317 status = ioctl (fd, FIONREAD, &avail);
2312 #endif /* not MSDOS */ 2332 #endif /* not MSDOS */
2313 #endif /* no FIONREAD */ 2333 #endif /* no FIONREAD */
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 }
2321 } 2341 }
2322 } 2342 }
2329 /* Wait for a SIGALRM (or maybe a SIGTINT) */ 2349 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2330 while (select_alarmed == 0 && *local_timeout != 0 2350 while (select_alarmed == 0 && *local_timeout != 0
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 ())
2344 select_alarmed = 1; 2364 select_alarmed = 1;
2345 } 2365 }