comparison src/process.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 41dbb7a9d5f2
children
comparison
equal deleted inserted replaced
423:28d9c139be4c 424:11054d720c21
69 /* Valid values of process->status_symbol */ 69 /* Valid values of process->status_symbol */
70 Lisp_Object Qrun, Qstop; 70 Lisp_Object Qrun, Qstop;
71 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */ 71 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
72 Lisp_Object Qopen, Qclosed; 72 Lisp_Object Qopen, Qclosed;
73 /* Protocol families */ 73 /* Protocol families */
74 Lisp_Object Qtcpip; 74 Lisp_Object Qtcp, Qudp;
75 75
76 #ifdef HAVE_MULTICAST 76 #ifdef HAVE_MULTICAST
77 Lisp_Object Qmulticast; /* Will be used for occasional warnings */ 77 Lisp_Object Qmulticast; /* Will be used for occasional warnings */
78 #endif 78 #endif
79 79
109 extern Lisp_Object Vlisp_EXEC_SUFFIXES; 109 extern Lisp_Object Vlisp_EXEC_SUFFIXES;
110 110
111 111
112 112
113 static Lisp_Object 113 static Lisp_Object
114 mark_process (Lisp_Object obj, void (*markobj) (Lisp_Object)) 114 mark_process (Lisp_Object obj)
115 { 115 {
116 struct Lisp_Process *proc = XPROCESS (obj); 116 struct Lisp_Process *proc = XPROCESS (obj);
117 MAYBE_PROCMETH (mark_process_data, (proc, markobj)); 117 MAYBE_PROCMETH (mark_process_data, (proc));
118 markobj (proc->name); 118 mark_object (proc->name);
119 markobj (proc->command); 119 mark_object (proc->command);
120 markobj (proc->filter); 120 mark_object (proc->filter);
121 markobj (proc->sentinel); 121 mark_object (proc->sentinel);
122 markobj (proc->buffer); 122 mark_object (proc->buffer);
123 markobj (proc->mark); 123 mark_object (proc->mark);
124 markobj (proc->pid); 124 mark_object (proc->pid);
125 markobj (proc->pipe_instream); 125 mark_object (proc->pipe_instream);
126 markobj (proc->pipe_outstream); 126 mark_object (proc->pipe_outstream);
127 #ifdef FILE_CODING 127 #ifdef FILE_CODING
128 markobj (proc->coding_instream); 128 mark_object (proc->coding_instream);
129 markobj (proc->coding_outstream); 129 mark_object (proc->coding_outstream);
130 #endif 130 #endif
131 return proc->status_symbol; 131 return proc->status_symbol;
132 } 132 }
133 133
134 static void 134 static void
243 243
244 #ifdef HAVE_SOCKETS 244 #ifdef HAVE_SOCKETS
245 int 245 int
246 network_connection_p (Lisp_Object process) 246 network_connection_p (Lisp_Object process)
247 { 247 {
248 return GC_CONSP (XPROCESS (process)->pid); 248 return CONSP (XPROCESS (process)->pid);
249 } 249 }
250 #endif 250 #endif
251 251
252 DEFUN ("processp", Fprocessp, 1, 1, 0, /* 252 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
253 Return t if OBJECT is a process. 253 Return t if OBJECT is a process.
270 */ 270 */
271 (name)) 271 (name))
272 { 272 {
273 Lisp_Object tail; 273 Lisp_Object tail;
274 274
275 if (GC_PROCESSP (name)) 275 if (PROCESSP (name))
276 return name; 276 return name;
277 277
278 if (!gc_in_progress) 278 if (!gc_in_progress)
279 /* this only gets called during GC when emacs is going away as a result 279 /* this only gets called during GC when emacs is going away as a result
280 of a signal or crash. */ 280 of a signal or crash. */
281 CHECK_STRING (name); 281 CHECK_STRING (name);
282 282
283 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail)) 283 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
284 { 284 {
285 Lisp_Object proc = XCAR (tail); 285 Lisp_Object proc = XCAR (tail);
286 QUIT; 286 QUIT;
287 if (internal_equal (name, XPROCESS (proc)->name, 0)) 287 if (internal_equal (name, XPROCESS (proc)->name, 0))
288 return XCAR (tail); 288 return XCAR (tail);
296 */ 296 */
297 (name)) 297 (name))
298 { 298 {
299 Lisp_Object buf, tail, proc; 299 Lisp_Object buf, tail, proc;
300 300
301 if (GC_NILP (name)) return Qnil; 301 if (NILP (name)) return Qnil;
302 buf = Fget_buffer (name); 302 buf = Fget_buffer (name);
303 if (GC_NILP (buf)) return Qnil; 303 if (NILP (buf)) return Qnil;
304 304
305 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail)) 305 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
306 { 306 {
307 /* jwz: do not quit here - it isn't necessary, as there is no way for 307 /* jwz: do not quit here - it isn't necessary, as there is no way for
308 Vprocess_list to get circular or overwhelmingly long, and this 308 Vprocess_list to get circular or overwhelmingly long, and this
309 function is called from layout_mode_element under redisplay. */ 309 function is called from layout_mode_element under redisplay. */
310 /* QUIT; */ 310 /* QUIT; */
311 proc = XCAR (tail); 311 proc = XCAR (tail);
312 if (GC_PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf)) 312 if (PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
313 return proc; 313 return proc;
314 } 314 }
315 return Qnil; 315 return Qnil;
316 } 316 }
317 317
329 /* #### Look more closely into translating process names. */ 329 /* #### Look more closely into translating process names. */
330 #endif 330 #endif
331 331
332 /* This may be called during a GC from process_send_signal() from 332 /* This may be called during a GC from process_send_signal() from
333 kill_buffer_processes() if emacs decides to abort(). */ 333 kill_buffer_processes() if emacs decides to abort(). */
334 if (GC_PROCESSP (name)) 334 if (PROCESSP (name))
335 return name; 335 return name;
336 336
337 if (GC_STRINGP (name)) 337 if (STRINGP (name))
338 { 338 {
339 obj = Fget_process (name); 339 obj = Fget_process (name);
340 if (GC_NILP (obj)) 340 if (NILP (obj))
341 obj = Fget_buffer (name); 341 obj = Fget_buffer (name);
342 if (GC_NILP (obj)) 342 if (NILP (obj))
343 error ("Process %s does not exist", XSTRING_DATA (name)); 343 error ("Process %s does not exist", XSTRING_DATA (name));
344 } 344 }
345 else if (GC_NILP (name)) 345 else if (NILP (name))
346 obj = Fcurrent_buffer (); 346 obj = Fcurrent_buffer ();
347 else 347 else
348 obj = name; 348 obj = name;
349 349
350 /* Now obj should be either a buffer object or a process object. 350 /* Now obj should be either a buffer object or a process object.
351 */ 351 */
352 if (GC_BUFFERP (obj)) 352 if (BUFFERP (obj))
353 { 353 {
354 proc = Fget_buffer_process (obj); 354 proc = Fget_buffer_process (obj);
355 if (GC_NILP (proc)) 355 if (NILP (proc))
356 error ("Buffer %s has no process", XSTRING_DATA (XBUFFER(obj)->name)); 356 error ("Buffer %s has no process", XSTRING_DATA (XBUFFER(obj)->name));
357 } 357 }
358 else 358 else
359 { 359 {
360 /* #### This was commented out. Although, simple 360 /* #### This was commented out. Although, simple
657 connection has no PID; you cannot signal it. All you can do is 657 connection has no PID; you cannot signal it. All you can do is
658 deactivate and close it via delete-process */ 658 deactivate and close it via delete-process */
659 659
660 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 5, 0, /* 660 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 5, 0, /*
661 Open a TCP connection for a service to a host. 661 Open a TCP connection for a service to a host.
662 Returns a subprocess-object to represent the connection. 662 Return a subprocess-object to represent the connection.
663 Input and output work as for subprocesses; `delete-process' closes it. 663 Input and output work as for subprocesses; `delete-process' closes it.
664 664
665 NAME is name for process. It is modified if necessary to make it unique. 665 NAME is name for process. It is modified if necessary to make it unique.
666 BUFFER is the buffer (or buffer-name) to associate with the process. 666 BUFFER is the buffer (or buffer-name) to associate with the process.
667 Process output goes at end of that buffer, unless you specify 667 Process output goes at end of that buffer, unless you specify
669 BUFFER may also be nil, meaning that this process is not associated 669 BUFFER may also be nil, meaning that this process is not associated
670 with any buffer. 670 with any buffer.
671 Third arg is name of the host to connect to, or its IP address. 671 Third arg is name of the host to connect to, or its IP address.
672 Fourth arg SERVICE is name of the service desired, or an integer 672 Fourth arg SERVICE is name of the service desired, or an integer
673 specifying a port number to connect to. 673 specifying a port number to connect to.
674 Fifth argument FAMILY is a protocol family. When omitted, 'tcp/ip 674 Fifth argument PROTOCOL is a network protocol. Currently 'tcp
675 \(Internet protocol family TCP/IP) is assumed. 675 (Transmission Control Protocol) and 'udp (User Datagram Protocol) are
676 */ 676 supported. When omitted, 'tcp is assumed.
677 (name, buffer, host, service, family)) 677
678 Ouput via `process-send-string' and input via buffer or filter (see
679 `set-process-filter') are stream-oriented. That means UDP datagrams are
680 not guaranteed to be sent and received in discrete packets. (But small
681 datagrams around 500 bytes that are not truncated by `process-send-string'
682 are usually fine.) Note further that UDP protocol does not guard against
683 lost packets.
684 */
685 (name, buffer, host, service, protocol))
678 { 686 {
679 /* !!#### This function has not been Mule-ized */ 687 /* !!#### This function has not been Mule-ized */
680 /* This function can GC */ 688 /* This function can GC */
681 Lisp_Object proc = Qnil; 689 Lisp_Object proc = Qnil;
682 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, ngcpro1; 690 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, ngcpro1;
683 void *inch, *outch; 691 void *inch, *outch;
684 692
685 GCPRO5 (name, buffer, host, service, family); 693 GCPRO5 (name, buffer, host, service, protocol);
686 CHECK_STRING (name); 694 CHECK_STRING (name);
687 695
688 if (NILP(family)) 696 if (NILP(protocol))
689 family = Qtcpip; 697 protocol = Qtcp;
690 else 698 else
691 CHECK_SYMBOL (family); 699 CHECK_SYMBOL (protocol);
692 700
693 /* Since this code is inside HAVE_SOCKETS, existence of 701 /* Since this code is inside HAVE_SOCKETS, existence of
694 open_network_stream is mandatory */ 702 open_network_stream is mandatory */
695 PROCMETH (open_network_stream, (name, host, service, family, 703 PROCMETH (open_network_stream, (name, host, service, protocol,
696 &inch, &outch)); 704 &inch, &outch));
697 705
698 if (!NILP (buffer)) 706 if (!NILP (buffer))
699 buffer = Fget_buffer_create (buffer); 707 buffer = Fget_buffer_create (buffer);
700 proc = make_process_internal (name); 708 proc = make_process_internal (name);
714 722
715 #ifdef HAVE_MULTICAST 723 #ifdef HAVE_MULTICAST
716 724
717 DEFUN ("open-multicast-group-internal", Fopen_multicast_group_internal, 5, 5, 0, /* 725 DEFUN ("open-multicast-group-internal", Fopen_multicast_group_internal, 5, 5, 0, /*
718 Open a multicast connection on the specified dest/port/ttl. 726 Open a multicast connection on the specified dest/port/ttl.
719 Returns a subprocess-object to represent the connection. 727 Return a subprocess-object to represent the connection.
720 Input and output work as for subprocesses; `delete-process' closes it. 728 Input and output work as for subprocesses; `delete-process' closes it.
721 729
722 NAME is name for process. It is modified if necessary to make it unique. 730 NAME is name for process. It is modified if necessary to make it unique.
723 BUFFER is the buffer (or buffer-name) to associate with the process. 731 BUFFER is the buffer (or buffer-name) to associate with the process.
724 Process output goes at end of that buffer, unless you specify 732 Process output goes at end of that buffer, unless you specify
963 signal_simple_error ("Process not open for writing", proc); 971 signal_simple_error ("Process not open for writing", proc);
964 972
965 if (nonrelocatable) 973 if (nonrelocatable)
966 lstream = 974 lstream =
967 make_fixed_buffer_input_stream (nonrelocatable + start, len); 975 make_fixed_buffer_input_stream (nonrelocatable + start, len);
968 else if (GC_BUFFERP (relocatable)) 976 else if (BUFFERP (relocatable))
969 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable), 977 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
970 start, start + len, 0); 978 start, start + len, 0);
971 else 979 else
972 lstream = make_lisp_string_input_stream (relocatable, start, len); 980 lstream = make_lisp_string_input_stream (relocatable, start, len);
973 981
1896 void 1904 void
1897 kill_buffer_processes (Lisp_Object buffer) 1905 kill_buffer_processes (Lisp_Object buffer)
1898 { 1906 {
1899 Lisp_Object tail; 1907 Lisp_Object tail;
1900 1908
1901 for (tail = Vprocess_list; GC_CONSP (tail); 1909 for (tail = Vprocess_list; CONSP (tail);
1902 tail = XCDR (tail)) 1910 tail = XCDR (tail))
1903 { 1911 {
1904 Lisp_Object proc = XCAR (tail); 1912 Lisp_Object proc = XCAR (tail);
1905 if (GC_PROCESSP (proc) 1913 if (PROCESSP (proc)
1906 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer))) 1914 && (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer)))
1907 { 1915 {
1908 if (network_connection_p (proc)) 1916 if (network_connection_p (proc))
1909 Fdelete_process (proc); 1917 Fdelete_process (proc);
1910 else if (!NILP (XPROCESS (proc)->pipe_instream)) 1918 else if (!NILP (XPROCESS (proc)->pipe_instream))
1911 process_send_signal (proc, SIGHUP, 0, 1); 1919 process_send_signal (proc, SIGHUP, 0, 1);
1973 defsymbol (&Qrun, "run"); 1981 defsymbol (&Qrun, "run");
1974 defsymbol (&Qstop, "stop"); 1982 defsymbol (&Qstop, "stop");
1975 defsymbol (&Qopen, "open"); 1983 defsymbol (&Qopen, "open");
1976 defsymbol (&Qclosed, "closed"); 1984 defsymbol (&Qclosed, "closed");
1977 1985
1978 defsymbol (&Qtcpip, "tcp/ip"); 1986 defsymbol (&Qtcp, "tcp");
1987 defsymbol (&Qudp, "udp");
1979 1988
1980 #ifdef HAVE_MULTICAST 1989 #ifdef HAVE_MULTICAST
1981 defsymbol(&Qmulticast, "multicast"); /* Used for occasional warnings */ 1990 defsymbol(&Qmulticast, "multicast"); /* Used for occasional warnings */
1982 #endif 1991 #endif
1983 1992