Mercurial > hg > xemacs-beta
comparison src/event-unixoid.c @ 263:727739f917cb r20-5b30
Import from CVS: tag r20-5b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:24:41 +0200 |
parents | 3d6bfa290dbd |
children | 966663fcf606 |
comparison
equal
deleted
inserted
replaced
262:9d8607af9e13 | 263:727739f917cb |
---|---|
31 | 31 |
32 #include "console-stream.h" | 32 #include "console-stream.h" |
33 #include "console-tty.h" | 33 #include "console-tty.h" |
34 #include "device.h" | 34 #include "device.h" |
35 #include "events.h" | 35 #include "events.h" |
36 #include "lstream.h" | |
36 #include "process.h" | 37 #include "process.h" |
37 | 38 |
38 #include "sysdep.h" | 39 #include "sysdep.h" |
39 #include "sysproc.h" /* select stuff */ | 40 #include "sysproc.h" /* select stuff */ |
40 #include "systime.h" | 41 #include "systime.h" |
98 loops reading EOF's */ | 99 loops reading EOF's */ |
99 Fconsole_disable_input (console); | 100 Fconsole_disable_input (console); |
100 } | 101 } |
101 else | 102 else |
102 { | 103 { |
103 character_to_event (ch, event, con, 1); | 104 character_to_event (ch, event, con, 1, 1); |
104 event->channel = console; | 105 event->channel = console; |
105 return 1; | 106 return 1; |
106 } | 107 } |
107 return 0; | 108 return 0; |
108 } | 109 } |
180 FD_CLR (infd, &non_fake_input_wait_mask); | 181 FD_CLR (infd, &non_fake_input_wait_mask); |
181 FD_CLR (infd, &tty_only_mask); | 182 FD_CLR (infd, &tty_only_mask); |
182 return infd; | 183 return infd; |
183 } | 184 } |
184 | 185 |
186 static int | |
187 get_process_infd (struct Lisp_Process *p) | |
188 { | |
189 Lisp_Object instr, outstr; | |
190 get_process_streams (p, &instr, &outstr); | |
191 assert (!NILP (instr)); | |
192 return filedesc_stream_fd (XLSTREAM (instr)); | |
193 } | |
194 | |
185 int | 195 int |
186 event_stream_unixoid_select_process (struct Lisp_Process *proc) | 196 event_stream_unixoid_select_process (struct Lisp_Process *proc) |
187 { | 197 { |
188 int infd, outfd; | 198 int infd = get_process_infd (proc); |
189 | |
190 get_process_file_descriptors (proc, &infd, &outfd); | |
191 assert (infd >= 0); | |
192 | 199 |
193 FD_SET (infd, &input_wait_mask); | 200 FD_SET (infd, &input_wait_mask); |
194 FD_SET (infd, &non_fake_input_wait_mask); | 201 FD_SET (infd, &non_fake_input_wait_mask); |
195 FD_SET (infd, &process_only_mask); | 202 FD_SET (infd, &process_only_mask); |
196 return infd; | 203 return infd; |
197 } | 204 } |
198 | 205 |
199 int | 206 int |
200 event_stream_unixoid_unselect_process (struct Lisp_Process *proc) | 207 event_stream_unixoid_unselect_process (struct Lisp_Process *proc) |
201 { | 208 { |
202 int infd, outfd; | 209 int infd = get_process_infd (proc); |
203 | |
204 get_process_file_descriptors (proc, &infd, &outfd); | |
205 assert (infd >= 0); | |
206 | 210 |
207 FD_CLR (infd, &input_wait_mask); | 211 FD_CLR (infd, &input_wait_mask); |
208 FD_CLR (infd, &non_fake_input_wait_mask); | 212 FD_CLR (infd, &non_fake_input_wait_mask); |
209 FD_CLR (infd, &process_only_mask); | 213 FD_CLR (infd, &process_only_mask); |
210 return infd; | 214 return infd; |
237 /* else, we got interrupted by a signal, so try again. */ | 241 /* else, we got interrupted by a signal, so try again. */ |
238 } | 242 } |
239 | 243 |
240 RETURN_NOT_REACHED(0) /* not reached */ | 244 RETURN_NOT_REACHED(0) /* not reached */ |
241 } | 245 } |
246 | |
247 /****************************************************************************/ | |
248 /* Unixoid (file descriptors based) process I/O streams routines */ | |
249 /****************************************************************************/ | |
250 | |
251 USID | |
252 event_stream_unixoid_create_stream_pair (void* inhandle, void* outhandle, | |
253 Lisp_Object* instream, | |
254 Lisp_Object* outstream, | |
255 int flags) | |
256 { | |
257 int infd, outfd; | |
258 /* Decode inhandle and outhandle. Their meaning depends on | |
259 the process implementation being used. */ | |
260 #ifdef HAVE_WIN32_PROCESSES | |
261 /* We're passed in Windows handles. Open new fds for them */ | |
262 if ((HANDLE)inhandle != INVALID_HANDLE_VALUE) | |
263 { | |
264 infd = open_osfhandle ((HANDLE)inhandle, 0); | |
265 if (infd < 0) | |
266 return USID_ERROR; | |
267 } | |
268 else | |
269 infd = -1; | |
270 | |
271 if ((HANDLE)outhandle != INVALID_HANDLE_VALUE) | |
272 { | |
273 outfd = open_osfhandle ((HANDLE)outhandle, 0); | |
274 if (outfd < 0) | |
275 { | |
276 if (infd >= 0) | |
277 close (infd); | |
278 return USID_ERROR; | |
279 } | |
280 } | |
281 else | |
282 outfd = -1; | |
283 | |
284 flags = 0; | |
285 #endif | |
286 | |
287 #ifdef HAVE_UNIX_PROCESSES | |
288 /* We are passed plain old file descs */ | |
289 infd = (int)inhandle; | |
290 outfd = (int)outhandle; | |
291 #endif | |
292 | |
293 *instream = (infd >= 0 | |
294 ? make_filedesc_input_stream (infd, 0, -1, 0) | |
295 : Qnil); | |
296 | |
297 *outstream = (outfd >= 0 | |
298 ? make_filedesc_output_stream (outfd, 0, -1, LSTR_BLOCKED_OK) | |
299 : Qnil); | |
300 | |
301 #if defined(HAVE_UNIX_PROCESSES) && defined(HAVE_PTYS) | |
302 /* FLAGS is process->pty_flag for UNIX_PROCESSES */ | |
303 if (flags && outfd >= 0) | |
304 { | |
305 Bufbyte eof_char = get_eof_char (outfd); | |
306 int pty_max_bytes = get_pty_max_bytes (outfd); | |
307 filedesc_stream_set_pty_flushing (XLSTREAM(*outstream), pty_max_bytes, eof_char); | |
308 } | |
309 #endif | |
310 | |
311 return FD_TO_USID (infd); | |
312 } | |
313 | |
314 USID | |
315 event_stream_unixoid_delete_stream_pair (Lisp_Object instream, | |
316 Lisp_Object outstream) | |
317 { | |
318 int in = (NILP(instream) ? -1 | |
319 : filedesc_stream_fd (XLSTREAM (instream))); | |
320 int out = (NILP(outstream) ? -1 | |
321 : filedesc_stream_fd (XLSTREAM (outstream))); | |
322 | |
323 if (in >= 0) | |
324 close (in); | |
325 if (out != in && out >= 0) | |
326 close (out); | |
327 | |
328 if (!NILP (instream)) | |
329 Lstream_close (XLSTREAM (instream)); | |
330 if (!NILP (outstream)) | |
331 Lstream_close (XLSTREAM (outstream)); | |
332 | |
333 return FD_TO_USID (in); | |
334 } | |
242 | 335 |
243 | 336 |
244 void | 337 void |
245 init_event_unixoid (void) | 338 init_event_unixoid (void) |
246 { | 339 { |