Use boost::winapi::GetLastError() consistently:

This replaces a few direct calls to ::GetLastError, and also removes a
couple of duplicate calls when the value was already held locally.
This commit is contained in:
Paul "TBBle" Hampson
2018-01-08 13:03:56 +11:00
committed by Vinnie Falco
parent 035248cefb
commit 0efc246466
3 changed files with 8 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ Version 153:
* Remove BOOST_VERSION checks * Remove BOOST_VERSION checks
* Use make_error_code for setting an error_code from errc * Use make_error_code for setting an error_code from errc
* Use boost::winapi::GetLastError() consistently
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@@ -300,9 +300,9 @@ read(void* buffer, std::size_t n, error_code& ec)
boost::winapi::DWORD_ bytesRead; boost::winapi::DWORD_ bytesRead;
if(! ::ReadFile(h_, buffer, amount, &bytesRead, 0)) if(! ::ReadFile(h_, buffer, amount, &bytesRead, 0))
{ {
auto const dwError = ::GetLastError(); auto const dwError = boost::winapi::GetLastError();
if(dwError != boost::winapi::ERROR_HANDLE_EOF_) if(dwError != boost::winapi::ERROR_HANDLE_EOF_)
ec.assign(::GetLastError(), system_category()); ec.assign(dwError, system_category());
else else
ec.assign(0, ec.category()); ec.assign(0, ec.category());
return nread; return nread;
@@ -341,9 +341,9 @@ write(void const* buffer, std::size_t n, error_code& ec)
boost::winapi::DWORD_ bytesWritten; boost::winapi::DWORD_ bytesWritten;
if(! ::WriteFile(h_, buffer, amount, &bytesWritten, 0)) if(! ::WriteFile(h_, buffer, amount, &bytesWritten, 0))
{ {
auto const dwError = ::GetLastError(); auto const dwError = boost::winapi::GetLastError();
if(dwError != boost::winapi::ERROR_HANDLE_EOF_) if(dwError != boost::winapi::ERROR_HANDLE_EOF_)
ec.assign(::GetLastError(), system_category()); ec.assign(dwError, system_category());
else else
ec.assign(0, ec.category()); ec.assign(0, ec.category());
return nwritten; return nwritten;

View File

@@ -25,6 +25,7 @@
#include <boost/make_unique.hpp> #include <boost/make_unique.hpp>
#include <boost/smart_ptr/make_shared_array.hpp> #include <boost/smart_ptr/make_shared_array.hpp>
#include <boost/winapi/basic_types.hpp> #include <boost/winapi/basic_types.hpp>
#include <boost/winapi/get_last_error.hpp>
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
@@ -436,14 +437,13 @@ operator()()
overlapped.get(), overlapped.get(),
nullptr, nullptr,
0); 0);
auto const dwError = ::GetLastError(); auto const dwError = boost::winapi::GetLastError();
if(! bSuccess && dwError != if(! bSuccess && dwError !=
boost::winapi::ERROR_IO_PENDING_) boost::winapi::ERROR_IO_PENDING_)
{ {
// VFALCO This needs review, is 0 the right number? // VFALCO This needs review, is 0 the right number?
// completed immediately (with error?) // completed immediately (with error?)
overlapped.complete(error_code{static_cast<int>( overlapped.complete(error_code{static_cast<int>(dwError),
boost::winapi::GetLastError()),
system_category()}, 0); system_category()}, 0);
return; return;
} }