ReactOS 0.4.15-dev-8145-ga541a46
mailslot.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/file/mailslot.c
5 * PURPOSE: Mailslot functions
6 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
7 * UPDATE HISTORY:
8 */
9
10/* INCLUDES *******************************************************************/
11
12#include <k32.h>
13#define NDEBUG
14#include <debug.h>
15
16/* FUNCTIONS ******************************************************************/
17
18/*
19 * @implemented
20 */
24 IN DWORD nMaxMessageSize,
25 IN DWORD lReadTimeout,
26 IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
27{
28 /* Call the W(ide) function */
29 ConvertWin32AnsiObjectApiToUnicodeApi2(Mailslot, lpName, nMaxMessageSize, lReadTimeout, lpSecurityAttributes);
30}
31
32/*
33 * @implemented
34 */
38 IN DWORD nMaxMessageSize,
39 IN DWORD lReadTimeout,
40 IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
41{
43 UNICODE_STRING MailslotName;
44 HANDLE MailslotHandle;
47 LARGE_INTEGER DefaultTimeOut;
51
53 if (!Result)
54 {
57 }
58
59 DPRINT("Mailslot name: %wZ\n", &MailslotName);
60
61 if (lpSecurityAttributes)
62 {
63 SecurityDescriptor = lpSecurityAttributes->lpSecurityDescriptor;
64 if(lpSecurityAttributes->bInheritHandle) Attributes |= OBJ_INHERIT;
65 }
66
68 &MailslotName,
70 NULL,
72
73 if (lReadTimeout == MAILSLOT_WAIT_FOREVER)
74 {
75 /* Set the max */
76 DefaultTimeOut.QuadPart = 0xFFFFFFFFFFFFFFFFLL;
77 }
78 else
79 {
80 /* Convert to NT format */
81 DefaultTimeOut.QuadPart = lReadTimeout * -10000LL;
82 }
83
84 Status = NtCreateMailslotFile(&MailslotHandle,
87 &Iosb,
89 0,
90 nMaxMessageSize,
91 &DefaultTimeOut);
92
95 {
97 }
98
99 RtlFreeHeap(RtlGetProcessHeap(), 0, MailslotName.Buffer);
100
101 if (!NT_SUCCESS(Status))
102 {
103 DPRINT1("NtCreateMailslot failed (Status %x)!\n", Status);
106 }
107
108 return MailslotHandle;
109}
110
111/*
112 * @implemented
113 */
114BOOL
115WINAPI
117 IN LPDWORD lpMaxMessageSize,
118 IN LPDWORD lpNextSize,
119 IN LPDWORD lpMessageCount,
120 IN LPDWORD lpReadTimeout)
121{
126
127 Status = NtQueryInformationFile(hMailslot,
128 &Iosb,
129 &Buffer,
132 if (!NT_SUCCESS(Status))
133 {
134 DPRINT1("NtQueryInformationFile failed (Status %x)!\n", Status);
136 return FALSE;
137 }
138
139 if (lpMaxMessageSize) *lpMaxMessageSize = Buffer.MaximumMessageSize;
140 if (lpNextSize) *lpNextSize = Buffer.NextMessageSize;
141 if (lpMessageCount) *lpMessageCount = Buffer.MessagesAvailable;
142
143 if (lpReadTimeout)
144 {
145 if (Buffer.ReadTimeout.QuadPart == 0xFFFFFFFFFFFFFFFFLL)
146 {
147 *lpReadTimeout = MAILSLOT_WAIT_FOREVER;
148 }
149 else
150 {
151 Timeout.QuadPart = -Buffer.ReadTimeout.QuadPart;
153 if (Timeout.HighPart == 0)
154 {
155 *lpReadTimeout = Timeout.LowPart;
156 }
157 else
158 {
159 *lpReadTimeout = 0xFFFFFFFE;
160 }
161 }
162 }
163
164 return TRUE;
165}
166
167/*
168 * @implemented
169 */
170BOOL
171WINAPI
173 IN DWORD lReadTimeout)
174{
179
180 if (lReadTimeout == MAILSLOT_WAIT_FOREVER)
181 {
182 /* Set the max */
183 Timeout.QuadPart = 0xFFFFFFFFFFFFFFFFLL;
184 }
185 else
186 {
187 /* Convert to NT format */
188 Timeout.QuadPart = lReadTimeout * -10000LL;
189 }
190
191 Buffer.ReadTimeout = &Timeout;
192
193 Status = NtSetInformationFile(hMailslot,
194 &Iosb,
195 &Buffer,
198 if (!NT_SUCCESS(Status))
199 {
200 DPRINT1("NtSetInformationFile failed (Status %x)!\n", Status);
202 return FALSE;
203 }
204
205 return TRUE;
206}
207
208/* EOF */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define ConvertWin32AnsiObjectApiToUnicodeApi2(obj, name,...)
Definition: base_x.h:65
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
HANDLE WINAPI CreateMailslotW(IN LPCWSTR lpName, IN DWORD nMaxMessageSize, IN DWORD lReadTimeout, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: mailslot.c:37
BOOL WINAPI SetMailslotInfo(IN HANDLE hMailslot, IN DWORD lReadTimeout)
Definition: mailslot.c:172
BOOL WINAPI GetMailslotInfo(IN HANDLE hMailslot, IN LPDWORD lpMaxMessageSize, IN LPDWORD lpNextSize, IN LPDWORD lpMessageCount, IN LPDWORD lpReadTimeout)
Definition: mailslot.c:116
HANDLE WINAPI CreateMailslotA(IN LPCSTR lpName, IN DWORD nMaxMessageSize, IN DWORD lReadTimeout, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: mailslot.c:23
return Iosb
Definition: create.c:4402
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
@ FileMailslotSetInformation
Definition: from_kernel.h:88
@ FileMailslotQueryInformation
Definition: from_kernel.h:87
#define FILE_WRITE_THROUGH
Definition: from_kernel.h:26
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_INHERIT
Definition: winternl.h:225
NTSYSAPI LONGLONG WINAPI RtlExtendedLargeIntegerDivide(LONGLONG, INT, INT *)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define MAILSLOT_WAIT_FOREVER
Definition: finfo.c:19
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
#define SYNCHRONIZE
Definition: nt_native.h:61
#define WRITE_DAC
Definition: nt_native.h:59
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3096
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
NTSTATUS NTAPI NtCreateMailslotFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG CreateOptions, IN ULONG MailslotQuota, IN ULONG MaxMessageSize, IN PLARGE_INTEGER TimeOut)
Definition: file.c:3789
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
static ULONG Timeout
Definition: ping.c:61
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define DPRINT
Definition: sndvol32.h:73
uint32_t * LPDWORD
Definition: typedefs.h:59
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_In_ LPCSTR lpName
Definition: winbase.h:2789
#define WINAPI
Definition: msvc.h:6
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:191
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185