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 *****************************************************************/
13 #include <ddk/ntddk.h>
14 #include <ntdll/rtl.h>
17 #include <kernel32/kernel32.h>
18 #include <kernel32/error.h>
20 /* FUNCTIONS ****************************************************************/
23 CreateMailslotA(LPCSTR lpName,
24 DWORD nMaxMessageSize,
26 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
28 HANDLE MailslotHandle;
32 RtlInitAnsiString(&NameA, (LPSTR)lpName);
33 RtlAnsiStringToUnicodeString(&NameU, &NameA, TRUE);
35 MailslotHandle = CreateMailslotW(NameU.Buffer,
38 lpSecurityAttributes);
40 RtlFreeUnicodeString(&NameU);
42 return(MailslotHandle);
47 CreateMailslotW(LPCWSTR lpName,
48 DWORD nMaxMessageSize,
50 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
52 OBJECT_ATTRIBUTES ObjectAttributes;
53 UNICODE_STRING MailslotName;
54 HANDLE MailslotHandle;
57 LARGE_INTEGER DefaultTimeOut;
60 Result = RtlDosPathNameToNtPathName_U((LPWSTR)lpName,
66 SetLastError(ERROR_PATH_NOT_FOUND);
67 return(INVALID_HANDLE_VALUE);
70 DPRINT("Mailslot name: %wZ\n", &MailslotName);
72 InitializeObjectAttributes(&ObjectAttributes,
78 DefaultTimeOut.QuadPart = lReadTimeout * 10000;
80 Status = NtCreateMailslotFile(&MailslotHandle,
81 GENERIC_READ | SYNCHRONIZE | WRITE_DAC,
89 RtlFreeUnicodeString(&MailslotName);
91 if (!NT_SUCCESS(Status))
93 DPRINT("NtCreateMailslot failed (Status %x)!\n", Status);
94 SetLastErrorByStatus (Status);
95 return(INVALID_HANDLE_VALUE);
98 return(MailslotHandle);
103 GetMailslotInfo(HANDLE hMailslot,
104 LPDWORD lpMaxMessageSize,
106 LPDWORD lpMessageCount,
107 LPDWORD lpReadTimeout)
109 FILE_MAILSLOT_QUERY_INFORMATION Buffer;
110 IO_STATUS_BLOCK Iosb;
113 Status = NtQueryInformationFile(hMailslot,
116 sizeof(FILE_MAILSLOT_QUERY_INFORMATION),
117 FileMailslotQueryInformation);
118 if (!NT_SUCCESS(Status))
120 DPRINT("NtQueryInformationFile failed (Status %x)!\n", Status);
121 SetLastErrorByStatus (Status);
125 if (lpMaxMessageSize != NULL)
127 *lpMaxMessageSize = Buffer.MaxMessageSize;
129 if (lpNextSize != NULL)
131 *lpNextSize = Buffer.NextSize;
133 if (lpMessageCount != NULL)
135 *lpMessageCount = Buffer.MessageCount;
137 if (lpReadTimeout != NULL)
139 *lpReadTimeout = (DWORD)(Buffer.Timeout.QuadPart / -10000);
147 SetMailslotInfo(HANDLE hMailslot,
150 FILE_MAILSLOT_SET_INFORMATION Buffer;
151 IO_STATUS_BLOCK Iosb;
154 Buffer.Timeout.QuadPart = lReadTimeout * -10000;
156 Status = NtSetInformationFile(hMailslot,
159 sizeof(FILE_MAILSLOT_SET_INFORMATION),
160 FileMailslotSetInformation);
161 if (!NT_SUCCESS(Status))
163 DPRINT("NtSetInformationFile failed (Status %x)!\n", Status);
164 SetLastErrorByStatus (Status);