|
|
1.1 root 1: /* Server.c
2: *
3: * This program emulates the headwaiter reading requests (from a queue)
4: * placed in the queue by the gatekeeper (see customer.c). The following
5: * functions are illustrated here:
6: * DOSCREATEQUEUE, DOSQUERYQUEUE, DOSREADQUEUE, DOSCLOSEQUEUE
7: *
8: * This example first makes the shared segment created by customer.c
9: * addressable. The data queued by the customer.c is contained in this
10: * segment. It creates a queue, loops querying the number of elements in the
11: * queue. It exits the loop when the number of elements in the queue is
12: * nonzero. It loops reading each element from the queue and checking the
13: * value of the RequestID in the element. It exits the loop when the
14: * RequestID indicates nomore elements. It frees the shared segment
15: * and closes the queue.
16: *
17: * Compile as: cl -AL -G2 -Lp server.c
18: *
19: * Copyright (C) Microsoft Corp. 1986
20: */
21:
22: #include <doscalls.h> /* 286DOS function declarations */
23: #include "defines.h" /* definitions for example programs */
24:
25: #define Q 0 /* determine type of Queue to create */
26: #define ERROR_FILE_NOT_FOUND 2
27:
28:
29:
30:
31:
32:
33: void main (argc, argv, envp)
34: int argc;
35: char *argv[];
36: char *envp;
37: {
38: unsigned QueueHandle, /* handle to the queue */
39: NumberElements = 0, /* number of elements in queue */
40: DataLength, /* length of element received */
41: SharedSel; /* selector to shared segment */
42: unsigned long DataAddress, /* address of element received */
43: PID_RequestID; /* will hold PID & request ID */
44: unsigned char ElemPriority, /* priority of element in queue */
45: TableID, /* ID of the table */
46: Priorty, /* Priority of the Data Element */
47: type; /* example type */
48:
49: /* get the shared segment */
50: while (DOSGETSHRSEG (SEGNAME, &SharedSel) ==
51: ERROR_FILE_NOT_FOUND) /* keep trying to get the shared seg...*/
52: DOSSLEEP(1000L); /* ...until the customer creates it */
53:
54: /* create the appropriate queue */
55: if (argc > 1){
56: ++argv;
57: type = *argv[0];
58: }
59: else type = 'd';
60: switch (*argv[0]) {
61: case 'f': DOSCREATEQUEUE (&QueueHandle, FIFO, QUEUENAME);
62: printf("FIFO Queue selected ... \n");
63: break;
64: case 'F': DOSCREATEQUEUE (&QueueHandle, FIFO, QUEUENAME);
65: printf("FIFO Queue selected ...\n");
66: break;
67: case 'l': DOSCREATEQUEUE (&QueueHandle, LIFO, QUEUENAME);
68: printf("LIFO Queue selected ...\n");
69: break;
70: case 'L': DOSCREATEQUEUE (&QueueHandle, LIFO, QUEUENAME);
71: printf("LIFO Queue selected ...\n");
72: break;
73: case 'p': DOSCREATEQUEUE (&QueueHandle, PRIO, QUEUENAME);
74: printf("PRIO Queue selected ...\n");
75: break;
76: case 'P': DOSCREATEQUEUE (&QueueHandle, PRIO, QUEUENAME);
77: printf("PRIO Queue selected ...\n");
78: break;
79: default: DOSCREATEQUEUE (&QueueHandle, FIFO, QUEUENAME);
80: printf("FIFO Queue selected - default\n");
81: ;
82: } /* endswitch */
83:
84: /* check if there are any requests */
85: while (NumberElements == 0) {
86: DOSQUERYQUEUE (QueueHandle, &NumberElements);
87: DOSSLEEP(1000L);
88: }
89:
90: /* there are requests in the queue. */
91:
92: /* initialise request ID */
93: *((unsigned *)(&PID_RequestID) + 1) = REQWAITER;
94:
95: /* loop for rest of queue elements until no nore */
96:
97: do {
98:
99: /* read an element from the queue */
100: DOSREADQUEUE (QueueHandle, &PID_RequestID,
101: &DataLength, &DataAddress, FIRSTELEMENT,
102: (unsigned char) WAIT, &ElemPriority,
103: (unsigned long) DUMMYPARAM);
104: TableID = *((unsigned char *) DataAddress);
105: Priorty = *((unsigned char *) DataAddress + 1);
106:
107: /* dispatch waiter to table */
108:
109: if (*((unsigned *)(&PID_RequestID) + 1) != NOMORE){
110: printf("Server sending waiter to Table %u : Priority = %u ", TableID, Priorty);
111: printf(": Data Length= %u\n", DataLength);
112: } /* endif */
113:
114: } while (*((unsigned *)(&PID_RequestID) + 1) != NOMORE); /* enddo */
115:
116:
117:
118: /* free the shared segment */
119: DOSFREESEG (SharedSel);
120:
121: /* close the queue */
122: DOSCLOSEQUEUE (QueueHandle);
123: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.