home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mandlcpp.zip / client.cpp < prev    next >
C/C++ Source or Header  |  1993-06-19  |  1KB  |  72 lines

  1. #define INCL_DOSNMPIPES
  2. #include <os2.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "communication.h"
  6.  
  7.  
  8. int main(int argc, char **argv)
  9. {       (void)argc;
  10.     (void)argv;
  11.     HPIPE hPipe;
  12.     APIRET iRet;
  13.     unsigned long iAction;
  14.  
  15.     if (iRet = DosWaitNPipe(pPipeName, -1))
  16.     {    fprintf(stderr,
  17.             "DosWaitNPipe() returned error code %u!\n",
  18.             iRet);
  19.         exit(1);
  20.     }
  21.     if (iRet = DosOpen(pPipeName,
  22.         &hPipe,
  23.         &iAction,
  24.         0,
  25.         0,
  26.         0
  27.         | OPEN_ACTION_FAIL_IF_NEW
  28.         | OPEN_ACTION_OPEN_IF_EXISTS
  29.         ,
  30.         0
  31.         //| OPEN_FLAGS_WRITE_THROUGH
  32.         //| OPEN_FLAGS_FAIL_ON_ERROR
  33.         //| OPEN_FLAGS_NO_CACHE
  34.         //| OPEN_FLAGS_SEQUENTIAL
  35.         //| OPEN_FLAGS_NOINHERIT
  36.         | OPEN_SHARE_DENYNONE
  37.         | OPEN_ACCESS_WRITEONLY
  38.         ,
  39.         (EAOP2*)0))
  40.     {    fprintf(stderr,
  41.             "DosOpen() returned error code %u!\n",
  42.             iRet);
  43.         exit(1);
  44.     }
  45.     {       char acBuffer[1024];
  46.         unsigned long iBytesRead;
  47.         unsigned long iBytesWritten;
  48.  
  49.  
  50.         while (!(iRet = DosRead(0,
  51.             acBuffer,
  52.             sizeof acBuffer,
  53.             &iBytesRead)
  54.             && iBytesRead))
  55.         {    APIRET iRet;
  56.  
  57.             if (iRet = DosWrite(hPipe,
  58.                 acBuffer,
  59.                 iBytesRead,
  60.                 &iBytesWritten))
  61.              {    fprintf(stderr,
  62.                     "DosWrite returned error code %u\n!",
  63.                     iRet);
  64.                 break;
  65.              }
  66.         }
  67.         if (iRet)            fprintf(stderr,
  68.                 "DosRead returned error code %u\n!",
  69.                 iRet);
  70.     }
  71.     return 0;
  72. }