Mercurial > emacs
comparison src/process.c @ 44067:e8a136850817
(QCfeature, QCdatagram): Removed variables.
(QCtype, Qdatagram): New variables.
(network_process_featurep): Removed function.
(Fmake_network_process): Removed :feature check.
Use :type 'datagram instead of :datagram t to create a datagram
socket. This allows us to add other connection types (e.g. raw
sockets) later in a consistent manner.
(init_process) [subprocess]: Provide list of supported subfeatures
for feature make-network-process.
(syms_of_process) [subprocess]: Remove QCfeature and QCdatagram.
Intern and staticpro QCtype and Qdatagram.
(syms_of_process) [!subprocess]: Intern and staticpro QCtype.
| author | Kim F. Storm <storm@cua.dk> |
|---|---|
| date | Thu, 21 Mar 2002 12:20:24 +0000 |
| parents | 134644f94850 |
| children | 9984126a7008 |
comparison
equal
deleted
inserted
replaced
| 44066:d0bef01f3cb3 | 44067:e8a136850817 |
|---|---|
| 123 #include "atimer.h" | 123 #include "atimer.h" |
| 124 | 124 |
| 125 Lisp_Object Qprocessp; | 125 Lisp_Object Qprocessp; |
| 126 Lisp_Object Qrun, Qstop, Qsignal; | 126 Lisp_Object Qrun, Qstop, Qsignal; |
| 127 Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; | 127 Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; |
| 128 Lisp_Object Qlocal; | 128 Lisp_Object Qlocal, Qdatagram; |
| 129 Lisp_Object QCname, QCbuffer, QChost, QCservice; | 129 Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype; |
| 130 Lisp_Object QClocal, QCremote, QCcoding; | 130 Lisp_Object QClocal, QCremote, QCcoding; |
| 131 Lisp_Object QCserver, QCdatagram, QCnowait, QCnoquery, QCstop; | 131 Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; |
| 132 Lisp_Object QCsentinel, QClog, QCoptions, QCfeature; | 132 Lisp_Object QCsentinel, QClog, QCoptions; |
| 133 Lisp_Object Qlast_nonmenu_event; | 133 Lisp_Object Qlast_nonmenu_event; |
| 134 /* QCfamily is declared and initialized in xfaces.c, | 134 /* QCfamily is declared and initialized in xfaces.c, |
| 135 QCfilter in keyboard.c. */ | 135 QCfilter in keyboard.c. */ |
| 136 extern Lisp_Object QCfamily, QCfilter; | 136 extern Lisp_Object QCfamily, QCfilter; |
| 137 | 137 |
| 2378 set_socket_options (XPROCESS (process)->infd, opts, 0); | 2378 set_socket_options (XPROCESS (process)->infd, opts, 0); |
| 2379 } | 2379 } |
| 2380 return process; | 2380 return process; |
| 2381 } | 2381 } |
| 2382 | 2382 |
| 2383 /* Check whether a given KEY VALUE pair is supported on this system. */ | |
| 2384 | |
| 2385 static int | |
| 2386 network_process_featurep (key, value) | |
| 2387 Lisp_Object key, value; | |
| 2388 { | |
| 2389 | |
| 2390 if (EQ (key, QCnowait)) | |
| 2391 { | |
| 2392 #ifdef NON_BLOCKING_CONNECT | |
| 2393 return 1; | |
| 2394 #else | |
| 2395 return NILP (value); | |
| 2396 #endif | |
| 2397 } | |
| 2398 | |
| 2399 if (EQ (key, QCdatagram)) | |
| 2400 { | |
| 2401 #ifdef DATAGRAM_SOCKETS | |
| 2402 return 1; | |
| 2403 #else | |
| 2404 return NILP (value); | |
| 2405 #endif | |
| 2406 } | |
| 2407 | |
| 2408 if (EQ (key, QCfamily)) | |
| 2409 { | |
| 2410 if (NILP (value)) | |
| 2411 return 1; | |
| 2412 #ifdef HAVE_LOCAL_SOCKETS | |
| 2413 if (EQ (key, Qlocal)) | |
| 2414 return 1; | |
| 2415 #endif | |
| 2416 return 0; | |
| 2417 } | |
| 2418 | |
| 2419 if (EQ (key, QCname)) | |
| 2420 return STRINGP (value); | |
| 2421 | |
| 2422 if (EQ (key, QCbuffer)) | |
| 2423 return (NILP (value) || STRINGP (value) || BUFFERP (value)); | |
| 2424 | |
| 2425 if (EQ (key, QClocal) || EQ (key, QCremote)) | |
| 2426 { | |
| 2427 int family; | |
| 2428 return get_lisp_to_sockaddr_size (value, &family); | |
| 2429 } | |
| 2430 | |
| 2431 if (EQ (key, QChost)) | |
| 2432 return (NILP (value) || STRINGP (value)); | |
| 2433 | |
| 2434 if (EQ (key, QCservice)) | |
| 2435 { | |
| 2436 #ifdef HAVE_GETSOCKNAME | |
| 2437 if (EQ (value, Qt)) | |
| 2438 return 1; | |
| 2439 #endif | |
| 2440 return (INTEGERP (value) || STRINGP (value)); | |
| 2441 } | |
| 2442 | |
| 2443 if (EQ (key, QCserver)) | |
| 2444 { | |
| 2445 #ifndef TERM | |
| 2446 return 1; | |
| 2447 #else | |
| 2448 return NILP (value); | |
| 2449 #endif | |
| 2450 } | |
| 2451 | |
| 2452 if (EQ (key, QCoptions)) | |
| 2453 return set_socket_options (-1, value, 0); | |
| 2454 | |
| 2455 if (EQ (key, QCcoding)) | |
| 2456 return 1; | |
| 2457 if (EQ (key, QCsentinel)) | |
| 2458 return 1; | |
| 2459 if (EQ (key, QCfilter)) | |
| 2460 return 1; | |
| 2461 if (EQ (key, QClog)) | |
| 2462 return 1; | |
| 2463 if (EQ (key, QCnoquery)) | |
| 2464 return 1; | |
| 2465 if (EQ (key, QCstop)) | |
| 2466 return 1; | |
| 2467 | |
| 2468 return 0; | |
| 2469 } | |
| 2470 | |
| 2471 /* A version of request_sigio suitable for a record_unwind_protect. */ | 2383 /* A version of request_sigio suitable for a record_unwind_protect. */ |
| 2472 | 2384 |
| 2473 Lisp_Object | 2385 Lisp_Object |
| 2474 unwind_request_sigio (dummy) | 2386 unwind_request_sigio (dummy) |
| 2475 Lisp_Object dummy; | 2387 Lisp_Object dummy; |
| 2513 host, and only clients connecting to that address will be accepted. | 2425 host, and only clients connecting to that address will be accepted. |
| 2514 | 2426 |
| 2515 :service SERVICE -- SERVICE is name of the service desired, or an | 2427 :service SERVICE -- SERVICE is name of the service desired, or an |
| 2516 integer specifying a port number to connect to. If SERVICE is t, | 2428 integer specifying a port number to connect to. If SERVICE is t, |
| 2517 a random port number is selected for the server. | 2429 a random port number is selected for the server. |
| 2430 | |
| 2431 :type TYPE -- TYPE is the type of connection. The default (nil) is a | |
| 2432 stream type connection, `datagram' creates a datagram type connection. | |
| 2518 | 2433 |
| 2519 :family FAMILY -- FAMILY is the address (and protocol) family for the | 2434 :family FAMILY -- FAMILY is the address (and protocol) family for the |
| 2520 service specified by HOST and SERVICE. The default address family is | 2435 service specified by HOST and SERVICE. The default address family is |
| 2521 Inet (or IPv4) for the host and port number specified by HOST and | 2436 Inet (or IPv4) for the host and port number specified by HOST and |
| 2522 SERVICE. Other address families supported are: | 2437 SERVICE. Other address families supported are: |
| 2542 address data with one element per address data byte. Do not rely on | 2457 address data with one element per address data byte. Do not rely on |
| 2543 this format in portable code, as it may depend on implementation | 2458 this format in portable code, as it may depend on implementation |
| 2544 defined constants, data sizes, and data structure alignment. | 2459 defined constants, data sizes, and data structure alignment. |
| 2545 | 2460 |
| 2546 :coding CODING -- CODING is coding system for this process. | 2461 :coding CODING -- CODING is coding system for this process. |
| 2547 | |
| 2548 :datagram BOOL -- Create a datagram type connection if BOOL is | |
| 2549 non-nil. Default is a stream type connection. | |
| 2550 | 2462 |
| 2551 :options OPTIONS -- Set the specified options for the network process. | 2463 :options OPTIONS -- Set the specified options for the network process. |
| 2552 See `set-process-options' for details. | 2464 See `set-process-options' for details. |
| 2553 | 2465 |
| 2554 :nowait BOOL -- If BOOL is non-nil for a stream type client process, | 2466 :nowait BOOL -- If BOOL is non-nil for a stream type client process, |
| 2597 Notice that the FILTER and SENTINEL args are never used directly by | 2509 Notice that the FILTER and SENTINEL args are never used directly by |
| 2598 the server process. Also, the BUFFER argument is not used directly by | 2510 the server process. Also, the BUFFER argument is not used directly by |
| 2599 the server process, but via `network-server-log-function' hook, a log | 2511 the server process, but via `network-server-log-function' hook, a log |
| 2600 of the accepted (and failed) connections may be recorded in the server | 2512 of the accepted (and failed) connections may be recorded in the server |
| 2601 process' buffer. | 2513 process' buffer. |
| 2602 | |
| 2603 The following special call returns t iff a given KEY VALUE | |
| 2604 pair is supported on this system: | |
| 2605 (make-network-process :feature KEY VALUE) | |
| 2606 | 2514 |
| 2607 usage: (make-network-process &rest ARGS) */) | 2515 usage: (make-network-process &rest ARGS) */) |
| 2608 (nargs, args) | 2516 (nargs, args) |
| 2609 int nargs; | 2517 int nargs; |
| 2610 Lisp_Object *args; | 2518 Lisp_Object *args; |
| 2643 Lisp_Object tem; | 2551 Lisp_Object tem; |
| 2644 Lisp_Object name, buffer, host, service, address; | 2552 Lisp_Object name, buffer, host, service, address; |
| 2645 Lisp_Object filter, sentinel; | 2553 Lisp_Object filter, sentinel; |
| 2646 int is_non_blocking_client = 0; | 2554 int is_non_blocking_client = 0; |
| 2647 int is_server = 0; | 2555 int is_server = 0; |
| 2648 int socktype = SOCK_STREAM; | 2556 int socktype; |
| 2649 int family = -1; | 2557 int family = -1; |
| 2650 | 2558 |
| 2651 if (nargs == 0) | 2559 if (nargs == 0) |
| 2652 return Qnil; | 2560 return Qnil; |
| 2653 | |
| 2654 /* Handle :feature KEY VALUE query. */ | |
| 2655 if (EQ (args[0], QCfeature)) | |
| 2656 { | |
| 2657 if (nargs != 3) | |
| 2658 return Qnil; | |
| 2659 return network_process_featurep (args[1], args[2]) ? Qt : Qnil; | |
| 2660 } | |
| 2661 | 2561 |
| 2662 /* Save arguments for process-contact and clone-process. */ | 2562 /* Save arguments for process-contact and clone-process. */ |
| 2663 contact = Flist (nargs, args); | 2563 contact = Flist (nargs, args); |
| 2664 GCPRO1 (contact); | 2564 GCPRO1 (contact); |
| 2665 | 2565 |
| 2666 #ifdef WINDOWSNT | 2566 #ifdef WINDOWSNT |
| 2667 /* Ensure socket support is loaded if available. */ | 2567 /* Ensure socket support is loaded if available. */ |
| 2668 init_winsock (TRUE); | 2568 init_winsock (TRUE); |
| 2669 #endif | 2569 #endif |
| 2670 | 2570 |
| 2671 /* :datagram BOOL */ | 2571 /* :type TYPE (nil: stream, datagram */ |
| 2672 tem = Fplist_get (contact, QCdatagram); | 2572 tem = Fplist_get (contact, QCtype); |
| 2673 if (!NILP (tem)) | 2573 if (NILP (tem)) |
| 2674 { | 2574 socktype = SOCK_STREAM; |
| 2675 #ifndef DATAGRAM_SOCKETS | 2575 #ifdef DATAGRAM_SOCKETS |
| 2676 error ("Datagram connections not supported"); | 2576 else if (EQ (tem, Qdatagram)) |
| 2677 #else | 2577 socktype = SOCK_DGRAM; |
| 2678 socktype = SOCK_DGRAM; | 2578 #endif |
| 2679 #endif | 2579 else |
| 2680 } | 2580 error ("Unsupported connection type"); |
| 2681 | 2581 |
| 2682 /* :server BOOL */ | 2582 /* :server BOOL */ |
| 2683 tem = Fplist_get (contact, QCserver); | 2583 tem = Fplist_get (contact, QCserver); |
| 2684 if (!NILP (tem)) | 2584 if (!NILP (tem)) |
| 2685 { | 2585 { |
| 6109 | 6009 |
| 6110 void | 6010 void |
| 6111 init_process () | 6011 init_process () |
| 6112 { | 6012 { |
| 6113 register int i; | 6013 register int i; |
| 6014 Lisp_Object subfeatures; | |
| 6114 | 6015 |
| 6115 #ifdef SIGCHLD | 6016 #ifdef SIGCHLD |
| 6116 #ifndef CANNOT_DUMP | 6017 #ifndef CANNOT_DUMP |
| 6117 if (! noninteractive || initialized) | 6018 if (! noninteractive || initialized) |
| 6118 #endif | 6019 #endif |
| 6135 bzero (proc_decode_coding_system, sizeof proc_decode_coding_system); | 6036 bzero (proc_decode_coding_system, sizeof proc_decode_coding_system); |
| 6136 bzero (proc_encode_coding_system, sizeof proc_encode_coding_system); | 6037 bzero (proc_encode_coding_system, sizeof proc_encode_coding_system); |
| 6137 #ifdef DATAGRAM_SOCKETS | 6038 #ifdef DATAGRAM_SOCKETS |
| 6138 bzero (datagram_address, sizeof datagram_address); | 6039 bzero (datagram_address, sizeof datagram_address); |
| 6139 #endif | 6040 #endif |
| 6041 | |
| 6042 #define ADD_SUBFEATURE(key, val) \ | |
| 6043 subfeatures = Fcons (Fcons (key, Fcons (val, Qnil)), subfeatures) | |
| 6044 | |
| 6045 subfeatures = Qnil; | |
| 6046 #ifdef NON_BLOCKING_CONNECT | |
| 6047 ADD_SUBFEATURE (QCnowait, Qt); | |
| 6048 #endif | |
| 6049 #ifdef DATAGRAM_SOCKETS | |
| 6050 ADD_SUBFEATURE (QCtype, Qdatagram); | |
| 6051 #endif | |
| 6052 #ifdef HAVE_LOCAL_SOCKETS | |
| 6053 ADD_SUBFEATURE (QCfamily, Qlocal); | |
| 6054 #endif | |
| 6055 #ifdef HAVE_GETSOCKNAME | |
| 6056 ADD_SUBFEATURE (QCservice, Qt); | |
| 6057 #endif | |
| 6058 #ifndef TERM | |
| 6059 ADD_SUBFEATURE (QCserver, Qt); | |
| 6060 #endif | |
| 6061 #ifdef SO_BINDTODEVICE | |
| 6062 ADD_SUBFEATURE (QCoptions, intern ("bindtodevice")); | |
| 6063 #endif | |
| 6064 #ifdef SO_BROADCAST | |
| 6065 ADD_SUBFEATURE (QCoptions, intern ("broadcast")); | |
| 6066 #endif | |
| 6067 #ifdef SO_DONTROUTE | |
| 6068 ADD_SUBFEATURE (QCoptions, intern ("dontroute")); | |
| 6069 #endif | |
| 6070 #ifdef SO_KEEPALIVE | |
| 6071 ADD_SUBFEATURE (QCoptions, intern ("keepalive")); | |
| 6072 #endif | |
| 6073 #ifdef SO_LINGER | |
| 6074 ADD_SUBFEATURE (QCoptions, intern ("linger")); | |
| 6075 #endif | |
| 6076 #ifdef SO_OOBINLINE | |
| 6077 ADD_SUBFEATURE (QCoptions, intern ("oobinline")); | |
| 6078 #endif | |
| 6079 #ifdef SO_PRIORITY | |
| 6080 ADD_SUBFEATURE (QCoptions, intern ("priority")); | |
| 6081 #endif | |
| 6082 #ifdef SO_REUSEADDR | |
| 6083 ADD_SUBFEATURE (QCoptions, intern ("reuseaddr")); | |
| 6084 #endif | |
| 6085 Fprovide (intern ("make-network-process"), subfeatures); | |
| 6140 } | 6086 } |
| 6141 | 6087 |
| 6142 void | 6088 void |
| 6143 syms_of_process () | 6089 syms_of_process () |
| 6144 { | 6090 { |
| 6167 staticpro (&Qfailed); | 6113 staticpro (&Qfailed); |
| 6168 Qlisten = intern ("listen"); | 6114 Qlisten = intern ("listen"); |
| 6169 staticpro (&Qlisten); | 6115 staticpro (&Qlisten); |
| 6170 Qlocal = intern ("local"); | 6116 Qlocal = intern ("local"); |
| 6171 staticpro (&Qlocal); | 6117 staticpro (&Qlocal); |
| 6118 Qdatagram = intern ("datagram"); | |
| 6119 staticpro (&Qdatagram); | |
| 6172 | 6120 |
| 6173 QCname = intern (":name"); | 6121 QCname = intern (":name"); |
| 6174 staticpro (&QCname); | 6122 staticpro (&QCname); |
| 6175 QCbuffer = intern (":buffer"); | 6123 QCbuffer = intern (":buffer"); |
| 6176 staticpro (&QCbuffer); | 6124 staticpro (&QCbuffer); |
| 6177 QChost = intern (":host"); | 6125 QChost = intern (":host"); |
| 6178 staticpro (&QChost); | 6126 staticpro (&QChost); |
| 6179 QCservice = intern (":service"); | 6127 QCservice = intern (":service"); |
| 6180 staticpro (&QCservice); | 6128 staticpro (&QCservice); |
| 6129 QCtype = intern (":type"); | |
| 6130 staticpro (&QCtype); | |
| 6181 QClocal = intern (":local"); | 6131 QClocal = intern (":local"); |
| 6182 staticpro (&QClocal); | 6132 staticpro (&QClocal); |
| 6183 QCremote = intern (":remote"); | 6133 QCremote = intern (":remote"); |
| 6184 staticpro (&QCremote); | 6134 staticpro (&QCremote); |
| 6185 QCcoding = intern (":coding"); | 6135 QCcoding = intern (":coding"); |
| 6186 staticpro (&QCcoding); | 6136 staticpro (&QCcoding); |
| 6187 QCserver = intern (":server"); | 6137 QCserver = intern (":server"); |
| 6188 staticpro (&QCserver); | 6138 staticpro (&QCserver); |
| 6189 QCdatagram = intern (":datagram"); | |
| 6190 staticpro (&QCdatagram); | |
| 6191 QCnowait = intern (":nowait"); | 6139 QCnowait = intern (":nowait"); |
| 6192 staticpro (&QCnowait); | 6140 staticpro (&QCnowait); |
| 6193 QCsentinel = intern (":sentinel"); | 6141 QCsentinel = intern (":sentinel"); |
| 6194 staticpro (&QCsentinel); | 6142 staticpro (&QCsentinel); |
| 6195 QClog = intern (":log"); | 6143 QClog = intern (":log"); |
| 6198 staticpro (&QCnoquery); | 6146 staticpro (&QCnoquery); |
| 6199 QCstop = intern (":stop"); | 6147 QCstop = intern (":stop"); |
| 6200 staticpro (&QCstop); | 6148 staticpro (&QCstop); |
| 6201 QCoptions = intern (":options"); | 6149 QCoptions = intern (":options"); |
| 6202 staticpro (&QCoptions); | 6150 staticpro (&QCoptions); |
| 6203 QCfeature = intern (":feature"); | |
| 6204 staticpro (&QCfeature); | |
| 6205 | 6151 |
| 6206 Qlast_nonmenu_event = intern ("last-nonmenu-event"); | 6152 Qlast_nonmenu_event = intern ("last-nonmenu-event"); |
| 6207 staticpro (&Qlast_nonmenu_event); | 6153 staticpro (&Qlast_nonmenu_event); |
| 6208 | 6154 |
| 6209 staticpro (&Vprocess_alist); | 6155 staticpro (&Vprocess_alist); |
| 6289 extern int frame_garbaged; | 6235 extern int frame_garbaged; |
| 6290 | 6236 |
| 6291 extern EMACS_TIME timer_check (); | 6237 extern EMACS_TIME timer_check (); |
| 6292 extern int timers_run; | 6238 extern int timers_run; |
| 6293 | 6239 |
| 6240 Lisp_Object QCtype; | |
| 6241 | |
| 6294 /* As described above, except assuming that there are no subprocesses: | 6242 /* As described above, except assuming that there are no subprocesses: |
| 6295 | 6243 |
| 6296 Wait for timeout to elapse and/or keyboard input to be available. | 6244 Wait for timeout to elapse and/or keyboard input to be available. |
| 6297 | 6245 |
| 6298 time_limit is: | 6246 time_limit is: |
| 6564 } | 6512 } |
| 6565 | 6513 |
| 6566 void | 6514 void |
| 6567 syms_of_process () | 6515 syms_of_process () |
| 6568 { | 6516 { |
| 6517 QCtype = intern (":type"); | |
| 6518 staticpro (&QCtype); | |
| 6519 | |
| 6569 defsubr (&Sget_buffer_process); | 6520 defsubr (&Sget_buffer_process); |
| 6570 defsubr (&Sprocess_inherit_coding_system_flag); | 6521 defsubr (&Sprocess_inherit_coding_system_flag); |
| 6571 } | 6522 } |
| 6572 | 6523 |
| 6573 | 6524 |
