diff --git a/include/libimp/error.h b/include/libimp/error.h index 351ae66..6a5e67b 100644 --- a/include/libimp/error.h +++ b/include/libimp/error.h @@ -17,6 +17,7 @@ LIBIMP_NAMESPACE_BEG_ using error_code_t = std::uint64_t; constexpr error_code_t error_number_limit = error_code_t(-1); +constexpr error_code_t no_error = 0; /** * \brief Serves as the base class for specific error category types. diff --git a/include/libipc/shm.h b/include/libipc/shm.h index 9e05b36..9320654 100644 --- a/include/libipc/shm.h +++ b/include/libipc/shm.h @@ -21,11 +21,15 @@ using shm_t = shm_handle *; /// \brief Create a new shared memory handle with a name of the shared memory file. LIBIMP_EXPORT ::LIBIMP::result shm_open(std::string name, - std::size_t size = 0, - mode::type = mode::create | mode::open) noexcept; + std::size_t size = 0, + mode::type = mode::create | mode::open) noexcept; /// \brief Close the shared memory handle. -LIBIMP_EXPORT ::LIBIMP::result_code shm_close(shm_t) noexcept; +LIBIMP_EXPORT ::LIBIMP::result shm_close(shm_t) noexcept; + +/// \brief Gets the name of the shared memory file based on the shared memory handle. +/// \return empty string on failure. +LIBIMP_EXPORT std::string shm_name(shm_t) noexcept; /// \brief Gets a memory pointer based on the shared memory handle. /// \return nullptr on failure. @@ -39,10 +43,6 @@ LIBIMP_EXPORT std::size_t shm_size(shm_t) noexcept; /// \remark [TBD] LIBIMP_EXPORT ::LIBIMP::result_code shm_size(shm_t, std::size_t) noexcept; -/// \brief Gets the name of the shared memory file based on the shared memory handle. -/// \return empty string on failure. -LIBIMP_EXPORT std::string shm_name(shm_t) noexcept; - /** * \brief The shared memory object. */ diff --git a/src/libipc/platform/posix/shm_impl.h b/src/libipc/platform/posix/shm_impl.h index 2d65c47..60f302c 100644 --- a/src/libipc/platform/posix/shm_impl.h +++ b/src/libipc/platform/posix/shm_impl.h @@ -150,7 +150,7 @@ result shm_open(std::string name, std::size_t size, mode::type type) noex /** * \see https://man7.org/linux/man-pages/man2/mmap.2.html */ -result_code shm_close(shm_t h) noexcept { +result shm_close(shm_t h) noexcept { LIBIMP_LOG_(); auto shm = valid(h); if (shm == nullptr) return {}; @@ -161,7 +161,7 @@ result_code shm_close(shm_t h) noexcept { } /// \brief no unlink the file. delete shm; - return posix::succ; + return no_error; } LIBIPC_NAMESPACE_END_ diff --git a/src/libipc/platform/win/mmap_impl.h b/src/libipc/platform/win/mmap_impl.h index e1db442..9a5b78d 100644 --- a/src/libipc/platform/win/mmap_impl.h +++ b/src/libipc/platform/win/mmap_impl.h @@ -33,7 +33,7 @@ namespace { * \brief Closes an open object handle. * \see https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle */ -result_code mmap_close(HANDLE h) { +result mmap_close(HANDLE h) { LIBIMP_LOG_(); if (h == NULL) { log.error("handle is null."); @@ -44,7 +44,7 @@ result_code mmap_close(HANDLE h) { log.error("failed: CloseHandle(", h, "). error = ", err); return err; } - return ERROR_SUCCESS; + return no_error; } /** @@ -161,7 +161,7 @@ result mmap_sizeof(LPCVOID mem) { * \brief Unmaps a mapped view of a file from the calling process's address space. * \see https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-unmapviewoffile */ -result_code mmap_release(HANDLE h, LPCVOID mem) { +result mmap_release(HANDLE h, LPCVOID mem) { LIBIMP_LOG_(); if (h == NULL) { log.error("handle is null."); diff --git a/src/libipc/platform/win/shm_impl.h b/src/libipc/platform/win/shm_impl.h index 537b984..deec8f3 100644 --- a/src/libipc/platform/win/shm_impl.h +++ b/src/libipc/platform/win/shm_impl.h @@ -39,7 +39,7 @@ result shm_open(std::string name, std::size_t size, mode::type type) noex return new shm_handle{std::move(name), *sz, *mem, *h}; } -result_code shm_close(shm_t h) noexcept { +result shm_close(shm_t h) noexcept { LIBIMP_LOG_(); if (h == nullptr) { log.error("shm handle is null."); diff --git a/test/ipc/test_ipc_shm.cpp b/test/ipc/test_ipc_shm.cpp index c7fcd90..4b23aaa 100644 --- a/test/ipc/test_ipc_shm.cpp +++ b/test/ipc/test_ipc_shm.cpp @@ -3,7 +3,7 @@ #include "libipc/shm.h" -TEST(shm, create_close) { +TEST(shm, open_close) { EXPECT_FALSE(ipc::shm_open("hello-ipc-shm", 1024, ipc::mode::none)); auto shm1 = ipc::shm_open("hello-ipc-shm", 1024, ipc::mode::create | ipc::mode::open); @@ -77,7 +77,6 @@ TEST(shm, shared_memory) { } #include - #if defined(LIBIMP_OS_LINUX) #include #include