Changeset 10132 for trunk/src


Ignore:
Timestamp:
Jun 2, 2003, 6:25:36 PM (22 years ago)
Author:
sandervl
Message:

CreatePipe: create unique named pipe

Location:
trunk/src/kernel32
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/HandleManager.cpp

    r10109 r10132  
    1 /* $Id: HandleManager.cpp,v 1.103 2003-05-23 13:53:42 sandervl Exp $ */
     1/* $Id: HandleManager.cpp,v 1.104 2003-06-02 16:25:15 sandervl Exp $ */
    22
    33/*
     
    45234523 * Author    : Przemyslaw Dobrowolski
    45244524 *****************************************************************************/
    4525 DWORD HMCreateNamedPipe(LPCTSTR lpName,
     4525HANDLE HMCreateNamedPipe(LPCTSTR lpName,
    45264526                      DWORD   dwOpenMode,
    45274527                      DWORD   dwPipeMode,
     
    45464546  {
    45474547    SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
    4548     return 0;
     4548    return INVALID_HANDLE_VALUE;
    45494549  }
    45504550
     
    45754575  {
    45764576      TabWin32Handles[iIndexNew].hmHandleData.hHMHandle = INVALID_HANDLE_VALUE;
    4577       return 0;                                           /* signal error */
     4577      return INVALID_HANDLE_VALUE;                         /* signal error */
    45784578  }
    45794579
     
    48204820
    48214821/*****************************************************************************
    4822  * Name      : HMCreatePipe
    4823  * Purpose   :
    4824  * Parameters:
    4825  * Variables :
    4826  * Result    :
    4827  * Remark    :
    4828  * Status    : NOT TESTED!
    4829  *
    4830  * Author    : Przemyslaw Dobrowolski
    4831  *****************************************************************************/
    4832 BOOL HMCreatePipe(PHANDLE phRead,
    4833                   PHANDLE phWrite,
    4834                   LPSECURITY_ATTRIBUTES lpsa,
    4835                   DWORD                 cbPipe)
    4836 {
    4837   int             iIndex;                     /* index into the handle table */
    4838   int             iIndexNewRead;              /* index into the handle table */
    4839   int             iIndexNewWrite;             /* index into the handle table */
    4840   HMDeviceHandler *pDeviceHandler;            /* device handler for this handle */
    4841   PHMHANDLEDATA   pHMHandleData;
    4842   HANDLE          rc;                                     /* API return code */
    4843 
    4844   SetLastError(ERROR_SUCCESS);
    4845 
    4846   pDeviceHandler = HMGlobals.pHMNamedPipe;         /* device is predefined */
    4847 
    4848   iIndexNewRead = _HMHandleGetFree();              /* get free handle */
    4849   if (-1 == iIndexNewRead)                         /* oops, no free handles ! */
    4850   {
    4851     SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
    4852     return 0;
    4853   }
    4854 
    4855   iIndexNewWrite = _HMHandleGetFree();              /* get free handle */
    4856   if (-1 == iIndexNewWrite)                         /* oops, no free handles ! */
    4857   {
    4858     HMHandleFree(iIndexNewRead);
    4859     SetLastError(ERROR_NOT_ENOUGH_MEMORY);      /* use this as error message */
    4860     return 0;
    4861   }
    4862 
    4863 
    4864   /* initialize the complete HMHANDLEDATA structure */
    4865   pHMHandleData = &TabWin32Handles[iIndexNewRead].hmHandleData;
    4866   pHMHandleData->dwAccess   = 0;
    4867   pHMHandleData->dwShare    = 0;
    4868   pHMHandleData->dwCreation = 0;
    4869   pHMHandleData->dwFlags    = 0;
    4870   pHMHandleData->lpHandlerData = NULL;
    4871 
    4872   /* we've got to mark the handle as occupied here, since another device */
    4873   /* could be created within the device handler -> deadlock */
    4874 
    4875   /* write appropriate entry into the handle table if open succeeded */
    4876   TabWin32Handles[iIndexNewRead].hmHandleData.hHMHandle = iIndexNewRead;
    4877   TabWin32Handles[iIndexNewRead].pDeviceHandler         = pDeviceHandler;
    4878 
    4879   /* initialize the complete HMHANDLEDATA structure */
    4880   pHMHandleData = &TabWin32Handles[iIndexNewWrite].hmHandleData;
    4881   pHMHandleData->dwAccess   = 0;
    4882   pHMHandleData->dwShare    = 0;
    4883   pHMHandleData->dwCreation = 0;
    4884   pHMHandleData->dwFlags    = 0;
    4885   pHMHandleData->lpHandlerData = NULL;
    4886 
    4887   /* we've got to mark the handle as occupied here, since another device */
    4888   /* could be created within the device handler -> deadlock */
    4889 
    4890   /* write appropriate entry into the handle table if open succeeded */
    4891   TabWin32Handles[iIndexNewWrite].hmHandleData.hHMHandle = iIndexNewWrite;
    4892   TabWin32Handles[iIndexNewWrite].pDeviceHandler         = pDeviceHandler;
    4893   /* call the device handler */
    4894 
    4895   rc = pDeviceHandler->CreatePipe(&TabWin32Handles[iIndexNewRead].hmHandleData,
    4896                                   &TabWin32Handles[iIndexNewWrite].hmHandleData,
    4897                                   lpsa,
    4898                                   cbPipe);
    4899 
    4900   if (rc == 0)     /* oops, creation failed within the device handler */
    4901   {
    4902       HMHandleFree(iIndexNewRead);
    4903       HMHandleFree(iIndexNewWrite);
    4904       return FALSE;                                           /* signal error */
    4905   }
    4906 
    4907   dprintf(("Read pipe %x, Write pipe %x", iIndexNewRead, iIndexNewWrite));
    4908   if(lpsa && lpsa->bInheritHandle) {
    4909       dprintf(("Set inheritance for child processes"));
    4910       HMSetHandleInformation(iIndexNewRead, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
    4911       HMSetHandleInformation(iIndexNewWrite, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
    4912   }
    4913 
    4914   *phRead  = iIndexNewRead;
    4915   *phWrite = iIndexNewWrite;
    4916 
    4917   return TRUE;
    4918 }
    4919 
    4920 /*****************************************************************************
    49214822 * Name      : HMCreateMailslotA
    49224823 * Purpose   :
  • trunk/src/kernel32/hmdevice.cpp

    r10073 r10132  
    1 /* $Id: hmdevice.cpp,v 1.36 2003-05-06 12:06:09 sandervl Exp $ */
     1/* $Id: hmdevice.cpp,v 1.37 2003-06-02 16:25:16 sandervl Exp $ */
    22
    33/*
     
    17821782
    17831783/*****************************************************************************
    1784  * Name      : BOOL HMDeviceHandler::CreatePipe
    1785  * Purpose   :
    1786  * Variables :
    1787  * Result    :
    1788  * Remark    :
    1789  * Status    :
    1790  *
    1791  * Author    : Przemyslaw Dobrowolski
    1792  *****************************************************************************/
    1793 BOOL HMDeviceHandler::CreatePipe(PHMHANDLEDATA pHMHandleDataRead,
    1794                                  PHMHANDLEDATA pHMHandleDataWrite,
    1795                                  LPSECURITY_ATTRIBUTES lpsa,
    1796                                  DWORD         cbPipe)
    1797 {
    1798   dprintf(("KERNEL32: ERROR: HandleManager::DeviceHandler::CreatePipe (%08x,%08x)\n",
    1799            pHMHandleDataRead->hHMHandle,pHMHandleDataWrite->hHMHandle));
    1800 
    1801     return(FALSE);
    1802 }
    1803 /*****************************************************************************
    18041784 * Name      : BOOL HMDeviceHandler::GetMailslotInfo
    18051785 * Purpose   :
  • trunk/src/kernel32/hmdevice.h

    r10073 r10132  
    1 /* $Id: hmdevice.h,v 1.35 2003-05-06 12:06:09 sandervl Exp $ */
     1/* $Id: hmdevice.h,v 1.36 2003-06-02 16:25:17 sandervl Exp $ */
    22
    33/*
     
    452452                                      LPDWORD lpdwCollectDataTimeout);
    453453
    454   virtual BOOL  CreatePipe(PHMHANDLEDATA pHMHandleDataRead,
    455                            PHMHANDLEDATA pHMHandleDataWrite,
    456                            LPSECURITY_ATTRIBUTES lpsa,
    457                            DWORD         cbPipe);
    458 
    459454  virtual BOOL GetMailslotInfo(PHMHANDLEDATA pHMHandleData,
    460455                               LPDWORD lpMaxMessageSize,
  • trunk/src/kernel32/hmnpipe.cpp

    r9660 r10132  
    1 /* $Id: hmnpipe.cpp,v 1.10 2003-01-10 15:19:53 sandervl Exp $ */
     1/* $Id: hmnpipe.cpp,v 1.11 2003-06-02 16:25:18 sandervl Exp $ */
    22/*
    33 * Project Odin Software License can be found in LICENSE.TXT
     
    1212 *
    1313 */
     14#include <stdio.h>
    1415#include <odin.h>
    1516#include <os2win.h>
     
    187188//******************************************************************************
    188189//******************************************************************************
    189 BOOL HMDeviceNamedPipeClass::CreatePipe(PHMHANDLEDATA pHMHandleDataRead,
    190                                         PHMHANDLEDATA pHMHandleDataWrite,
    191                                         LPSECURITY_ATTRIBUTES lpsa,
    192                                         DWORD         cbPipe)
    193 {
    194   pHMHandleDataRead->dwInternalType  = HMTYPE_PIPE;
    195   pHMHandleDataWrite->dwInternalType = HMTYPE_PIPE;
    196 
    197   dprintfl(("KERNEL32: HMDeviceNamedPipeClass::CreatePipe"));
    198 
    199   if(!OSLibDosCreatePipe(&pHMHandleDataRead->hHMHandle,
    200                          &pHMHandleDataWrite->hHMHandle,
    201                          lpsa,
    202                          cbPipe))
    203   {
    204      return TRUE;
    205   }
    206   else
    207      return FALSE;
    208 }
    209 //******************************************************************************
    210 //******************************************************************************
    211190BOOL HMDeviceNamedPipeClass::ConnectNamedPipe( PHMHANDLEDATA pHMHandleData,
    212191                                               LPOVERLAPPED lpOverlapped)
  • trunk/src/kernel32/hmnpipe.h

    r7927 r10132  
    1 /* $Id: hmnpipe.h,v 1.6 2002-02-15 19:14:52 sandervl Exp $ */
     1/* $Id: hmnpipe.h,v 1.7 2003-06-02 16:25:18 sandervl Exp $ */
    22/*
    33 * Project Odin Software License can be found in LICENSE.TXT
     
    9595                                    LPDWORD       arg3,
    9696                                    BOOL          arg4);
    97 
    98   virtual BOOL  CreatePipe(PHMHANDLEDATA pHMHandleDataRead,
    99                            PHMHANDLEDATA pHMHandleDataWrite,
    100                            LPSECURITY_ATTRIBUTES lpsa,
    101                            DWORD         cbPipe);
    102 
    103 
    10497};
    10598
  • trunk/src/kernel32/npipe.cpp

    r9975 r10132  
    1 /* $Id: npipe.cpp,v 1.11 2003-04-02 12:58:30 sandervl Exp $ */
     1/* $Id: npipe.cpp,v 1.12 2003-06-02 16:25:18 sandervl Exp $ */
    22/*
    33 * Win32 Named pipes API
     
    3838                         LPSECURITY_ATTRIBUTES lpsa, DWORD cbPipe)
    3939{
    40   return (HMCreatePipe(phRead,phWrite,lpsa,cbPipe));
     40  char        szPipeName[64];
     41  HANDLE      hPipeRead, hPipeWrite;
     42
     43  // create a unique pipe name
     44  for(int i=0;i<16;i++)
     45  {
     46        sprintf(szPipeName, "\\\\.\\pipe\\Win32.Pipes.%08x.%08x", GetCurrentProcessId(), GetCurrentTime());
     47        hPipeRead = ::CreateNamedPipeA(szPipeName, PIPE_ACCESS_DUPLEX,
     48                                     PIPE_TYPE_BYTE | PIPE_WAIT, 1, cbPipe, cbPipe,
     49                                     NMPWAIT_USE_DEFAULT_WAIT, lpsa);
     50        if(hPipeRead != INVALID_HANDLE_VALUE) break;
     51
     52        Sleep(10);
     53  }
     54
     55  if (hPipeRead == INVALID_HANDLE_VALUE) {
     56      dprintf(("ERROR: Unable to create named pipe with unique name!! (%s)", szPipeName));
     57      return FALSE;
     58  }
     59
     60  ULONG mode = PIPE_NOWAIT|PIPE_READMODE_BYTE;
     61
     62  //Set pipe in non-blocking mode
     63  SetNamedPipeHandleState(hPipeRead, &mode, NULL, NULL);
     64
     65  //Set pipe in listening mode (so the next CreateFile will succeed)
     66  ConnectNamedPipe(hPipeRead, NULL);
     67
     68  //Put pipe back in blocking mode
     69  mode = PIPE_WAIT|PIPE_READMODE_BYTE;
     70  SetNamedPipeHandleState(hPipeRead, &mode, NULL, NULL);
     71
     72  //Create write pipe
     73  hPipeWrite = CreateFileA(szPipeName, GENERIC_WRITE, 0, lpsa, OPEN_EXISTING, 0, 0);
     74  if (hPipeWrite == INVALID_HANDLE_VALUE)
     75  {
     76      dprintf(("ERROR: Unable to create write handle for anonymous pipe!!"));
     77      CloseHandle(hPipeRead);
     78      return FALSE;
     79  }
     80
     81  dprintf(("Created pipe with handles %x and %x", hPipeRead, hPipeWrite));
     82  *phRead  = hPipeRead;
     83  *phWrite = hPipeWrite;
     84  return TRUE;
    4185}
    4286//******************************************************************************
  • trunk/src/kernel32/oslibdos.cpp

    r9945 r10132  
    1 /* $Id: oslibdos.cpp,v 1.119 2003-03-27 14:00:52 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.120 2003-06-02 16:25:19 sandervl Exp $ */
    22/*
    33 * Wrappers for OS/2 Dos* API
     
    15951595   DWORD rc, ulAction;
    15961596
    1597   if (dwOpenMode & PIPE_ACCESS_DUPLEX_W)
     1597  if ((dwOpenMode & PIPE_ACCESS_DUPLEX_W) == PIPE_ACCESS_DUPLEX_W)
    15981598    dwOS2Mode |= NP_ACCESS_DUPLEX;
    15991599  else
Note: See TracChangeset for help on using the changeset viewer.