changeset 49164:8bee0ccd5fd6

(QCvars): New variable. (syms_of_process): Intern and staticpro it. (Fprocess_variable, Fset_process_variable): New functions. (syms_of_process): Defsubr them. (Fstart_process): Initialize private_vars plist to nil. (Fmake_network_process): New arg :vars to setup the private variables for new network process. (server_accept_connection): Copy server's private variables to client process.
author Kim F. Storm <storm@cua.dk>
date Sun, 12 Jan 2003 20:24:06 +0000
parents 5697f31e3ca6
children ab4091602937
files src/process.c
diffstat 1 files changed, 39 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/process.c	Sun Jan 12 20:23:45 2003 +0000
+++ b/src/process.c	Sun Jan 12 20:24:06 2003 +0000
@@ -132,7 +132,7 @@
 Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype;
 Lisp_Object QClocal, QCremote, QCcoding;
 Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
-Lisp_Object QCsentinel, QClog, QCoptions;
+Lisp_Object QCsentinel, QClog, QCoptions, QCvars;
 Lisp_Object Qlast_nonmenu_event;
 /* QCfamily is declared and initialized in xfaces.c,
    QCfilter in keyboard.c.  */
@@ -1037,20 +1037,34 @@
   return Fplist_get (contact, key);
 }
 
-DEFUN ("set-process-contact", Fset_process_contact, Sset_process_contact,
+DEFUN ("process-variable", Fprocess_variable, Sprocess_variable,
+       1, 2, 0,
+       doc: /* Return the value of PROCESS' private variable VAR.
+If VARIABLE is omitted or nil, return plist with all PROCESS variables.  */)
+     (process, var)
+     register Lisp_Object process, var;
+{
+  CHECK_PROCESS (process);
+
+  if (NILP (var))
+    return XPROCESS (process)->private_vars;
+
+  return Fplist_get (XPROCESS (process)->private_vars, var);
+}
+
+DEFUN ("set-process-variable", Fset_process_variable, Sset_process_variable,
        3, 3, 0,
-       doc: /* Change value in PROCESS' contact information list of KEY to VAL.
-If KEY is already a property on the list, its value is set to VAL,
-otherwise the new KEY VAL pair is added.  Returns VAL.  */)
-     (process, key, val)
-     register Lisp_Object process, key, val;
+       doc: /* Change value of PROCESS' private variable VAR to VAL, and return VAL.
+If VAR is nil, set all PROCESS' private variables according to plist VAL.  */)
+     (process, var, val)
+     register Lisp_Object process, var, val;
 {
-  Lisp_Object contact;
-
   CHECK_PROCESS (process);
 
-  if (NETCONN_P (process))
-    XPROCESS (process)->childp = Fplist_put (XPROCESS (process)->childp, key, val);
+  XPROCESS (process)->private_vars
+    = (NILP (var)
+       ? val
+       : Fplist_put (XPROCESS (process)->private_vars, var, val));
 
   return val;
 }
@@ -1420,6 +1434,7 @@
   record_unwind_protect (start_process_unwind, proc);
 
   XPROCESS (proc)->childp = Qt;
+  XPROCESS (proc)->private_vars = Qnil;
   XPROCESS (proc)->command_channel_p = Qnil;
   XPROCESS (proc)->buffer = buffer;
   XPROCESS (proc)->sentinel = Qnil;
@@ -2584,6 +2599,9 @@
 is the server process, CLIENT is the new process for the connection,
 and MESSAGE is a string.
 
+:vars VARS -- Initialize the process' private variables according to
+a list of variable/value pairs (VAR1 VAL1 VAR2 VAL2...).
+ 
 :server BOOL -- if BOOL is non-nil, create a server process for the
 specified FAMILY, SERVICE, and connection type (stream or datagram).
 Default is a client process.
@@ -2601,6 +2619,8 @@
 inherited from the server process' TYPE, FILTER and SENTINEL.
 - The client process' contact info is set according to the client's
 addressing information (typically an IP address and a port number).
+- The client process' private variables are initialized from the
+server's private variables.
 
 Notice that the FILTER and SENTINEL args are never used directly by
 the server process.  Also, the BUFFER argument is not used directly by
@@ -2609,7 +2629,6 @@
 
 The original argument list, modified with the actual connection
 information, is available via the `process-contact' function.
-Additional arguments may be added via `set-process-contact'.
 
 usage: (make-network-process &rest ARGS)  */)
      (nargs, args)
@@ -3164,6 +3183,8 @@
   p = XPROCESS (proc);
 
   p->childp = contact;
+  p->private_vars = Fcopy_sequence (Fplist_get (contact, QCvars));
+  
   p->buffer = buffer;
   p->sentinel = sentinel;
   p->filter = filter;
@@ -3595,6 +3616,8 @@
 #endif
 
   p->childp = contact;
+  p->private_vars = Fcopy_sequence (ps->private_vars);
+
   p->buffer = buffer;
   p->sentinel = ps->sentinel;
   p->filter = ps->filter;
@@ -6320,6 +6343,8 @@
   staticpro (&QCstop);
   QCoptions = intern (":options");
   staticpro (&QCoptions);
+  QCvars = intern (":vars");
+  staticpro (&QCvars);
     
   Qlast_nonmenu_event = intern ("last-nonmenu-event");
   staticpro (&Qlast_nonmenu_event);
@@ -6363,7 +6388,8 @@
   defsubr (&Sset_process_query_on_exit_flag);
   defsubr (&Sprocess_query_on_exit_flag);
   defsubr (&Sprocess_contact);
-  defsubr (&Sset_process_contact);
+  defsubr (&Sprocess_variable);
+  defsubr (&Sset_process_variable);
   defsubr (&Slist_processes);
   defsubr (&Sprocess_list);
   defsubr (&Sstart_process);