[7849] | 1 | /* $Id: mailslot.cpp,v 1.3 2002-02-09 12:45:13 sandervl Exp $
|
---|
[6646] | 2 | *
|
---|
[5587] | 3 | * Win32 mailslot APIs
|
---|
| 4 | *
|
---|
| 5 | * Copyright 2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
| 6 | *
|
---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 8 | *
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | #include <odin.h>
|
---|
| 12 | #include <odinwrap.h>
|
---|
| 13 | #include <os2sel.h>
|
---|
| 14 | #include <os2win.h>
|
---|
| 15 | #include <string.h>
|
---|
[21302] | 16 | #include <HandleManager.h>
|
---|
[5587] | 17 | #include <unicode.h>
|
---|
| 18 |
|
---|
[21302] | 19 | #include "hmhandle.h"
|
---|
| 20 | #include "hmmailslot.h"
|
---|
| 21 |
|
---|
[5587] | 22 | #define DBG_LOCALLOG DBG_mailslot
|
---|
| 23 | #include "dbglocal.h"
|
---|
| 24 |
|
---|
| 25 | ODINDEBUGCHANNEL(KERNEL32-MAILSLOT)
|
---|
| 26 |
|
---|
| 27 | /*****************************************************************************
|
---|
| 28 | * Name : HANDLE WIN32API CreateMailslotA
|
---|
| 29 | * Purpose : The CreateMailslot function creates a mailslot with the specified
|
---|
| 30 | * name and returns a handle that a mailslot server can use to
|
---|
| 31 | * perform operations on the mailslot. The mailslot is local to the
|
---|
| 32 | * computer that creates it. An error occurs if a mailslot with
|
---|
| 33 | * the specified name already exists.
|
---|
| 34 | * Parameters: LPCSTR lpName pointer to string for mailslot name
|
---|
| 35 | * DWORD nMaxMessageSize maximum message size
|
---|
| 36 | * DWORD lReadTimeout milliseconds before read time-out
|
---|
| 37 | * LPSECURITY_ATTRIBUTES lpSecurityAttributes pointer to security structure
|
---|
| 38 | * Variables :
|
---|
| 39 | * Result : If the function succeeds, the return value is a handle to
|
---|
| 40 | * the mailslot, for use in server mailslot operations.
|
---|
| 41 | * If the function fails, the return value is INVALID_HANDLE_VALUE.
|
---|
| 42 | * Remark :
|
---|
[6646] | 43 | * Status :
|
---|
[5587] | 44 | *
|
---|
| 45 | * Author : SvL
|
---|
| 46 | *****************************************************************************/
|
---|
| 47 |
|
---|
[7849] | 48 | HANDLE WIN32API CreateMailslotA(LPCSTR lpName, DWORD nMaxMessageSize,
|
---|
| 49 | DWORD lReadTimeout,
|
---|
| 50 | LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
---|
[5587] | 51 | {
|
---|
[21302] | 52 | PHMHANDLE pHandle;
|
---|
| 53 | BOOL rc; /* API return code */
|
---|
| 54 | HMMailslotClass *pDeviceHandler;
|
---|
[5587] | 55 |
|
---|
[21302] | 56 | SetLastError(ERROR_SUCCESS);
|
---|
[5587] | 57 |
|
---|
[21302] | 58 | pHandle = HMHandleGetFreePtr(HMTYPE_MAILSLOT); /* get free handle */
|
---|
| 59 | if (pHandle == NULL) /* oops, no free handles ! */
|
---|
| 60 | {
|
---|
| 61 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); /* use this as error message */
|
---|
| 62 | return INVALID_HANDLE_VALUE;
|
---|
| 63 | }
|
---|
[5587] | 64 |
|
---|
[21302] | 65 | /* call the device handler */
|
---|
| 66 | pDeviceHandler = (HMMailslotClass *)pHandle->pDeviceHandler;
|
---|
| 67 | rc = pDeviceHandler->CreateMailslotA(&pHandle->hmHandleData,
|
---|
| 68 | lpName, nMaxMessageSize,
|
---|
| 69 | lReadTimeout, lpSecurityAttributes);
|
---|
| 70 |
|
---|
| 71 | if (rc == FALSE) /* oops, creation failed within the device handler */
|
---|
| 72 | {
|
---|
| 73 | HMHandleFree(pHandle->hmHandleData.hWin32Handle);
|
---|
| 74 | return INVALID_HANDLE_VALUE; /* signal error */
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | return pHandle->hmHandleData.hWin32Handle;
|
---|
[5587] | 78 | }
|
---|
| 79 | /*****************************************************************************
|
---|
| 80 | * Name : BOOL GetMailslotInfo
|
---|
| 81 | * Purpose : The GetMailslotInfo function retrieves information about the
|
---|
| 82 | * specified mailslot.
|
---|
| 83 | * Parameters: HANDLE hMailslot mailslot handle
|
---|
| 84 | * LPDWORD lpMaxMessageSize address of maximum message size
|
---|
| 85 | * LPDWORD lpNextSize address of size of next message
|
---|
| 86 | * LPDWORD lpMessageCount address of number of messages
|
---|
| 87 | * LPDWORD lpReadTimeout address of read time-out
|
---|
| 88 | * Variables :
|
---|
| 89 | * Result : TRUE / FALSE
|
---|
| 90 | * Remark :
|
---|
[6646] | 91 | * Status :
|
---|
[5587] | 92 | *
|
---|
| 93 | * Author : SvL
|
---|
| 94 | *****************************************************************************/
|
---|
| 95 |
|
---|
[7849] | 96 | BOOL WIN32API GetMailslotInfo(HANDLE hMailslot,
|
---|
| 97 | LPDWORD lpMaxMessageSize,
|
---|
| 98 | LPDWORD lpNextSize,
|
---|
| 99 | LPDWORD lpMessageCount,
|
---|
| 100 | LPDWORD lpReadTimeout)
|
---|
[5587] | 101 | {
|
---|
[21302] | 102 | BOOL lpResult; /* result from the device handler's API */
|
---|
| 103 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
| 104 |
|
---|
| 105 | SetLastError(ERROR_SUCCESS);
|
---|
| 106 | /* validate handle */
|
---|
| 107 | pHMHandle = HMHandleQueryPtr(hMailslot); /* get the index */
|
---|
| 108 | if (pHMHandle == NULL) /* error ? */
|
---|
| 109 | {
|
---|
| 110 | return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE)
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | lpResult = pHMHandle->pDeviceHandler->GetMailslotInfo(&pHMHandle->hmHandleData,
|
---|
| 114 | lpMaxMessageSize,
|
---|
| 115 | lpNextSize,
|
---|
| 116 | lpMessageCount,
|
---|
| 117 | lpReadTimeout);
|
---|
| 118 | return (lpResult); /* deliver return code */
|
---|
[5587] | 119 | }
|
---|
| 120 | /*****************************************************************************
|
---|
| 121 | * Name : BOOL SetMailslotInfo
|
---|
| 122 | * Purpose : The SetMailslotInfo function sets the time-out value used by the
|
---|
| 123 | * specified mailslot for a read operation.
|
---|
| 124 | * Parameters: HANDLE hObject handle to a mailslot object
|
---|
| 125 | * DWORD dwReadTimeout read time-out
|
---|
| 126 | * Variables :
|
---|
| 127 | * Result : TRUE / FALSE
|
---|
| 128 | * Remark :
|
---|
[6646] | 129 | * Status :
|
---|
[5587] | 130 | *
|
---|
| 131 | * Author : SvL
|
---|
| 132 | *****************************************************************************/
|
---|
[21302] | 133 | BOOL SetMailslotInfo(HANDLE hMailslot,
|
---|
| 134 | DWORD dwReadTimeout)
|
---|
| 135 | {
|
---|
| 136 | BOOL fResult;
|
---|
| 137 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
[5587] | 138 |
|
---|
[21302] | 139 | SetLastError(ERROR_SUCCESS);
|
---|
| 140 | /* validate handle */
|
---|
| 141 | pHMHandle = HMHandleQueryPtr(hMailslot); /* get the index */
|
---|
| 142 | if (pHMHandle == NULL) /* error ? */
|
---|
| 143 | {
|
---|
| 144 | return FALSE; //last error set by HMHandleQueryPtr (ERROR_INVALID_HANDLE)
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | fResult = pHMHandle->pDeviceHandler->SetMailslotInfo(&pHMHandle->hmHandleData,
|
---|
| 148 | dwReadTimeout);
|
---|
| 149 |
|
---|
| 150 | return fResult; /* deliver return code */
|
---|
| 151 | }
|
---|
| 152 | /*****************************************************************************
|
---|
| 153 | * Name : HANDLE WIN32API CreateMailslotW
|
---|
| 154 | * Purpose : The CreateMailslot function creates a mailslot with the specified
|
---|
| 155 | * name and returns a handle that a mailslot server can use to
|
---|
| 156 | * perform operations on the mailslot. The mailslot is local to the
|
---|
| 157 | * computer that creates it. An error occurs if a mailslot with
|
---|
| 158 | * the specified name already exists.
|
---|
| 159 | * Parameters: LPCWSTR lpName pointer to string for mailslot name
|
---|
| 160 | * DWORD nMaxMessageSize maximum message size
|
---|
| 161 | * DWORD lReadTimeout milliseconds before read time-out
|
---|
| 162 | * LPSECURITY_ATTRIBUTES lpSecurityAttributes pointer to security
|
---|
| 163 | * structure
|
---|
| 164 | * Variables :
|
---|
| 165 | * Result : If the function succeeds, the return value is a handle to
|
---|
| 166 | * the mailslot, for use in server mailslot operations.
|
---|
| 167 | * If the function fails, the return value is INVALID_HANDLE_VALUE.
|
---|
| 168 | * Remark :
|
---|
| 169 | * Status :
|
---|
| 170 | *
|
---|
| 171 | * Author : SvL
|
---|
| 172 | *****************************************************************************/
|
---|
| 173 |
|
---|
| 174 | HANDLE WIN32API CreateMailslotW(LPCWSTR lpName, DWORD nMaxMessageSize,
|
---|
| 175 | DWORD lReadTimeout,
|
---|
| 176 | LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
---|
[5587] | 177 | {
|
---|
[21302] | 178 | HANDLE rc;
|
---|
| 179 | char *astring;
|
---|
| 180 |
|
---|
| 181 | astring = UnicodeToAsciiString((LPWSTR)lpName);
|
---|
| 182 | rc = CreateMailslotA(astring, nMaxMessageSize, lReadTimeout, lpSecurityAttributes);
|
---|
| 183 | FreeAsciiString(astring);
|
---|
| 184 | return(rc);
|
---|
[5587] | 185 | }
|
---|
[21302] | 186 |
|
---|
| 187 |
|
---|