From 30ceb55fb4f1db7c868102320f0c3b0980c2ae84 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 11 Sep 2018 20:31:53 +0300 Subject: [PATCH] Fix checking of return values. GitOrigin-RevId: 81accbd062db24d031a3054ba5cc86ace38774ad --- .../td/utils/port/detail/EventFdWindows.cpp | 22 +++++++++++++++---- tdutils/td/utils/port/detail/Iocp.cpp | 9 +++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/tdutils/td/utils/port/detail/EventFdWindows.cpp b/tdutils/td/utils/port/detail/EventFdWindows.cpp index 7b55b338..0542739d 100644 --- a/tdutils/td/utils/port/detail/EventFdWindows.cpp +++ b/tdutils/td/utils/port/detail/EventFdWindows.cpp @@ -16,7 +16,12 @@ namespace td { namespace detail { void EventFdWindows::init() { - event_ = NativeFd(CreateEventW(nullptr, true, false, nullptr)); + auto handle = CreateEventW(nullptr, true, false, nullptr); + if (handle == nullptr) { + auto error = OS_ERROR("CreateEventW failed"); + LOG(FATAL) << error; + } + event_ = NativeFd(handle); } bool EventFdWindows::empty() { @@ -36,16 +41,25 @@ PollableFdInfo &EventFdWindows::get_poll_info() { } void EventFdWindows::release() { - SetEvent(event_.fd()); + if (SetEvent(event_.fd()) == 0) { + auto error = OS_ERROR("SetEvent failed"); + LOG(FATAL) << error; + } } void EventFdWindows::acquire() { - ResetEvent(event_.fd()); + if (ResetEvent(event_.fd()) == 0) { + auto error = OS_ERROR("ResetEvent failed"); + LOG(FATAL) << error; + } } void EventFdWindows::wait(int timeout_ms) { WaitForSingleObject(event_.fd(), timeout_ms); - ResetEvent(event_.fd()); + if (ResetEvent(event_.fd()) == 0) { + auto error = OS_ERROR("ResetEvent failed"); + LOG(FATAL) << error; + } } } // namespace detail diff --git a/tdutils/td/utils/port/detail/Iocp.cpp b/tdutils/td/utils/port/detail/Iocp.cpp index f651d54e..9e3f2b5b 100644 --- a/tdutils/td/utils/port/detail/Iocp.cpp +++ b/tdutils/td/utils/port/detail/Iocp.cpp @@ -69,7 +69,7 @@ void Iocp::subscribe(const NativeFd &native_fd, Callback *callback) { CHECK(iocp_handle_); auto iocp_handle = CreateIoCompletionPort(native_fd.fd(), iocp_handle_.fd(), reinterpret_cast(callback), 0); - if (iocp_handle == INVALID_HANDLE_VALUE) { + if (iocp_handle == nullptr) { auto error = OS_ERROR("CreateIoCompletionPort"); LOG(FATAL) << error; } @@ -77,8 +77,11 @@ void Iocp::subscribe(const NativeFd &native_fd, Callback *callback) { } void Iocp::post(size_t size, Callback *callback, WSAOVERLAPPED *overlapped) { - PostQueuedCompletionStatus(iocp_handle_.fd(), DWORD(size), reinterpret_cast(callback), - reinterpret_cast(overlapped)); + if (PostQueuedCompletionStatus(iocp_handle_.fd(), DWORD(size), reinterpret_cast(callback), + reinterpret_cast(overlapped)) == 0) { + auto error = OS_ERROR("IOCP post failed"); + LOG(FATAL) << error; + } } } // namespace detail