File:  [OS/2 SDKs] / os2sdk / demos / examples / queues / serv.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:14 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1988, HEAD
Microsoft OS/2 SDK 03-01-1988

/* Server.c
 *
 * This program emulates the headwaiter reading requests (from a queue)
 * placed in the queue by the gatekeeper (see customer.c).  The following
 * functions are illustrated here:
 *	DosCreateQueue, DosQueryQueue, DosReadQueue, DosCloseQueue
 *
 * This example first makes the shared segment created by customer.c
 * addressable. The data queued by the customer.c is contained in this
 * segment. It creates a queue, loops querying the number of elements in the
 * queue. It exits the loop when the number of elements in the queue is
 * nonzero. It loops reading each element from the queue and checking the
 * value of the RequestID in the element. It exits the loop when the
 * RequestID indicates nomore elements. It frees the shared segment
 * and closes the queue.
 *
 * Compile as: cl -AL -G2 -Lp server.c
 *
 * Created by Microsoft Corp. 1986
 */

#define INCL_DOSMEMMGR
#define INCL_DOSQUEUES
#define INCL_DOSPROCESS
#define INCL_DOSERRORS

#include <os2def.h>
#include <bse.h>			/* MS OS/2 function declarations     */
#include "defines.h"                    /* definitions for example programs */

#define Q                       0       /* determine type of Queue to create */

void main (argc, argv, envp)
    int argc;
    char *argv[];
    char *envp;
{
	HQUEUE		QueueHandle;	    /* handle to the queue	    */
	USHORT		NumberElements = 0; /* number of elements in queue  */
	USHORT		DataLength;	    /* length of element received   */
	SEL		SharedSel;	    /* selector to shared segment   */
	ULONG		DataAddress,	    /* address of element received  */
                        PID_RequestID;      /* will hold PID & request ID   */
	UCHAR		ElemPriority,	    /* priority of element in queue */
                        TableID,            /* ID of the table              */
                        Priorty,            /* Priority of the Data Element */
                        type;               /* example type                 */

        /* get the shared segment */
	while (DosGetShrSeg (SEGNAME, &SharedSel) ==
               ERROR_FILE_NOT_FOUND) /* keep trying to get the shared seg...*/
		  DosSleep(1000L);   /* ...until the customer creates it    */

        /* create the appropriate queue */
        if (argc > 1){
           ++argv;
           type = *argv[0];
        }
        else type = 'd';
        switch (*argv[0]) {
	  case 'f': DosCreateQueue (&QueueHandle, FIFO, QUEUENAME);
                    printf("FIFO Queue selected ... \n");
            break;
	  case 'F': DosCreateQueue (&QueueHandle, FIFO, QUEUENAME);
                    printf("FIFO Queue selected ...\n");
            break;
	  case 'l': DosCreateQueue (&QueueHandle, LIFO, QUEUENAME);
                    printf("LIFO Queue selected ...\n");
            break;
	  case 'L': DosCreateQueue (&QueueHandle, LIFO, QUEUENAME);
                    printf("LIFO Queue selected ...\n");
            break;
	  case 'p': DosCreateQueue (&QueueHandle, PRIO, QUEUENAME);
                    printf("PRIO Queue selected ...\n");
            break;
	  case 'P': DosCreateQueue (&QueueHandle, PRIO, QUEUENAME);
                    printf("PRIO Queue selected ...\n");
            break;
	  default: DosCreateQueue (&QueueHandle, FIFO, QUEUENAME);
                    printf("FIFO Queue selected - default\n");
            ;
        } /* endswitch */

        /* check if there are any requests */
        while (NumberElements == 0) {
	  DosQueryQueue (QueueHandle, &NumberElements);
	  DosSleep(1000L);
        }

        /* there are requests in the queue. */

        /* initialise request ID */
        *((unsigned *)(&PID_RequestID) + 1) = REQWAITER;

        /* loop for rest of queue elements until no nore */

        do {

          /* read an element from the queue */
	  DosReadQueue (QueueHandle, &PID_RequestID,
                        &DataLength, &DataAddress, FIRSTELEMENT,
			(UCHAR) WAIT, &ElemPriority,
			(HSEM) DUMMYPARAM);
	  TableID = *((PUCHAR) DataAddress);
	  Priorty  = *((PUCHAR) DataAddress + 1);

          /* dispatch waiter to table */

          if (*((unsigned *)(&PID_RequestID) + 1) != NOMORE){
            printf("Server sending waiter to Table %u : Priority = %u ", TableID, Priorty);
            printf(": Data Length= %u\n", DataLength);
          } /* endif */

        } while (*((unsigned *)(&PID_RequestID) + 1) != NOMORE); /* enddo */



        /* free the shared segment */
	DosFreeSeg (SharedSel);

        /* close the queue */
	DosCloseQueue (QueueHandle);
}


unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.