Lines Matching +full:port +full:-

2  * Copyright (c) 2009-2012 Niels Provos, Nick Mathewson
26 #include "evconfig-private.h"
39 #include "util-internal.h"
40 #include "iocp-internal.h"
41 #include "log-internal.h"
42 #include "mm-internal.h"
43 #include "event-internal.h"
44 #include "evthread-internal.h"
46 #define NOTIFICATION_KEY ((ULONG_PTR)-1)
52 o->cb = cb; in event_overlapped_init_()
60 eo->cb(eo, completion_key, nBytes, ok); in handle_entry()
66 struct event_iocp_port *port = port_; in loop() local
67 long ms = port->ms; in loop()
68 HANDLE p = port->port; in loop()
79 EnterCriticalSection(&port->lock); in loop()
80 if (port->shutdown) { in loop()
81 if (--port->n_live_threads == 0) in loop()
82 ReleaseSemaphore(port->shutdownSemaphore, 1, in loop()
84 LeaveCriticalSection(&port->lock); in loop()
87 LeaveCriticalSection(&port->lock); in loop()
95 EnterCriticalSection(&port->lock); in loop()
96 if (--port->n_live_threads == 0) in loop()
97 ReleaseSemaphore(port->shutdownSemaphore, 1, NULL); in loop()
98 LeaveCriticalSection(&port->lock); in loop()
102 event_iocp_port_associate_(struct event_iocp_port *port, evutil_socket_t fd, in event_iocp_port_associate_() argument
106 h = CreateIoCompletionPort((HANDLE)fd, port->port, key, port->n_threads); in event_iocp_port_associate_()
108 return -1; in event_iocp_port_associate_()
156 ext->AcceptEx = get_extension_function(s, &acceptex); in init_extension_functions()
157 ext->ConnectEx = get_extension_function(s, &connectex); in init_extension_functions()
158 ext->GetAcceptExSockaddrs = get_extension_function(s, in init_extension_functions()
178 struct event_iocp_port *port; in event_iocp_port_launch_() local
184 if (!(port = mm_calloc(1, sizeof(struct event_iocp_port)))) in event_iocp_port_launch_()
189 port->n_threads = n_cpus * 2; in event_iocp_port_launch_()
190 port->threads = mm_calloc(port->n_threads, sizeof(HANDLE)); in event_iocp_port_launch_()
191 if (!port->threads) in event_iocp_port_launch_()
194 port->port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, in event_iocp_port_launch_()
196 port->ms = -1; in event_iocp_port_launch_()
197 if (!port->port) in event_iocp_port_launch_()
200 port->shutdownSemaphore = CreateSemaphore(NULL, 0, 1, NULL); in event_iocp_port_launch_()
201 if (!port->shutdownSemaphore) in event_iocp_port_launch_()
204 for (i=0; i<port->n_threads; ++i) { in event_iocp_port_launch_()
205 ev_uintptr_t th = _beginthread(loop, 0, port); in event_iocp_port_launch_()
206 if (th == (ev_uintptr_t)-1) in event_iocp_port_launch_()
208 port->threads[i] = (HANDLE)th; in event_iocp_port_launch_()
209 ++port->n_live_threads; in event_iocp_port_launch_()
212 InitializeCriticalSectionAndSpinCount(&port->lock, 1000); in event_iocp_port_launch_()
214 return port; in event_iocp_port_launch_()
216 if (port->port) in event_iocp_port_launch_()
217 CloseHandle(port->port); in event_iocp_port_launch_()
218 if (port->threads) in event_iocp_port_launch_()
219 mm_free(port->threads); in event_iocp_port_launch_()
220 if (port->shutdownSemaphore) in event_iocp_port_launch_()
221 CloseHandle(port->shutdownSemaphore); in event_iocp_port_launch_()
222 mm_free(port); in event_iocp_port_launch_()
227 event_iocp_port_unlock_and_free_(struct event_iocp_port *port) in event_iocp_port_unlock_and_free_() argument
229 DeleteCriticalSection(&port->lock); in event_iocp_port_unlock_and_free_()
230 CloseHandle(port->port); in event_iocp_port_unlock_and_free_()
231 CloseHandle(port->shutdownSemaphore); in event_iocp_port_unlock_and_free_()
232 mm_free(port->threads); in event_iocp_port_unlock_and_free_()
233 mm_free(port); in event_iocp_port_unlock_and_free_()
237 event_iocp_notify_all(struct event_iocp_port *port) in event_iocp_notify_all() argument
240 for (i=0; i<port->n_threads; ++i) { in event_iocp_notify_all()
241 r = PostQueuedCompletionStatus(port->port, 0, NOTIFICATION_KEY, in event_iocp_notify_all()
246 return ok ? 0 : -1; in event_iocp_notify_all()
250 event_iocp_shutdown_(struct event_iocp_port *port, long waitMsec) in event_iocp_shutdown_() argument
255 EnterCriticalSection(&port->lock); in event_iocp_shutdown_()
256 port->shutdown = 1; in event_iocp_shutdown_()
257 LeaveCriticalSection(&port->lock); in event_iocp_shutdown_()
258 event_iocp_notify_all(port); in event_iocp_shutdown_()
263 WaitForSingleObject(port->shutdownSemaphore, ms); in event_iocp_shutdown_()
264 EnterCriticalSection(&port->lock); in event_iocp_shutdown_()
265 n = port->n_live_threads; in event_iocp_shutdown_()
266 LeaveCriticalSection(&port->lock); in event_iocp_shutdown_()
268 event_iocp_port_unlock_and_free_(port); in event_iocp_shutdown_()
271 return -1; in event_iocp_shutdown_()
277 struct event_iocp_port *port, struct event_overlapped *o, in event_iocp_activate_overlapped_() argument
282 r = PostQueuedCompletionStatus(port->port, n, key, &o->overlapped); in event_iocp_activate_overlapped_()
283 return (r==0) ? -1 : 0; in event_iocp_activate_overlapped_()
290 return base->iocp; in event_base_get_iocp_()