ReactOS  0.4.13-dev-249-gcba1a2f
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  */
21 HANDLE
22 WINAPI
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  */
35 HANDLE
36 WINAPI
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  {
56  return INVALID_HANDLE_VALUE;
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,
69  Attributes,
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);
105  return INVALID_HANDLE_VALUE;
106  }
107 
108  return MailslotHandle;
109 }
110 
111 /*
112  * @implemented
113  */
114 BOOL
115 WINAPI
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  */
170 BOOL
171 WINAPI
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 */
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#define LL
Definition: tui.h:72
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
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:3788
BOOL WINAPI SetMailslotInfo(IN HANDLE hMailslot, IN DWORD lReadTimeout)
Definition: mailslot.c:172
HANDLE WINAPI CreateMailslotW(IN LPCWSTR lpName, IN DWORD nMaxMessageSize, IN DWORD lReadTimeout, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: mailslot.c:37
_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:182
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
_In_ LPCSTR lpName
Definition: winbase.h:2729
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
HANDLE WINAPI CreateMailslotA(IN LPCSTR lpName, IN DWORD nMaxMessageSize, IN DWORD lReadTimeout, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: mailslot.c:23
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FILE_WRITE_THROUGH
Definition: from_kernel.h:26
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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:426
void DPRINT(...)
Definition: polytest.cpp:61
NTSYSAPI LONGLONG WINAPI RtlExtendedLargeIntegerDivide(LONGLONG, INT, INT *)
Definition: bufpool.h:45
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
const char * LPCSTR
Definition: xmlstorage.h:183
BOOL WINAPI GetMailslotInfo(IN HANDLE hMailslot, IN LPDWORD lpMaxMessageSize, IN LPDWORD lpNextSize, IN LPDWORD lpMessageCount, IN LPDWORD lpReadTimeout)
Definition: mailslot.c:116
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_INHERIT
Definition: winternl.h:225
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WRITE_DAC
Definition: nt_native.h:59
#define SetLastError(x)
Definition: compat.h:409
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define GENERIC_READ
Definition: compat.h:124
NTSTATUS NTAPI NtQueryInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
#define SYNCHRONIZE
Definition: nt_native.h:61
Status
Definition: gdiplustypes.h:24
#define MAILSLOT_WAIT_FOREVER
Definition: finfo.c:19
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
static ULONG Timeout
Definition: ping.c:61
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
#define DPRINT1
Definition: precomp.h:8
uint32_t * LPDWORD
Definition: typedefs.h:57
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define ConvertWin32AnsiObjectApiToUnicodeApi2(obj, name,...)
Definition: base_x.h:65
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:3042
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)
LONGLONG QuadPart
Definition: typedefs.h:112