Add .keep guard files in order to restore lost but empty directories we had with...
[reactos.git] / dll / win32 / ws2_32 / misc / event.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 DLL
4 * FILE: dll/win32/ws2_32/misc/event.c
5 * PURPOSE: Event handling
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 01/09-2000 Created
9 */
10
11 #include "ws2_32.h"
12
13 /*
14 * @implemented
15 */
16 BOOL
17 EXPORT
18 WSACloseEvent(IN WSAEVENT hEvent)
19 {
20 BOOL Success;
21
22 if (!WSAINITIALIZED)
23 {
24 WSASetLastError(WSANOTINITIALISED);
25 return FALSE;
26 }
27
28 Success = CloseHandle((HANDLE)hEvent);
29
30 if (!Success)
31 WSASetLastError(WSA_INVALID_HANDLE);
32
33 return Success;
34 }
35
36
37 /*
38 * @implemented
39 */
40 WSAEVENT
41 EXPORT
42 WSACreateEvent(VOID)
43 {
44 HANDLE Event;
45
46 if (!WSAINITIALIZED)
47 {
48 WSASetLastError(WSANOTINITIALISED);
49 return FALSE;
50 }
51
52 Event = CreateEventW(NULL, TRUE, FALSE, NULL);
53
54 if (Event == INVALID_HANDLE_VALUE)
55 WSASetLastError(WSA_INVALID_HANDLE);
56
57 return (WSAEVENT)Event;
58 }
59
60
61 /*
62 * @implemented
63 */
64 BOOL
65 EXPORT
66 WSAResetEvent(IN WSAEVENT hEvent)
67 {
68 BOOL Success;
69
70 if (!WSAINITIALIZED)
71 {
72 WSASetLastError(WSANOTINITIALISED);
73 return FALSE;
74 }
75
76 Success = ResetEvent((HANDLE)hEvent);
77
78 if (!Success)
79 WSASetLastError(WSA_INVALID_HANDLE);
80
81 return Success;
82 }
83
84
85 /*
86 * @implemented
87 */
88 BOOL
89 EXPORT
90 WSASetEvent(IN WSAEVENT hEvent)
91 {
92 BOOL Success;
93
94 if (!WSAINITIALIZED)
95 {
96 WSASetLastError(WSANOTINITIALISED);
97 return FALSE;
98 }
99
100 Success = SetEvent((HANDLE)hEvent);
101
102 if (!Success)
103 WSASetLastError(WSA_INVALID_HANDLE);
104
105 return Success;
106 }
107
108
109 /*
110 * @implemented
111 */
112 DWORD
113 EXPORT
114 WSAWaitForMultipleEvents(IN DWORD cEvents,
115 IN CONST WSAEVENT FAR* lphEvents,
116 IN BOOL fWaitAll,
117 IN DWORD dwTimeout,
118 IN BOOL fAlertable)
119 {
120 DWORD Status;
121
122 if (!WSAINITIALIZED)
123 {
124 WSASetLastError(WSANOTINITIALISED);
125 return FALSE;
126 }
127
128 Status = WaitForMultipleObjectsEx(cEvents,
129 lphEvents,
130 fWaitAll,
131 dwTimeout,
132 fAlertable);
133 if (Status == WAIT_FAILED)
134 {
135 Status = GetLastError();
136
137 if (Status == ERROR_NOT_ENOUGH_MEMORY)
138 WSASetLastError(WSA_NOT_ENOUGH_MEMORY);
139 else if (Status == ERROR_INVALID_HANDLE)
140 WSASetLastError(WSA_INVALID_HANDLE);
141 else
142 WSASetLastError(WSA_INVALID_PARAMETER);
143
144 return WSA_WAIT_FAILED;
145 }
146
147 return Status;
148 }
149
150
151 /*
152 * @implemented
153 */
154 INT
155 EXPORT
156 WSAEnumNetworkEvents(IN SOCKET s,
157 IN WSAEVENT hEventObject,
158 OUT LPWSANETWORKEVENTS lpNetworkEvents)
159 {
160 PCATALOG_ENTRY Provider;
161 INT Status;
162 INT Errno;
163
164 WS_DbgPrint(MID_TRACE,("Called (Socket %x, hEventObject %x, "
165 "lpNetworkEvents %x)\n",
166 s,
167 hEventObject,
168 lpNetworkEvents));
169
170 if (!lpNetworkEvents)
171 {
172 WSASetLastError(WSAEINVAL);
173 return SOCKET_ERROR;
174 }
175
176 if (!WSAINITIALIZED)
177 {
178 WSASetLastError(WSANOTINITIALISED);
179 return SOCKET_ERROR;
180 }
181
182 if (!ReferenceProviderByHandle((HANDLE)s,
183 &Provider))
184 {
185 WSASetLastError(WSAENOTSOCK);
186 return SOCKET_ERROR;
187 }
188
189 Status = Provider->ProcTable.lpWSPEnumNetworkEvents(s,
190 hEventObject,
191 lpNetworkEvents,
192 &Errno);
193
194 DereferenceProviderByPointer(Provider);
195
196 if (Status == SOCKET_ERROR)
197 WSASetLastError(Errno);
198
199 WS_DbgPrint(MID_TRACE,("Leaving %x\n", Status));
200
201 return Status;
202 }
203
204
205 /*
206 * @implemented
207 */
208 INT
209 EXPORT
210 WSAEventSelect(IN SOCKET s,
211 IN WSAEVENT hEventObject,
212 IN LONG lNetworkEvents)
213 {
214 PCATALOG_ENTRY Provider;
215 INT Status;
216 INT Errno;
217
218 if (!WSAINITIALIZED)
219 {
220 WSASetLastError(WSANOTINITIALISED);
221 return SOCKET_ERROR;
222 }
223
224 if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
225 {
226 WSASetLastError(WSAENOTSOCK);
227 return SOCKET_ERROR;
228 }
229
230 Status = Provider->ProcTable.lpWSPEventSelect(s,
231 hEventObject,
232 lNetworkEvents,
233 &Errno);
234
235 DereferenceProviderByPointer(Provider);
236
237 if (Status == SOCKET_ERROR)
238 WSASetLastError(Errno);
239
240 return Status;
241 }
242
243 /* EOF */