Annotation of mstools/samples/sdktools/rshell/server/pipe.c, revision 1.1

1.1     ! root        1: /****************************** Module Header ******************************\
        !             2: * Module Name: pipe.c
        !             3: *
        !             4: * Copyright (c) 1991, Microsoft Corporation
        !             5: *
        !             6: * This module implements a version of CreatePipe that allows
        !             7: * control over the file flags. e.g. FILE_FLAG_OVERLAPPED
        !             8: *
        !             9: * History:
        !            10: * 06-29-92 Davidc       Created.
        !            11: \***************************************************************************/
        !            12: 
        !            13: #include "rcmdsrv.h"
        !            14: 
        !            15: 
        !            16: ULONG PipeSerialNumber = 0;
        !            17: 
        !            18: #define PIPE_FORMAT_STRING  "\\\\.\\pipe\\rshsrv\\%08x.%08x"
        !            19: 
        !            20: 
        !            21: 
        !            22: /////////////////////////////////////////////////////////////////////////////
        !            23: //
        !            24: // MyCreatePipe
        !            25: //
        !            26: // Creates a uni-directional pipe with the specified security attributes,
        !            27: // size and timeout. The handles are opened with the specified file-flags
        !            28: // so FILE_FLAG_OVERLAPPED etc. can be specified.
        !            29: //
        !            30: // Returns handles to both end of pipe in passed parameters.
        !            31: //
        !            32: // Returns TRUE on success, FALSE on failure. (GetLastError() for details)
        !            33: //
        !            34: /////////////////////////////////////////////////////////////////////////////
        !            35: 
        !            36: BOOL
        !            37: MyCreatePipe(
        !            38:     LPHANDLE ReadHandle,
        !            39:     LPHANDLE WriteHandle,
        !            40:     LPSECURITY_ATTRIBUTES SecurityAttributes,
        !            41:     DWORD Size,
        !            42:     DWORD Timeout,
        !            43:     DWORD ReadHandleFlags,
        !            44:     DWORD WriteHandleFlags
        !            45:     )
        !            46: {
        !            47:     CHAR PipeName[MAX_PATH];
        !            48: 
        !            49:     //
        !            50:     // Make up a random pipe name
        !            51:     //
        !            52: 
        !            53:     sprintf(PipeName, PIPE_FORMAT_STRING, GetCurrentProcessId(), PipeSerialNumber++);
        !            54: 
        !            55: 
        !            56:     //
        !            57:     // Create the pipe
        !            58:     //
        !            59: 
        !            60:     *ReadHandle = CreateNamedPipeA(
        !            61:                         PipeName,
        !            62:                         PIPE_ACCESS_INBOUND | ReadHandleFlags,
        !            63:                         PIPE_TYPE_BYTE | PIPE_WAIT,
        !            64:                         1,             // Number of pipes
        !            65:                         Size,          // Out buffer size
        !            66:                         Size,          // In buffer size
        !            67:                         Timeout,       // Timeout in ms
        !            68:                         SecurityAttributes
        !            69:                       );
        !            70: 
        !            71:     if (*ReadHandle == NULL) {
        !            72:         DbgPrint("MyCreatePipe: failed to created pipe <%s>, error = %d\n", PipeName, GetLastError());
        !            73:         return(FALSE);
        !            74:     }
        !            75: 
        !            76:     //
        !            77:     // Open the client end of the pipe
        !            78:     //
        !            79: 
        !            80: 
        !            81:     *WriteHandle = CreateFileA(
        !            82:                         PipeName,
        !            83:                         GENERIC_WRITE,
        !            84:                         0,                         // No sharing
        !            85:                         SecurityAttributes,
        !            86:                         OPEN_EXISTING,
        !            87:                         FILE_ATTRIBUTE_NORMAL | WriteHandleFlags,
        !            88:                         NULL                       // Template file
        !            89:                       );
        !            90: 
        !            91:     if (*WriteHandle == INVALID_HANDLE_VALUE ) {
        !            92:         DbgPrint("Failed to open client end of pipe <%s>, error = %d\n", PipeName, GetLastError());
        !            93:         MyCloseHandle(*ReadHandle, "async pipe (server(read) side)");
        !            94:         return(FALSE);
        !            95:     }
        !            96: 
        !            97: 
        !            98:     //
        !            99:     // Everything succeeded
        !           100:     //
        !           101: 
        !           102:     return(TRUE);
        !           103: }
        !           104: 

unix.superglobalmegacorp.com

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