MCPcopy Create free account
hub / github.com/3rdparty/libprocess / registerHandle

Method registerHandle

src/windows/libwinio.cpp:397–426  ·  view source on GitHub ↗

NOTE: The following functions use `int_fd` instead of the native Win32 `HANDLE`, because they are the more "public" libwinio APIs that interface directly with the libprocess IO, socket and event loop code.

Source from the content-addressed store, hash-verified

395// `HANDLE`, because they are the more "public" libwinio APIs that interface
396// directly with the libprocess IO, socket and event loop code.
397Try<Nothing> EventLoop::registerHandle(const int_fd& fd)
398{
399 Try<HANDLE> assigned_handle = fd.assign_iocp(iocp_handle_.get(), KEY_IO);
400 if (assigned_handle.isError()) {
401 return Error(assigned_handle.error());
402 }
403
404 // In this case, the IOCP handle was already assigned. So, we check if the
405 // right one is assigned.
406 if (assigned_handle.get() != nullptr) {
407 if (assigned_handle.get() != iocp_handle_.get()) {
408 return Error(
409 "fd is already registered to a different Windows Event Loop");
410 }
411 return Nothing();
412 }
413
414 // This is the first time the handle was assigned. We continue the
415 // initialization. These are some optimizations that prevent IOCP
416 // notifications on success and event notifications, so that we have less
417 // context switches.
418 BOOL success = ::SetFileCompletionNotificationModes(
419 fd, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS | FILE_SKIP_SET_EVENT_ON_HANDLE);
420
421 if (!success) {
422 return WindowsError();
423 }
424
425 return Nothing();
426}
427
428
429template <typename T, typename O>

Callers 1

prepare_asyncFunction · 0.80

Calls 1

getMethod · 0.45

Tested by

no test coverage detected