Функция main сервера, текст которой приведен в листинге 15.12, открывает дескрипторы дверей и связывает каждый из них с одной из процедур сервера.Листинг 15.11. Две процедуры сервера
//doors/server7.c
1 #include "unpipc.h"
2 #include
3 #include "squareproc.h"
4 #include "sqrtproc.h"
5 void
6 squareproc(void *cookie, char *dataptr, size_t datasize,
7 door_desc_t *descptr, size_t ndesc)
8 {
9 squareproc_in_t in;
10 squareproc_out_t out;
11 memcpy(&in, dataptr, min(sizeof(in), datasize));
12 printf("squareproc: thread id %ld, arg = %ld\n",
13 pr_thread_id(NULL), in.arg1);
14 sleep(5);
15 out.res1 = in.arg1 * in.arg1;
16 Door_return((char *) &out, sizeof(out), NULL, 0);
17 }
18 void
19 sqrtproc(void *cookie, char *dataptr, size_t datasize,
20 door_desc_t *descptr, size_t ndesc)
21 {
22 sqrtproc_in_t in;
23 sqrtproc_out_t out;
24 memcpy(&in, dataptr, min(sizeof(in), datasize));
25 printf("sqrtproc: thread id %ld, arg = %ld\n",
26 pr_thread_id(NULL), in.arg1);
27 sleep(5);
28 out.res1 = sqrt((double)in.arg1);
29 Door_return((char *) &out, sizeof(out), NULL, 0);
30 }