Figure 10

#define PIPENAME            "\\PIPE\SAMPLE.PIP"
#define DEFAULT_TIMEOUT     5000L        // 5 seconds

static HPIPE                hPipe;
static USHORT               usNoBytes, usRC;
static CHAR                 acInBuf[4096], acOutBuf[4096];

DosMakeNmPipe(PIPENAME, &hPipe, PIPE_ACCESS_DUPLEX,
              PIPE_WAIT | PIPE_TYPE_MESSAGE
                        | PIPE_UNLIMITED_INSTANCES.
              sizeof(acOutBuf), sizeof(acInBuf),
              DEFAULT_TIMEOUT);
while (TRUE)
{
    DosConnectNmPipe(hPipe);
    while (TRUE)
    {
        usRC = DosRead(hPipe, acInBuf, sizeof(acInBuf),
                       &usNoBytes);
        if (usRC || 0 == usNoBytes)
            break;
        // Process request - format output in acOutBuf and
        // response length in usNoBytes
        DosWrite(hPipe, acOutBuf, usNoBytes, &usNoBytes);
    }
    DosDisConnectNmPipe(hPipe);
}

Typical Name Pipe Processing (Server End)


while (TRUE)
{
    usRC = DosOpen(PIPENAME, &hPipe, &usAction, 0L,
                   FILE_NORMAL, FILE_OPEN,
                   OPEN_ACCESS_READWRITE, 0L);
    if (0 == usRC)
        break;
    DosWaitNmPipe(PIPENAME, NP_DEFAULT_WAIT);
}
while (bRequests)      // while requests to be processed
{
    // Construct request in acOutBuf, length in usNoBytes
    DosTransactNmPipe(hPipe, acOutBuf, usNoBytes,
                      acInBuf, &usNoBytes);
    // Process response in acInBuf, lenght in usNoBytes
}
DosClose(hPipe);

Typical Named Pipe Processing (Client End)