reshuffling of dlls
[reactos.git] / reactos / 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: 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 #include <ws2_32.h>
11 #include <handle.h>
12
13
14 /*
15 * @implemented
16 */
17 BOOL
18 EXPORT
19 WSACloseEvent(
20 IN WSAEVENT hEvent)
21 {
22 BOOL Success;
23
24 if (!WSAINITIALIZED) {
25 WSASetLastError(WSANOTINITIALISED);
26 return FALSE;
27 }
28
29 Success = CloseHandle((HANDLE)hEvent);
30
31 if (!Success)
32 WSASetLastError(WSA_INVALID_HANDLE);
33
34 return Success;
35 }
36
37
38 /*
39 * @implemented
40 */
41 WSAEVENT
42 EXPORT
43 WSACreateEvent(VOID)
44 {
45 HANDLE Event;
46
47 if (!WSAINITIALIZED) {
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(
67 IN WSAEVENT hEvent)
68 {
69 BOOL Success;
70
71 if (!WSAINITIALIZED) {
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(
91 IN WSAEVENT hEvent)
92 {
93 BOOL Success;
94
95 if (!WSAINITIALIZED) {
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(
115 IN DWORD cEvents,
116 IN CONST WSAEVENT FAR* lphEvents,
117 IN BOOL fWaitAll,
118 IN DWORD dwTimeout,
119 IN BOOL fAlertable)
120 {
121 DWORD Status;
122
123 if (!WSAINITIALIZED) {
124 WSASetLastError(WSANOTINITIALISED);
125 return FALSE;
126 }
127
128 Status = WaitForMultipleObjectsEx(cEvents, lphEvents, fWaitAll, dwTimeout, fAlertable);
129 if (Status == WAIT_FAILED) {
130 Status = GetLastError();
131
132 if (Status == ERROR_NOT_ENOUGH_MEMORY)
133 WSASetLastError(WSA_NOT_ENOUGH_MEMORY);
134 else if (Status == ERROR_INVALID_HANDLE)
135 WSASetLastError(WSA_INVALID_HANDLE);
136 else
137 WSASetLastError(WSA_INVALID_PARAMETER);
138
139 return WSA_WAIT_FAILED;
140 }
141
142 return Status;
143 }
144
145
146 /*
147 * @implemented
148 */
149 INT
150 EXPORT
151 WSAEnumNetworkEvents(
152 IN SOCKET s,
153 IN WSAEVENT hEventObject,
154 OUT LPWSANETWORKEVENTS lpNetworkEvents)
155 {
156 PCATALOG_ENTRY Provider;
157 INT Status;
158 INT Errno;
159
160 WS_DbgPrint(MID_TRACE,("Called (Socket %x, hEventObject %x, "
161 "lpNetworkEvents %x)\n",
162 s, hEventObject, lpNetworkEvents));
163
164 if (!lpNetworkEvents) {
165 WSASetLastError(WSAEINVAL);
166 return SOCKET_ERROR;
167 }
168
169 if (!WSAINITIALIZED) {
170 WSASetLastError(WSANOTINITIALISED);
171 return SOCKET_ERROR;
172 }
173
174 if (!ReferenceProviderByHandle((HANDLE)s, &Provider)) {
175 WSASetLastError(WSAENOTSOCK);
176 return SOCKET_ERROR;
177 }
178
179 Status = Provider->ProcTable.lpWSPEnumNetworkEvents(
180 s, hEventObject, lpNetworkEvents, &Errno);
181
182 DereferenceProviderByPointer(Provider);
183
184 if (Status == SOCKET_ERROR)
185 WSASetLastError(Errno);
186
187 WS_DbgPrint(MID_TRACE,("Leaving %x\n", Status));
188
189 return Status;
190 }
191
192
193 /*
194 * @implemented
195 */
196 INT
197 EXPORT
198 WSAEventSelect(
199 IN SOCKET s,
200 IN WSAEVENT hEventObject,
201 IN LONG lNetworkEvents)
202 {
203 PCATALOG_ENTRY Provider;
204 INT Status;
205 INT Errno;
206
207 if (!WSAINITIALIZED) {
208 WSASetLastError(WSANOTINITIALISED);
209 return SOCKET_ERROR;
210 }
211
212 if (!ReferenceProviderByHandle((HANDLE)s, &Provider)) {
213 WSASetLastError(WSAENOTSOCK);
214 return SOCKET_ERROR;
215 }
216
217 Status = Provider->ProcTable.lpWSPEventSelect(
218 s, hEventObject, lNetworkEvents, &Errno);
219
220 DereferenceProviderByPointer(Provider);
221
222 if (Status == SOCKET_ERROR)
223 WSASetLastError(Errno);
224
225 return Status;
226 }
227
228 /* EOF */