From 6029b37796f6a92e143d10febf760dc6c6208c3a Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Tue, 8 Jan 2019 03:01:03 +0100 Subject: [PATCH] windows/socket: Assign io completion routine and test event first --- source/windows/socket.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/windows/socket.cpp b/source/windows/socket.cpp index 5264547..7cfec0c 100644 --- a/source/windows/socket.cpp +++ b/source/windows/socket.cpp @@ -84,7 +84,7 @@ void datapath::windows::socket::_watcher() // Read content. if (ReadFileEx(this->socket_handle, read_buffer.data(), DWORD(read_buffer.size()), - read_content_ov->get_overlapped(), NULL)) { + read_content_ov->get_overlapped(), &datapath::windows::utility::def_io_completion_routine)) { state = readstate::Content; waitable = read_content_ov; } else { @@ -152,7 +152,10 @@ void datapath::windows::socket::_watcher() if (!waitable) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } else { - datapath::error err = waitable->wait(std::chrono::milliseconds(1)); + datapath::error err = waitable->wait(std::chrono::milliseconds(0)); + if (err != datapath::error::Success) { + err = waitable->wait(std::chrono::milliseconds(1)); + } if (err == datapath::error::Closed) { _disconnect(); continue;