diff options
| author | Richard M. Stallman | 1994-08-08 07:08:17 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-08-08 07:08:17 +0000 |
| commit | 2f3179987f81afcbefe99860d451b0c529d7cc32 (patch) | |
| tree | 96dc551ecc8482b495fc156dbf9c7f2daf80d568 | |
| parent | 93cffa2f7ca23da10b1a040b2199a82734e73e67 (diff) | |
| download | emacs-2f3179987f81afcbefe99860d451b0c529d7cc32.tar.gz emacs-2f3179987f81afcbefe99860d451b0c529d7cc32.zip | |
[SYSV_IPC] (main): Make a separate process
so we can listen for multiple requests.
| -rw-r--r-- | lib-src/emacsserver.c | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/lib-src/emacsserver.c b/lib-src/emacsserver.c index fe95381c8f9..ed3493b76ce 100644 --- a/lib-src/emacsserver.c +++ b/lib-src/emacsserver.c | |||
| @@ -245,7 +245,7 @@ msgcatch () | |||
| 245 | 245 | ||
| 246 | main () | 246 | main () |
| 247 | { | 247 | { |
| 248 | int s, infd, fromlen; | 248 | int s, infd, fromlen, ioproc; |
| 249 | key_t key; | 249 | key_t key; |
| 250 | struct msgbuf * msgp = | 250 | struct msgbuf * msgp = |
| 251 | (struct msgbuf *) malloc (sizeof *msgp + BUFSIZ); | 251 | (struct msgbuf *) malloc (sizeof *msgp + BUFSIZ); |
| @@ -302,7 +302,25 @@ main () | |||
| 302 | } | 302 | } |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | /* This is executed in the child made by forking above. */ | 305 | /* This is executed in the child made by forking above. |
| 306 | Call it c1. Make another process, ioproc. */ | ||
| 307 | |||
| 308 | ioproc = fork (); | ||
| 309 | if (ioproc == 0) | ||
| 310 | { | ||
| 311 | /* In process ioproc, wait for text from Emacs, | ||
| 312 | and send it to the process c1. | ||
| 313 | This way, c1 only has to wait for one source of input. */ | ||
| 314 | while (fgets (msgp->mtext, BUFSIZ, stdin)) | ||
| 315 | { | ||
| 316 | msgp->mtype = 1; | ||
| 317 | msgsnd (s, msgp, strlen (msgp->mtext) + 1, 0); | ||
| 318 | } | ||
| 319 | exit (1); | ||
| 320 | } | ||
| 321 | |||
| 322 | /* In the process c1, | ||
| 323 | listen for messages from clients and pass them to Emacs. */ | ||
| 306 | while (1) | 324 | while (1) |
| 307 | { | 325 | { |
| 308 | if ((fromlen = msgrcv (s, msgp, BUFSIZ - 1, 1, 0)) < 0) | 326 | if ((fromlen = msgrcv (s, msgp, BUFSIZ - 1, 1, 0)) < 0) |
| @@ -313,17 +331,30 @@ main () | |||
| 313 | else | 331 | else |
| 314 | { | 332 | { |
| 315 | msgctl (s, IPC_STAT, &msg_st); | 333 | msgctl (s, IPC_STAT, &msg_st); |
| 334 | |||
| 335 | /* Distinguish whether the message came from a client, or from | ||
| 336 | ioproc. */ | ||
| 337 | if (msg_st.msg_lspid == ioproc) | ||
| 338 | { | ||
| 339 | char code[BUFSIZ]; | ||
| 340 | int inproc; | ||
| 341 | |||
| 342 | /* Message from ioproc: tell a client we are done. */ | ||
| 343 | msgp->mtext[strlen (msgp->mtext)-1] = 0; | ||
| 344 | sscanf (msgp->mtext, "%s %d", code, &inproc); | ||
| 345 | msgp->mtype = inproc; | ||
| 346 | msgsnd (s, msgp, strlen (msgp->mtext) + 1, 0); | ||
| 347 | continue; | ||
| 348 | } | ||
| 349 | |||
| 350 | /* This is a request from a client: copy to stdout | ||
| 351 | so that Emacs will get it. Include msg_lspid | ||
| 352 | so server.el can tell us where to send the reply. */ | ||
| 316 | strncpy (string, msgp->mtext, fromlen); | 353 | strncpy (string, msgp->mtext, fromlen); |
| 317 | string[fromlen] = 0; /* make sure */ | 354 | string[fromlen] = 0; /* make sure */ |
| 318 | /* Newline is part of string.. */ | 355 | /* Newline is part of string.. */ |
| 319 | printf ("Client: %d %s", s, string); | 356 | printf ("Client: %d %s", msg_st.msg_lspid, string); |
| 320 | fflush (stdout); | 357 | fflush (stdout); |
| 321 | /* Now, wait for a wakeup */ | ||
| 322 | fgets (msgp->mtext, BUFSIZ, stdin); | ||
| 323 | msgp->mtext[strlen (msgp->mtext)-1] = 0; | ||
| 324 | /* strcpy (msgp->mtext, "done");*/ | ||
| 325 | msgp->mtype = msg_st.msg_lspid; | ||
| 326 | msgsnd (s, msgp, strlen (msgp->mtext)+1, 0); | ||
| 327 | } | 358 | } |
| 328 | } | 359 | } |
| 329 | } | 360 | } |