3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/mailslot.c
6 * PURPOSE: Mailslot functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
11 /* INCLUDES *****************************************************************/
16 #include <kernel32/kernel32.h>
18 /* FUNCTIONS ****************************************************************/
24 CreateMailslotA(LPCSTR lpName,
25 DWORD nMaxMessageSize,
27 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
29 HANDLE MailslotHandle;
33 RtlInitAnsiString(&NameA, (LPSTR)lpName);
34 RtlAnsiStringToUnicodeString(&NameU, &NameA, TRUE);
36 MailslotHandle = CreateMailslotW(NameU.Buffer,
39 lpSecurityAttributes);
41 RtlFreeUnicodeString(&NameU);
43 return(MailslotHandle);
51 CreateMailslotW(LPCWSTR lpName,
52 DWORD nMaxMessageSize,
54 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
56 OBJECT_ATTRIBUTES ObjectAttributes;
57 UNICODE_STRING MailslotName;
58 HANDLE MailslotHandle;
61 LARGE_INTEGER DefaultTimeOut;
64 Result = RtlDosPathNameToNtPathName_U((LPWSTR)lpName,
70 SetLastError(ERROR_PATH_NOT_FOUND);
71 return(INVALID_HANDLE_VALUE);
74 DPRINT("Mailslot name: %wZ\n", &MailslotName);
76 InitializeObjectAttributes(&ObjectAttributes,
82 DefaultTimeOut.QuadPart = lReadTimeout * 10000;
84 Status = NtCreateMailslotFile(&MailslotHandle,
85 GENERIC_READ | SYNCHRONIZE | WRITE_DAC,
93 RtlFreeUnicodeString(&MailslotName);
95 if (!NT_SUCCESS(Status))
97 DPRINT("NtCreateMailslot failed (Status %x)!\n", Status);
98 SetLastErrorByStatus (Status);
99 return(INVALID_HANDLE_VALUE);
102 return(MailslotHandle);
110 GetMailslotInfo(HANDLE hMailslot,
111 LPDWORD lpMaxMessageSize,
113 LPDWORD lpMessageCount,
114 LPDWORD lpReadTimeout)
116 FILE_MAILSLOT_QUERY_INFORMATION Buffer;
117 IO_STATUS_BLOCK Iosb;
120 Status = NtQueryInformationFile(hMailslot,
123 sizeof(FILE_MAILSLOT_QUERY_INFORMATION),
124 FileMailslotQueryInformation);
125 if (!NT_SUCCESS(Status))
127 DPRINT("NtQueryInformationFile failed (Status %x)!\n", Status);
128 SetLastErrorByStatus (Status);
132 if (lpMaxMessageSize != NULL)
134 *lpMaxMessageSize = Buffer.MaxMessageSize;
136 if (lpNextSize != NULL)
138 *lpNextSize = Buffer.NextSize;
140 if (lpMessageCount != NULL)
142 *lpMessageCount = Buffer.MessageCount;
144 if (lpReadTimeout != NULL)
146 *lpReadTimeout = (DWORD)(Buffer.Timeout.QuadPart / -10000);
157 SetMailslotInfo(HANDLE hMailslot,
160 FILE_MAILSLOT_SET_INFORMATION Buffer;
161 IO_STATUS_BLOCK Iosb;
164 Buffer.Timeout.QuadPart = lReadTimeout * -10000;
166 Status = NtSetInformationFile(hMailslot,
169 sizeof(FILE_MAILSLOT_SET_INFORMATION),
170 FileMailslotSetInformation);
171 if (!NT_SUCCESS(Status))
173 DPRINT("NtSetInformationFile failed (Status %x)!\n", Status);
174 SetLastErrorByStatus (Status);