Mercurial > emacs
comparison src/process.c @ 47987:b30942bd85f3
(Fformat_network_address): New function.
(syms_of_process): Defsubr it.
(list_processes_1): Use it to format :local/:remote address if
service/host is not set; before emacs would crash in that case.
(Fmake_network_process): Don't use Ffind_operation_coding_system
to setup coding system if host or service is not set.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Thu, 24 Oct 2002 08:03:41 +0000 |
parents | 62a08cd28e83 |
children | f840e449c328 |
comparison
equal
deleted
inserted
replaced
47986:d249077dbc15 | 47987:b30942bd85f3 |
---|---|
1041 Lisp_Object process; | 1041 Lisp_Object process; |
1042 { | 1042 { |
1043 return XPROCESS (process)->type; | 1043 return XPROCESS (process)->type; |
1044 } | 1044 } |
1045 #endif | 1045 #endif |
1046 | |
1047 #ifdef HAVE_SOCKETS | |
1048 DEFUN ("format-network-address", Fformat_network_address, Sformat_network_address, | |
1049 1, 1, 0, | |
1050 doc: /* Convert network ADDRESS from internal format to a string. | |
1051 Returns nil if format of ADDRESS is invalid. */) | |
1052 (address) | |
1053 Lisp_Object address; | |
1054 { | |
1055 register struct Lisp_Vector *p; | |
1056 register unsigned char *cp; | |
1057 register int i; | |
1058 | |
1059 if (NILP (address)) | |
1060 return Qnil; | |
1061 | |
1062 if (STRINGP (address)) /* AF_LOCAL */ | |
1063 return address; | |
1064 | |
1065 if (VECTORP (address)) /* AF_INET */ | |
1066 { | |
1067 register struct Lisp_Vector *p = XVECTOR (address); | |
1068 Lisp_Object args[6]; | |
1069 | |
1070 if (p->size != 5) | |
1071 return Qnil; | |
1072 | |
1073 args[0] = build_string ("%d.%d.%d.%d:%d"); | |
1074 args[1] = XINT (p->contents[0]); | |
1075 args[2] = XINT (p->contents[1]); | |
1076 args[3] = XINT (p->contents[2]); | |
1077 args[4] = XINT (p->contents[3]); | |
1078 args[5] = XINT (p->contents[4]); | |
1079 return Fformat (6, args); | |
1080 } | |
1081 | |
1082 if (CONSP (address)) | |
1083 { | |
1084 Lisp_Object args[2]; | |
1085 args[0] = build_string ("<Family %d>"); | |
1086 args[1] = XINT (Fcar (address)); | |
1087 return Fformat (2, args); | |
1088 | |
1089 } | |
1090 | |
1091 return Qnil; | |
1092 } | |
1093 #endif | |
1046 | 1094 |
1047 Lisp_Object | 1095 Lisp_Object |
1048 list_processes_1 (query_only) | 1096 list_processes_1 (query_only) |
1049 Lisp_Object query_only; | 1097 Lisp_Object query_only; |
1050 { | 1098 { |
1202 if (EQ (p->status, Qlisten)) | 1250 if (EQ (p->status, Qlisten)) |
1203 { | 1251 { |
1204 Lisp_Object port = Fplist_get (p->childp, QCservice); | 1252 Lisp_Object port = Fplist_get (p->childp, QCservice); |
1205 if (INTEGERP (port)) | 1253 if (INTEGERP (port)) |
1206 port = Fnumber_to_string (port); | 1254 port = Fnumber_to_string (port); |
1255 if (NILP (port)) | |
1256 port = Fformat_network_address (Fplist_get (p->childp, QClocal)); | |
1207 sprintf (tembuf, "(network %s server on %s)\n", | 1257 sprintf (tembuf, "(network %s server on %s)\n", |
1208 (DATAGRAM_CHAN_P (XINT (p->infd)) ? "datagram" : "stream"), | 1258 (DATAGRAM_CHAN_P (XINT (p->infd)) ? "datagram" : "stream"), |
1209 SDATA (port)); | 1259 (STRINGP (port) ? (char *)SDATA (port) : "?")); |
1210 insert_string (tembuf); | 1260 insert_string (tembuf); |
1211 } | 1261 } |
1212 else if (NETCONN1_P (p)) | 1262 else if (NETCONN1_P (p)) |
1213 { | 1263 { |
1214 /* For a local socket, there is no host name, | 1264 /* For a local socket, there is no host name, |
1218 { | 1268 { |
1219 host = Fplist_get (p->childp, QCservice); | 1269 host = Fplist_get (p->childp, QCservice); |
1220 if (INTEGERP (host)) | 1270 if (INTEGERP (host)) |
1221 host = Fnumber_to_string (host); | 1271 host = Fnumber_to_string (host); |
1222 } | 1272 } |
1273 if (NILP (host)) | |
1274 host = Fformat_network_address (Fplist_get (p->childp, QCremote)); | |
1223 sprintf (tembuf, "(network %s connection to %s)\n", | 1275 sprintf (tembuf, "(network %s connection to %s)\n", |
1224 (DATAGRAM_CHAN_P (XINT (p->infd)) ? "datagram" : "stream"), | 1276 (DATAGRAM_CHAN_P (XINT (p->infd)) ? "datagram" : "stream"), |
1225 SDATA (host)); | 1277 (STRINGP (host) ? (char *)SDATA (host) : "?")); |
1226 insert_string (tembuf); | 1278 insert_string (tembuf); |
1227 } | 1279 } |
1228 else | 1280 else |
1229 { | 1281 { |
1230 tem = p->command; | 1282 tem = p->command; |
2496 :filter FILTER -- Install FILTER as the process filter. | 2548 :filter FILTER -- Install FILTER as the process filter. |
2497 | 2549 |
2498 :sentinel SENTINEL -- Install SENTINEL as the process sentinel. | 2550 :sentinel SENTINEL -- Install SENTINEL as the process sentinel. |
2499 | 2551 |
2500 :log LOG -- Install LOG as the server process log function. This | 2552 :log LOG -- Install LOG as the server process log function. This |
2501 function is called as when the server accepts a network connection from a | 2553 function is called when the server accepts a network connection from a |
2502 client. The arguments are SERVER, CLIENT, and MESSAGE, where SERVER | 2554 client. The arguments are SERVER, CLIENT, and MESSAGE, where SERVER |
2503 is the server process, CLIENT is the new process for the connection, | 2555 is the server process, CLIENT is the new process for the connection, |
2504 and MESSAGE is a string. | 2556 and MESSAGE is a string. |
2505 | 2557 |
2506 :server BOOL -- if BOOL is non-nil, create a server process for the | 2558 :server BOOL -- if BOOL is non-nil, create a server process for the |
3132 assume that they receive bare code including a sequene of | 3184 assume that they receive bare code including a sequene of |
3133 CR LF. */ | 3185 CR LF. */ |
3134 val = Qnil; | 3186 val = Qnil; |
3135 else | 3187 else |
3136 { | 3188 { |
3137 args[0] = Qopen_network_stream, args[1] = name, | 3189 if (NILP (host) || NILP (service)) |
3138 args[2] = buffer, args[3] = host, args[4] = service; | 3190 coding_systems = Qnil; |
3139 GCPRO1 (proc); | 3191 else |
3140 coding_systems = Ffind_operation_coding_system (5, args); | 3192 { |
3141 UNGCPRO; | 3193 args[0] = Qopen_network_stream, args[1] = name, |
3194 args[2] = buffer, args[3] = host, args[4] = service; | |
3195 GCPRO1 (proc); | |
3196 coding_systems = Ffind_operation_coding_system (5, args); | |
3197 UNGCPRO; | |
3198 } | |
3142 if (CONSP (coding_systems)) | 3199 if (CONSP (coding_systems)) |
3143 val = XCAR (coding_systems); | 3200 val = XCAR (coding_systems); |
3144 else if (CONSP (Vdefault_process_coding_system)) | 3201 else if (CONSP (Vdefault_process_coding_system)) |
3145 val = XCAR (Vdefault_process_coding_system); | 3202 val = XCAR (Vdefault_process_coding_system); |
3146 else | 3203 else |
3156 val = Qnil; | 3213 val = Qnil; |
3157 else | 3214 else |
3158 { | 3215 { |
3159 if (EQ (coding_systems, Qt)) | 3216 if (EQ (coding_systems, Qt)) |
3160 { | 3217 { |
3161 args[0] = Qopen_network_stream, args[1] = name, | 3218 if (NILP (host) || NILP (service)) |
3162 args[2] = buffer, args[3] = host, args[4] = service; | 3219 coding_systems = Qnil; |
3163 GCPRO1 (proc); | 3220 else |
3164 coding_systems = Ffind_operation_coding_system (5, args); | 3221 { |
3165 UNGCPRO; | 3222 args[0] = Qopen_network_stream, args[1] = name, |
3223 args[2] = buffer, args[3] = host, args[4] = service; | |
3224 GCPRO1 (proc); | |
3225 coding_systems = Ffind_operation_coding_system (5, args); | |
3226 UNGCPRO; | |
3227 } | |
3166 } | 3228 } |
3167 if (CONSP (coding_systems)) | 3229 if (CONSP (coding_systems)) |
3168 val = XCDR (coding_systems); | 3230 val = XCDR (coding_systems); |
3169 else if (CONSP (Vdefault_process_coding_system)) | 3231 else if (CONSP (Vdefault_process_coding_system)) |
3170 val = XCDR (Vdefault_process_coding_system); | 3232 val = XCDR (Vdefault_process_coding_system); |
6230 defsubr (&Sprocess_list); | 6292 defsubr (&Sprocess_list); |
6231 defsubr (&Sstart_process); | 6293 defsubr (&Sstart_process); |
6232 #ifdef HAVE_SOCKETS | 6294 #ifdef HAVE_SOCKETS |
6233 defsubr (&Sset_network_process_options); | 6295 defsubr (&Sset_network_process_options); |
6234 defsubr (&Smake_network_process); | 6296 defsubr (&Smake_network_process); |
6297 defsubr (&Sformat_network_address); | |
6235 #endif /* HAVE_SOCKETS */ | 6298 #endif /* HAVE_SOCKETS */ |
6236 #ifdef DATAGRAM_SOCKETS | 6299 #ifdef DATAGRAM_SOCKETS |
6237 defsubr (&Sprocess_datagram_address); | 6300 defsubr (&Sprocess_datagram_address); |
6238 defsubr (&Sset_process_datagram_address); | 6301 defsubr (&Sset_process_datagram_address); |
6239 #endif | 6302 #endif |