home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IPCX.ZIP / QSERVER.C < prev    next >
C/C++ Source or Header  |  1989-09-20  |  2KB  |  96 lines

  1. /* qserver.c RHS 5/1/89
  2.  *
  3.  *
  4.  This program demonstrates the use of queues and creates a server process
  5.  that client processes can pass messages to. To use it, start one instance
  6.  of this program with:
  7.  
  8.  QSERVER
  9.  
  10.  Then start multiple instances of QCLIENT.C with:
  11.  
  12.  QCLIENT
  13.  
  14.  *
  15.  */
  16.  
  17. #define INCL_DOS
  18. #define INCL_DOSQUEUES
  19. #define INCL_KBD
  20. #define INCL_ERRORS
  21.  
  22. #include<os2.h>
  23. #include<stdio.h>
  24.  
  25. #include"q.h"
  26.  
  27. void error_exit(USHORT err, char *msg);
  28. void main(void);
  29.  
  30. void main(void)
  31.     {
  32.     USHORT retval, qcount = 0;
  33.     KBDKEYINFO kbdkeyinfo;
  34.     PCH p;
  35.     HQUEUE qhandle;
  36.     QUEUERESULT qresult;
  37.     USHORT ellength;
  38.     BYTE priority;
  39.  
  40.     if(retval = DosCreateQueue(&qhandle,QUE_PRIORITY,QUEUENAME))
  41.         error_exit(retval,"DosCreateQueue");
  42.  
  43.     printf("Server has opened queue, awaiting messages...\n");
  44.  
  45.     while(TRUE)
  46.         {
  47.         if(retval = DosReadQueue(qhandle,&qresult,&ellength,
  48.                 (PVOID FAR *)&p,0x0000,DCWW_WAIT,&priority,0L))
  49.             {
  50.             if(retval != ERROR_QUE_EMPTY)    /* if error was not from empty queue */
  51.                 error_exit(retval,"DosReadQueue");
  52.             continue;
  53.             }
  54.         DosQueryQueue(qhandle,&qcount);
  55.         printf(
  56.             "Server: (%u pending) message received from %u, priority %02u: %s\n",
  57.                 qcount,qresult.pidProcess,priority,p);
  58.  
  59.         DosFreeSeg(SELECTOROF(p));
  60.  
  61.         KbdCharIn(&kbdkeyinfo,IO_NOWAIT,0);            /* check for key press        */
  62.         if(kbdkeyinfo.fbStatus & FINAL_CHAR_IN)    /* if pressed, break out    */
  63.             break;
  64.         }
  65.     DosCloseQueue(qhandle);
  66.     DosExit(EXIT_PROCESS,0);                            /* and exit                        */
  67.     }
  68.  
  69. void error_exit(USHORT err, char *msg)
  70.     {
  71.     printf("Error %u returned from %s\n",err,msg);
  72.     DosExit(EXIT_PROCESS,0);
  73.     }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.