1 | /* $Id: mailslot.cpp,v 1.3 2002-02-09 12:45:13 sandervl Exp $
|
---|
2 | *
|
---|
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>
|
---|
16 | #include <HandleManager.h>
|
---|
17 | #include <unicode.h>
|
---|
18 |
|
---|
19 | #include "hmhandle.h"
|
---|
20 | #include "hmmailslot.h"
|
---|
21 |
|
---|
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 :
|
---|
43 | * Status :
|
---|
44 | *
|
---|
45 | * Author : SvL
|
---|
46 | *****************************************************************************/
|
---|
47 |
|
---|
48 | HANDLE WIN32API CreateMailslotA(LPCSTR lpName, DWORD nMaxMessageSize,
|
---|
49 | DWORD lReadTimeout,
|
---|
50 | LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
---|
51 | {
|
---|
52 | PHMHANDLE pHandle;
|
---|
53 | BOOL rc; /* API return code */
|
---|
54 | HMMailslotClass *pDeviceHandler;
|
---|
55 |
|
---|
56 | SetLastError(ERROR_SUCCESS);
|
---|
57 |
|
---|
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 | }
|
---|
64 |
|
---|
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;
|
---|
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 :
|
---|
91 | * Status :
|
---|
92 | *
|
---|
93 | * Author : SvL
|
---|
94 | *****************************************************************************/
|
---|
95 |
|
---|
96 | BOOL WIN32API GetMailslotInfo(HANDLE hMailslot,
|
---|
97 | LPDWORD lpMaxMessageSize,
|
---|
98 | LPDWORD lpNextSize,
|
---|
99 | LPDWORD lpMessageCount,
|
---|
100 | LPDWORD lpReadTimeout)
|
---|
101 | {
|
---|
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 */
|
---|
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 :
|
---|
129 | * Status :
|
---|
130 | *
|
---|
131 | * Author : SvL
|
---|
132 | *****************************************************************************/
|
---|
133 | BOOL SetMailslotInfo(HANDLE hMailslot,
|
---|
134 | DWORD dwReadTimeout)
|
---|
135 | {
|
---|
136 | BOOL fResult;
|
---|
137 | PHMHANDLE pHMHandle; /* pointer to the handle structure in the table */
|
---|
138 |
|
---|
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)
|
---|
177 | {
|
---|
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);
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|