comparison src/process.c @ 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 8dca38bc0261
children 26622fa0d099
comparison
equal deleted inserted replaced
49163:5697f31e3ca6 49164:8bee0ccd5fd6
130 Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; 130 Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten;
131 Lisp_Object Qlocal, Qdatagram; 131 Lisp_Object Qlocal, Qdatagram;
132 Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype; 132 Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype;
133 Lisp_Object QClocal, QCremote, QCcoding; 133 Lisp_Object QClocal, QCremote, QCcoding;
134 Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; 134 Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
135 Lisp_Object QCsentinel, QClog, QCoptions; 135 Lisp_Object QCsentinel, QClog, QCoptions, QCvars;
136 Lisp_Object Qlast_nonmenu_event; 136 Lisp_Object Qlast_nonmenu_event;
137 /* QCfamily is declared and initialized in xfaces.c, 137 /* QCfamily is declared and initialized in xfaces.c,
138 QCfilter in keyboard.c. */ 138 QCfilter in keyboard.c. */
139 extern Lisp_Object QCfamily, QCfilter; 139 extern Lisp_Object QCfamily, QCfilter;
140 140
1035 return Fcons (Fplist_get (contact, QChost), 1035 return Fcons (Fplist_get (contact, QChost),
1036 Fcons (Fplist_get (contact, QCservice), Qnil)); 1036 Fcons (Fplist_get (contact, QCservice), Qnil));
1037 return Fplist_get (contact, key); 1037 return Fplist_get (contact, key);
1038 } 1038 }
1039 1039
1040 DEFUN ("set-process-contact", Fset_process_contact, Sset_process_contact, 1040 DEFUN ("process-variable", Fprocess_variable, Sprocess_variable,
1041 1, 2, 0,
1042 doc: /* Return the value of PROCESS' private variable VAR.
1043 If VARIABLE is omitted or nil, return plist with all PROCESS variables. */)
1044 (process, var)
1045 register Lisp_Object process, var;
1046 {
1047 CHECK_PROCESS (process);
1048
1049 if (NILP (var))
1050 return XPROCESS (process)->private_vars;
1051
1052 return Fplist_get (XPROCESS (process)->private_vars, var);
1053 }
1054
1055 DEFUN ("set-process-variable", Fset_process_variable, Sset_process_variable,
1041 3, 3, 0, 1056 3, 3, 0,
1042 doc: /* Change value in PROCESS' contact information list of KEY to VAL. 1057 doc: /* Change value of PROCESS' private variable VAR to VAL, and return VAL.
1043 If KEY is already a property on the list, its value is set to VAL, 1058 If VAR is nil, set all PROCESS' private variables according to plist VAL. */)
1044 otherwise the new KEY VAL pair is added. Returns VAL. */) 1059 (process, var, val)
1045 (process, key, val) 1060 register Lisp_Object process, var, val;
1046 register Lisp_Object process, key, val; 1061 {
1047 {
1048 Lisp_Object contact;
1049
1050 CHECK_PROCESS (process); 1062 CHECK_PROCESS (process);
1051 1063
1052 if (NETCONN_P (process)) 1064 XPROCESS (process)->private_vars
1053 XPROCESS (process)->childp = Fplist_put (XPROCESS (process)->childp, key, val); 1065 = (NILP (var)
1066 ? val
1067 : Fplist_put (XPROCESS (process)->private_vars, var, val));
1054 1068
1055 return val; 1069 return val;
1056 } 1070 }
1057 1071
1058 #if 0 /* Turned off because we don't currently record this info 1072 #if 0 /* Turned off because we don't currently record this info
1418 check in create_process doesn't need to call remove_process 1432 check in create_process doesn't need to call remove_process
1419 itself; it's all taken care of here. */ 1433 itself; it's all taken care of here. */
1420 record_unwind_protect (start_process_unwind, proc); 1434 record_unwind_protect (start_process_unwind, proc);
1421 1435
1422 XPROCESS (proc)->childp = Qt; 1436 XPROCESS (proc)->childp = Qt;
1437 XPROCESS (proc)->private_vars = Qnil;
1423 XPROCESS (proc)->command_channel_p = Qnil; 1438 XPROCESS (proc)->command_channel_p = Qnil;
1424 XPROCESS (proc)->buffer = buffer; 1439 XPROCESS (proc)->buffer = buffer;
1425 XPROCESS (proc)->sentinel = Qnil; 1440 XPROCESS (proc)->sentinel = Qnil;
1426 XPROCESS (proc)->filter = Qnil; 1441 XPROCESS (proc)->filter = Qnil;
1427 XPROCESS (proc)->command = Flist (nargs - 2, args + 2); 1442 XPROCESS (proc)->command = Flist (nargs - 2, args + 2);
2582 function is called when the server accepts a network connection from a 2597 function is called when the server accepts a network connection from a
2583 client. The arguments are SERVER, CLIENT, and MESSAGE, where SERVER 2598 client. The arguments are SERVER, CLIENT, and MESSAGE, where SERVER
2584 is the server process, CLIENT is the new process for the connection, 2599 is the server process, CLIENT is the new process for the connection,
2585 and MESSAGE is a string. 2600 and MESSAGE is a string.
2586 2601
2602 :vars VARS -- Initialize the process' private variables according to
2603 a list of variable/value pairs (VAR1 VAL1 VAR2 VAL2...).
2604
2587 :server BOOL -- if BOOL is non-nil, create a server process for the 2605 :server BOOL -- if BOOL is non-nil, create a server process for the
2588 specified FAMILY, SERVICE, and connection type (stream or datagram). 2606 specified FAMILY, SERVICE, and connection type (stream or datagram).
2589 Default is a client process. 2607 Default is a client process.
2590 2608
2591 A server process will listen for and accept connections from 2609 A server process will listen for and accept connections from
2599 NAME concatenated with the client identification string. 2617 NAME concatenated with the client identification string.
2600 - The connection type and the process filter and sentinel parameters are 2618 - The connection type and the process filter and sentinel parameters are
2601 inherited from the server process' TYPE, FILTER and SENTINEL. 2619 inherited from the server process' TYPE, FILTER and SENTINEL.
2602 - The client process' contact info is set according to the client's 2620 - The client process' contact info is set according to the client's
2603 addressing information (typically an IP address and a port number). 2621 addressing information (typically an IP address and a port number).
2622 - The client process' private variables are initialized from the
2623 server's private variables.
2604 2624
2605 Notice that the FILTER and SENTINEL args are never used directly by 2625 Notice that the FILTER and SENTINEL args are never used directly by
2606 the server process. Also, the BUFFER argument is not used directly by 2626 the server process. Also, the BUFFER argument is not used directly by
2607 the server process, but via the optional :log function, accepted (and 2627 the server process, but via the optional :log function, accepted (and
2608 failed) connections may be logged in the server process' buffer. 2628 failed) connections may be logged in the server process' buffer.
2609 2629
2610 The original argument list, modified with the actual connection 2630 The original argument list, modified with the actual connection
2611 information, is available via the `process-contact' function. 2631 information, is available via the `process-contact' function.
2612 Additional arguments may be added via `set-process-contact'.
2613 2632
2614 usage: (make-network-process &rest ARGS) */) 2633 usage: (make-network-process &rest ARGS) */)
2615 (nargs, args) 2634 (nargs, args)
2616 int nargs; 2635 int nargs;
2617 Lisp_Object *args; 2636 Lisp_Object *args;
3162 #endif 3181 #endif
3163 3182
3164 p = XPROCESS (proc); 3183 p = XPROCESS (proc);
3165 3184
3166 p->childp = contact; 3185 p->childp = contact;
3186 p->private_vars = Fcopy_sequence (Fplist_get (contact, QCvars));
3187
3167 p->buffer = buffer; 3188 p->buffer = buffer;
3168 p->sentinel = sentinel; 3189 p->sentinel = sentinel;
3169 p->filter = filter; 3190 p->filter = filter;
3170 p->log = Fplist_get (contact, QClog); 3191 p->log = Fplist_get (contact, QClog);
3171 if (tem = Fplist_get (contact, QCnoquery), !NILP (tem)) 3192 if (tem = Fplist_get (contact, QCnoquery), !NILP (tem))
3593 contact = Fplist_put (contact, QClocal, 3614 contact = Fplist_put (contact, QClocal,
3594 conv_sockaddr_to_lisp (&saddr.sa, len)); 3615 conv_sockaddr_to_lisp (&saddr.sa, len));
3595 #endif 3616 #endif
3596 3617
3597 p->childp = contact; 3618 p->childp = contact;
3619 p->private_vars = Fcopy_sequence (ps->private_vars);
3620
3598 p->buffer = buffer; 3621 p->buffer = buffer;
3599 p->sentinel = ps->sentinel; 3622 p->sentinel = ps->sentinel;
3600 p->filter = ps->filter; 3623 p->filter = ps->filter;
3601 p->command = Qnil; 3624 p->command = Qnil;
3602 p->pid = Qnil; 3625 p->pid = Qnil;
6318 staticpro (&QCnoquery); 6341 staticpro (&QCnoquery);
6319 QCstop = intern (":stop"); 6342 QCstop = intern (":stop");
6320 staticpro (&QCstop); 6343 staticpro (&QCstop);
6321 QCoptions = intern (":options"); 6344 QCoptions = intern (":options");
6322 staticpro (&QCoptions); 6345 staticpro (&QCoptions);
6346 QCvars = intern (":vars");
6347 staticpro (&QCvars);
6323 6348
6324 Qlast_nonmenu_event = intern ("last-nonmenu-event"); 6349 Qlast_nonmenu_event = intern ("last-nonmenu-event");
6325 staticpro (&Qlast_nonmenu_event); 6350 staticpro (&Qlast_nonmenu_event);
6326 6351
6327 staticpro (&Vprocess_alist); 6352 staticpro (&Vprocess_alist);
6361 defsubr (&Sset_process_inherit_coding_system_flag); 6386 defsubr (&Sset_process_inherit_coding_system_flag);
6362 defsubr (&Sprocess_inherit_coding_system_flag); 6387 defsubr (&Sprocess_inherit_coding_system_flag);
6363 defsubr (&Sset_process_query_on_exit_flag); 6388 defsubr (&Sset_process_query_on_exit_flag);
6364 defsubr (&Sprocess_query_on_exit_flag); 6389 defsubr (&Sprocess_query_on_exit_flag);
6365 defsubr (&Sprocess_contact); 6390 defsubr (&Sprocess_contact);
6366 defsubr (&Sset_process_contact); 6391 defsubr (&Sprocess_variable);
6392 defsubr (&Sset_process_variable);
6367 defsubr (&Slist_processes); 6393 defsubr (&Slist_processes);
6368 defsubr (&Sprocess_list); 6394 defsubr (&Sprocess_list);
6369 defsubr (&Sstart_process); 6395 defsubr (&Sstart_process);
6370 #ifdef HAVE_SOCKETS 6396 #ifdef HAVE_SOCKETS
6371 defsubr (&Sset_network_process_options); 6397 defsubr (&Sset_network_process_options);