|
|
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:
1.1.1.2 ! root 6: * DosCreateQueue, DosQueryQueue, DosReadQueue, DosCloseQueue
1.1 root 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: *
1.1.1.2 ! root 19: * Created by Microsoft Corp. 1986
1.1 root 20: */
21:
1.1.1.2 ! root 22: #define INCL_DOSMEMMGR
! 23: #define INCL_DOSQUEUES
! 24: #define INCL_DOSPROCESS
! 25: #define INCL_DOSERRORS
! 26:
! 27: #include <os2def.h>
! 28: #include <bse.h> /* MS OS/2 function declarations */
1.1 root 29: #include "defines.h" /* definitions for example programs */
30:
31: #define Q 0 /* determine type of Queue to create */
32:
33: void main (argc, argv, envp)
34: int argc;
35: char *argv[];
36: char *envp;
37: {
1.1.1.2 ! root 38: HQUEUE QueueHandle; /* handle to the queue */
! 39: USHORT NumberElements = 0; /* number of elements in queue */
! 40: USHORT DataLength; /* length of element received */
! 41: SEL SharedSel; /* selector to shared segment */
! 42: ULONG DataAddress, /* address of element received */
1.1 root 43: PID_RequestID; /* will hold PID & request ID */
1.1.1.2 ! root 44: UCHAR ElemPriority, /* priority of element in queue */
1.1 root 45: TableID, /* ID of the table */
46: Priorty, /* Priority of the Data Element */
47: type; /* example type */
48:
49: /* get the shared segment */
1.1.1.2 ! root 50: while (DosGetShrSeg (SEGNAME, &SharedSel) ==
1.1 root 51: ERROR_FILE_NOT_FOUND) /* keep trying to get the shared seg...*/
1.1.1.2 ! root 52: DosSleep(1000L); /* ...until the customer creates it */
1.1 root 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]) {
1.1.1.2 ! root 61: case 'f': DosCreateQueue (&QueueHandle, FIFO, QUEUENAME);
1.1 root 62: printf("FIFO Queue selected ... \n");
63: break;
1.1.1.2 ! root 64: case 'F': DosCreateQueue (&QueueHandle, FIFO, QUEUENAME);
1.1 root 65: printf("FIFO Queue selected ...\n");
66: break;
1.1.1.2 ! root 67: case 'l': DosCreateQueue (&QueueHandle, LIFO, QUEUENAME);
1.1 root 68: printf("LIFO Queue selected ...\n");
69: break;
1.1.1.2 ! root 70: case 'L': DosCreateQueue (&QueueHandle, LIFO, QUEUENAME);
1.1 root 71: printf("LIFO Queue selected ...\n");
72: break;
1.1.1.2 ! root 73: case 'p': DosCreateQueue (&QueueHandle, PRIO, QUEUENAME);
1.1 root 74: printf("PRIO Queue selected ...\n");
75: break;
1.1.1.2 ! root 76: case 'P': DosCreateQueue (&QueueHandle, PRIO, QUEUENAME);
1.1 root 77: printf("PRIO Queue selected ...\n");
78: break;
1.1.1.2 ! root 79: default: DosCreateQueue (&QueueHandle, FIFO, QUEUENAME);
1.1 root 80: printf("FIFO Queue selected - default\n");
81: ;
82: } /* endswitch */
83:
84: /* check if there are any requests */
85: while (NumberElements == 0) {
1.1.1.2 ! root 86: DosQueryQueue (QueueHandle, &NumberElements);
! 87: DosSleep(1000L);
1.1 root 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 */
1.1.1.2 ! root 100: DosReadQueue (QueueHandle, &PID_RequestID,
1.1 root 101: &DataLength, &DataAddress, FIRSTELEMENT,
1.1.1.2 ! root 102: (UCHAR) WAIT, &ElemPriority,
! 103: (HSEM) DUMMYPARAM);
! 104: TableID = *((PUCHAR) DataAddress);
! 105: Priorty = *((PUCHAR) DataAddress + 1);
1.1 root 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 */
1.1.1.2 ! root 119: DosFreeSeg (SharedSel);
1.1 root 120:
121: /* close the queue */
1.1.1.2 ! root 122: DosCloseQueue (QueueHandle);
1.1 root 123: }
1.1.1.2 ! root 124:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.