diff --git a/src/libimp/platform/posix/system.h b/src/libimp/platform/posix/system.h index 404077a..887f28e 100644 --- a/src/libimp/platform/posix/system.h +++ b/src/libimp/platform/posix/system.h @@ -38,11 +38,11 @@ result conf(info r) noexcept { } default: log.error("invalid info = ", underlyof(r)); - return {}; + return std::make_error_code(std::errc::invalid_argument); } auto err = sys::error(); log.error("info = ", underlyof(r), ", error = ", err); - return {false, err}; + return err; } } // namespace sys diff --git a/src/libimp/platform/win/system.h b/src/libimp/platform/win/system.h index 19c2043..c1f01fc 100644 --- a/src/libimp/platform/win/system.h +++ b/src/libimp/platform/win/system.h @@ -19,7 +19,6 @@ LIBIMP_NAMESPACE_BEG_ namespace sys { -namespace { /** * \brief Gets a text description of the system error @@ -56,8 +55,6 @@ std::string error_string(DWORD code) noexcept { return {}; } -} // namespace - /** * \brief Get the system error number. * \see https://en.cppreference.com/w/cpp/error/system_category @@ -82,7 +79,7 @@ result conf(info r) noexcept { } default: log.error("invalid info = ", underlyof(r)); - return {}; + return std::make_error_code(std::errc::invalid_argument); } } diff --git a/src/libipc/platform/posix/shm_impl.h b/src/libipc/platform/posix/shm_impl.h index 661027f..91b09bb 100644 --- a/src/libipc/platform/posix/shm_impl.h +++ b/src/libipc/platform/posix/shm_impl.h @@ -51,7 +51,7 @@ result shm_open_fd(std::string const &name, mode::type type) noexcept { LIBIMP_LOG_(); if (name.empty()) { log.error("name is empty."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } /// \brief Open the object for read-write access. @@ -70,7 +70,7 @@ result shm_open_fd(std::string const &name, mode::type type) noexcept { break; default: log.error("mode type is invalid. type = ", type); - return {}; + return std::make_error_code(std::errc::invalid_argument); } /// \brief Create/Open POSIX shared memory bject @@ -153,7 +153,9 @@ result shm_open(std::string name, std::size_t size, mode::type type) noex result shm_close(shm_t h) noexcept { LIBIMP_LOG_(); auto shm = valid(h); - if (shm == nullptr) return {}; + if (shm == nullptr) { + return std::make_error_code(std::errc::invalid_argument); + } if (::munmap(shm->memp, shm->f_sz) == posix::failed) { auto err = sys::error(); log.error("failed: munmap(", shm->memp, ", ", shm->f_sz, "). error = ", err); diff --git a/src/libipc/platform/win/event_impl.h b/src/libipc/platform/win/event_impl.h index 73ffbc8..9ca9c44 100644 --- a/src/libipc/platform/win/event_impl.h +++ b/src/libipc/platform/win/event_impl.h @@ -49,7 +49,7 @@ result evt_open(std::string name) noexcept { if (h == NULL) { auto err = sys::error(); log.error("failed: CreateEvent(FALSE, FALSE, ", name, "). error = ", err); - return {nullptr, err}; + return err; } return new evt_handle{std::move(name), h}; } @@ -99,7 +99,7 @@ result evt_wait(evt_t evt, std::int64_t ms) noexcept { LIBIMP_LOG_(); if (!is_valid(evt)) { log.error("handle is null."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } DWORD dwMilliseconds = (ms < 0) ? INFINITE : static_cast(ms); auto r = ::WaitForSingleObject(evt->h_event, dwMilliseconds); @@ -115,7 +115,7 @@ result evt_wait(evt_t evt, std::int64_t ms) noexcept { } auto err = sys::error(); log.error("failed: WaitForSingleObject(", evt->h_event, ", ", dwMilliseconds, "). error = ", err); - return {false, err}; + return err; } /** @@ -126,14 +126,14 @@ result evt_wait(::LIBIMP::span evts, std::int64_t ms) noexcep LIBIMP_LOG_(); if (evts.empty()) { log.error("evts handle is empty."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } // Conversion of the event handle array to the windows handle array. std::vector handles(evts.size()); for (std::size_t i = 0; i < evts.size(); ++i) { if (!is_valid(evts[i])) { log.error("handle is null."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } handles[i] = evts[i]->h_event; } @@ -152,7 +152,7 @@ result evt_wait(::LIBIMP::span evts, std::int64_t ms) noexcep } auto err = sys::error(); log.error("failed: WaitForMultipleObjects(", handles.size(), ", ", dwMilliseconds, "). error = ", err); - return {false, err}; + return err; } LIBIPC_NAMESPACE_END_ diff --git a/src/libipc/platform/win/mmap_impl.h b/src/libipc/platform/win/mmap_impl.h index e302a31..a28ef1b 100644 --- a/src/libipc/platform/win/mmap_impl.h +++ b/src/libipc/platform/win/mmap_impl.h @@ -37,7 +37,7 @@ result mmap_close(HANDLE h) { LIBIMP_LOG_(); if (h == NULL) { log.error("handle is null."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } if (!::CloseHandle(h)) { auto err = sys::error(); @@ -64,12 +64,12 @@ result mmap_open(std::string const &file, std::size_t size, mode::type t LIBIMP_LOG_(); if (file.empty()) { log.error("file name is empty."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } auto t_name = detail::to_tstring(file); if (t_name.empty()) { log.error("file name is empty. (TCHAR conversion failed)"); - return {}; + return std::make_error_code(std::errc::invalid_argument); } /// \brief Opens a named file mapping object. @@ -78,7 +78,7 @@ result mmap_open(std::string const &file, std::size_t size, mode::type t if (h == NULL) { auto err = sys::error(); log.error("failed: OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, ", file, "). error = ", err); - return {nullptr, err}; + return err; } return h; }; @@ -91,7 +91,7 @@ result mmap_open(std::string const &file, std::size_t size, mode::type t if (h == NULL) { auto err = sys::error(); log.error("failed: CreateFileMapping(PAGE_READWRITE | SEC_COMMIT, ", size, ", ", file, "). error = ", err); - return {nullptr, err}; + return err; } return h; }; @@ -105,7 +105,7 @@ result mmap_open(std::string const &file, std::size_t size, mode::type t return try_open(); } else if (!(type & mode::create)) { log.error("mode type is invalid. type = ", type); - return {}; + return std::make_error_code(std::errc::invalid_argument); } auto h = try_create(); if (!h) return h; @@ -114,7 +114,7 @@ result mmap_open(std::string const &file, std::size_t size, mode::type t if ((type == mode::create) && (::GetLastError() == ERROR_ALREADY_EXISTS)) { log.info("the file being created already exists. file = ", file, ", type = ", type); mmap_close(*h); - return {}; + return sys::error(); } return h; } @@ -127,13 +127,13 @@ result mmap_memof(HANDLE h) { LIBIMP_LOG_(); if (h == NULL) { log.error("handle is null."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } LPVOID mem = ::MapViewOfFile(h, FILE_MAP_ALL_ACCESS, 0, 0, 0); if (mem == NULL) { auto err = sys::error(); log.error("failed: MapViewOfFile(", h, ", FILE_MAP_ALL_ACCESS). error = ", err); - return {nullptr, err}; + return err; } return mem; } @@ -146,13 +146,13 @@ result mmap_sizeof(LPCVOID mem) { LIBIMP_LOG_(); if (mem == NULL) { log.error("memory pointer is null."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } MEMORY_BASIC_INFORMATION mem_info {}; if (::VirtualQuery(mem, &mem_info, sizeof(mem_info)) == 0) { auto err = sys::error(); log.error("failed: VirtualQuery(", mem, "). error = ", err); - return {false, err}; + return err; } return mem_info.RegionSize; } @@ -165,11 +165,11 @@ result mmap_release(HANDLE h, LPCVOID mem) { LIBIMP_LOG_(); if (h == NULL) { log.error("handle is null."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } if (mem == NULL) { log.error("memory pointer is null."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } if (!::UnmapViewOfFile(mem)) { log.warning("failed: UnmapViewOfFile. error = ", sys::error()); diff --git a/src/libipc/platform/win/shm_impl.h b/src/libipc/platform/win/shm_impl.h index deec8f3..243df96 100644 --- a/src/libipc/platform/win/shm_impl.h +++ b/src/libipc/platform/win/shm_impl.h @@ -22,19 +22,19 @@ result shm_open(std::string name, std::size_t size, mode::type type) noex auto h = mmap_open(name, size, type); if (*h == NULL) { log.error("failed: mmap_open(name = ", name, ", size = ", size, ", type = ", type, ")."); - return {nullptr, h.error()}; + return h.error(); } auto mem = mmap_memof(*h); if (*mem == NULL) { log.error("failed: mmap_memof(", *h, ")."); mmap_close(*h); - return {nullptr, mem.error()}; + return mem.error(); } auto sz = mmap_sizeof(*mem); if (!sz) { log.error("failed: mmap_sizeof(", *mem, ")."); mmap_close(*h); - return {nullptr, sz.error()}; + return sz.error(); } return new shm_handle{std::move(name), *sz, *mem, *h}; } @@ -43,7 +43,7 @@ result shm_close(shm_t h) noexcept { LIBIMP_LOG_(); if (h == nullptr) { log.error("shm handle is null."); - return {}; + return std::make_error_code(std::errc::invalid_argument); } auto shm = static_cast(h); auto ret = mmap_release(shm->h_fmap, shm->memp);