-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor handle closing in Windows platform code
- Loading branch information
Showing
4 changed files
with
58 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* \file libipc/platform/win/close_handle.h | ||
* \author mutouyun (orz@orzz.org) | ||
*/ | ||
#pragma once | ||
|
||
#include <Windows.h> | ||
|
||
#include "libimp/log.h" | ||
#include "libimp/system.h" | ||
|
||
#include "libipc/def.h" | ||
|
||
LIBIPC_NAMESPACE_BEG_ | ||
using namespace ::LIBIMP; | ||
|
||
namespace winapi { | ||
|
||
/** | ||
* \brief Closes an open object handle. | ||
* \see https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle | ||
*/ | ||
inline result<void> close_handle(HANDLE h) noexcept { | ||
LIBIMP_LOG_(); | ||
if (h == NULL) { | ||
log.error("handle is null."); | ||
return std::make_error_code(std::errc::invalid_argument); | ||
} | ||
if (!::CloseHandle(h)) { | ||
auto err = sys::error(); | ||
log.error("failed: CloseHandle(", h, "). error = ", err); | ||
return err; | ||
} | ||
return std::error_code{}; | ||
} | ||
|
||
} // namespace winapi | ||
LIBIPC_NAMESPACE_END_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters