home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_11 / 8n11045a < prev    next >
Text File  |  1990-09-19  |  2KB  |  55 lines

  1.  
  2.  
  3.  
  4.  
  5.          #define PIPENAME            "\\PIPE\SAMPLE.PIP"
  6.          #define DEFAULT_TIMEOUT     5000L        // 5 seconds
  7.  
  8.          static HPIPE                hPipe;
  9.          static USHORT               usNoBytes, usRC;
  10.          static CHAR                 acInBuf[4096], acOutBuf[4096];
  11.  
  12.          DosMakeNmPipe(PIPENAME, &hPipe, PIPE_ACCESS_DUPLEX,
  13.                        PIPE_WAIT | PIPE_TYPE_MESSAGE
  14.                                  | PIPE_UNLIMITED_INSTANCES,
  15.                        sizeof(acOutBuf), sizeof(acInBuf),
  16.                        DEFAULT_TIMEOUT);
  17.          while (TRUE)
  18.          {
  19.              DosConnectNmPipe(hPipe);
  20.              while (TRUE)
  21.              {
  22.                  usRC = DosRead(hPipe, acInBuf, sizeof(acInBuf),
  23.                                 &usNoBytes);
  24.                  if (usRC || 0 == usNoBytes)
  25.                      break;
  26.                  // Process request - format output in acOutBuf and
  27.                  // response length in usNoBytes
  28.                  DosWrite(hPipe, acOutBuf, usNoBytes, &usNoBytes);
  29.              }
  30.              DosDisConnectNmPipe(hPipe);
  31.          }
  32.  
  33.  
  34.  
  35.  
  36.          while (TRUE)
  37.          {
  38.              usRC = DosOpen(PIPENAME, &hPipe, &usAction, 0L,
  39.                             FILE_NORMAL, FILE_OPEN,
  40.                             OPEN_ACCESS_READWRITE, 0L);
  41.              if (0 == usRC)
  42.                  break;
  43.              DosWaitNmPipe(PIPENAME, NP_DEFAULT_WAIT);
  44.          }
  45.          while (bRequests)      // while requests to be processed
  46.          {
  47.              // Construct request in acOutBuf, length in usNoBytes
  48.              DosTransactNmPipe(hPipe, acOutBuf, usNoBytes,
  49.                                acInBuf, &usNoBytes);
  50.              // Process response in acInBuf, length in usNoBytes
  51.          }
  52.          DosClose(hPipe);
  53.  
  54.  
  55.