comparison src/event-unixoid.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents fdefd0186b75
children e38acbeb1cae
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
1 /* Code shared between all event loops that use select() and have a 1 /* Code shared between all event loops that use select() and have a
2 different input descriptor for each device. 2 different input descriptor for each device.
3 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 3 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
4 Copyright (C) 1995 Board of Trustees, University of Illinois. 4 Copyright (C) 1995 Board of Trustees, University of Illinois.
5 Copyright (C) 1995 Sun Microsystems, Inc. 5 Copyright (C) 1995 Sun Microsystems, Inc.
6 Copyright (C) 1995, 1996 Ben Wing. 6 Copyright (C) 1995, 1996, 2001 Ben Wing.
7 7
8 This file is part of XEmacs. 8 This file is part of XEmacs.
9 9
10 XEmacs is free software; you can redistribute it and/or modify it 10 XEmacs is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the 11 under the terms of the GNU General Public License as published by the
69 int signal_event_pipe_initialized; 69 int signal_event_pipe_initialized;
70 70
71 int fake_event_occurred; 71 int fake_event_occurred;
72 72
73 int 73 int
74 read_event_from_tty_or_stream_desc (Lisp_Event *event, 74 read_event_from_tty_or_stream_desc (Lisp_Event *event, struct console *con)
75 struct console *con, int fd) 75 {
76 { 76 Emchar ch;
77 unsigned char ch;
78 int nread;
79 Lisp_Object console; 77 Lisp_Object console;
80 78
81 XSETCONSOLE (console, con); 79 XSETCONSOLE (console, con);
82 80
83 nread = read (fd, &ch, 1); 81 if (CONSOLE_TTY_P (con))
84 if (nread <= 0) 82 ch = Lstream_get_emchar (XLSTREAM (CONSOLE_TTY_DATA (con)->instream));
83 else
84 {
85 /* #### Definitely something strange here. We should be setting
86 the stdio handle unbuffered and reading from it instead of mixing
87 stdio and raw io calls. */
88 int nread = retry_read (fileno (CONSOLE_STREAM_DATA (con)->in), &ch, 1);
89 if (nread <= 0)
90 ch = -1;
91 }
92
93 if (ch < 0)
85 { 94 {
86 /* deleting the console might not be safe right now ... */ 95 /* deleting the console might not be safe right now ... */
87 enqueue_magic_eval_event (io_error_delete_console, console); 96 enqueue_magic_eval_event (io_error_delete_console, console);
88 /* but we definitely need to unselect it to avoid infinite 97 /* but we definitely need to unselect it to avoid infinite
89 loops reading EOF's */ 98 loops reading EOF's */
108 if the signal occurs after we've checked for the signal 117 if the signal occurs after we've checked for the signal
109 occurrence (which could occur in many places throughout 118 occurrence (which could occur in many places throughout
110 an iteration of the command loop, e.g. in status_notify()), 119 an iteration of the command loop, e.g. in status_notify()),
111 but before we set the blocking flag. 120 but before we set the blocking flag.
112 121
113 This should be OK as long as write() is reentrant, which 122 This should be OK as long as write() is reentrant, which I'm fairly
114 I'm fairly sure it is since it's a system call. */ 123 sure it is since it's a system call. */
115 124
116 if (signal_event_pipe_initialized) 125 if (signal_event_pipe_initialized)
117 /* In case a signal comes through while we're dumping */ 126 /* In case a signal comes through while we're dumping */
118 { 127 {
119 int old_errno = errno; 128 int old_errno = errno;
120 write (signal_event_pipe[1], &byte, 1); 129 retry_write (signal_event_pipe[1], &byte, 1);
121 errno = old_errno; 130 errno = old_errno;
122 } 131 }
123 } 132 }
124 133
125 void 134 void
126 drain_signal_event_pipe (void) 135 drain_signal_event_pipe (void)
127 { 136 {
128 char chars[128]; 137 char chars[128];
129 /* The input end of the pipe has been set to non-blocking. */ 138 /* The input end of the pipe has been set to non-blocking. */
130 while (read (signal_event_pipe[0], chars, sizeof (chars)) > 0) 139 while (retry_read (signal_event_pipe[0], chars, sizeof (chars)) > 0)
131 ; 140 ;
132 } 141 }
133 142
134 int 143 int
135 event_stream_unixoid_select_console (struct console *con) 144 event_stream_unixoid_select_console (struct console *con)
262 { 271 {
263 outfd = open_osfhandle ((HANDLE)outhandle, 0); 272 outfd = open_osfhandle ((HANDLE)outhandle, 0);
264 if (outfd < 0) 273 if (outfd < 0)
265 { 274 {
266 if (infd >= 0) 275 if (infd >= 0)
267 close (infd); 276 retry_close (infd);
268 return USID_ERROR; 277 return USID_ERROR;
269 } 278 }
270 } 279 }
271 else 280 else
272 outfd = -1; 281 outfd = -1;
309 : filedesc_stream_fd (XLSTREAM (instream))); 318 : filedesc_stream_fd (XLSTREAM (instream)));
310 int out = (NILP(outstream) ? -1 319 int out = (NILP(outstream) ? -1
311 : filedesc_stream_fd (XLSTREAM (outstream))); 320 : filedesc_stream_fd (XLSTREAM (outstream)));
312 321
313 if (in >= 0) 322 if (in >= 0)
314 close (in); 323 retry_close (in);
315 if (out != in && out >= 0) 324 if (out != in && out >= 0)
316 close (out); 325 retry_close (out);
317 326
318 return FD_TO_USID (in); 327 return FD_TO_USID (in);
319 } 328 }
320 329
321 330