mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
add: [system] (TBD) sys::conf page_size
This commit is contained in:
parent
64a3ba24e7
commit
c604fadbea
@ -31,5 +31,13 @@ LIBIMP_EXPORT std::string error_str(result_code) noexcept;
|
|||||||
*/
|
*/
|
||||||
LIBIMP_EXPORT std::string error_msg(result_code) noexcept;
|
LIBIMP_EXPORT std::string error_msg(result_code) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get system configuration information at run time
|
||||||
|
*/
|
||||||
|
enum class info : std::int32_t {
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
LIBIMP_EXPORT std::int64_t conf(info) noexcept;
|
||||||
|
|
||||||
} // namespace sys
|
} // namespace sys
|
||||||
LIBIMP_NAMESPACE_END_
|
LIBIMP_NAMESPACE_END_
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "libimp/system.h"
|
#include "libimp/system.h"
|
||||||
#include "libimp/log.h"
|
#include "libimp/log.h"
|
||||||
@ -50,5 +51,26 @@ std::string error_str(result_code code) noexcept {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets configuration information at run time
|
||||||
|
* https://man7.org/linux/man-pages/man2/getpagesize.2.html
|
||||||
|
* https://man7.org/linux/man-pages/man3/sysconf.3.html
|
||||||
|
*/
|
||||||
|
std::int64_t conf(info r) noexcept {
|
||||||
|
LIBIMP_LOG_();
|
||||||
|
switch (r) {
|
||||||
|
case info::page_size: {
|
||||||
|
auto val = ::sysconf(_SC_PAGESIZE);
|
||||||
|
if (val >= 0) return (std::int64_t)val;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log.error("invalid info = {}", enum_cast(r));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
log.error("info = {}, error = {}", enum_cast(r), error_msg(error_code()));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sys
|
} // namespace sys
|
||||||
LIBIMP_NAMESPACE_END_
|
LIBIMP_NAMESPACE_END_
|
||||||
|
|||||||
@ -56,4 +56,8 @@ TEST(system, error_str) {
|
|||||||
EXPECT_EQ(imp::sys::error_str({}), "Success");
|
EXPECT_EQ(imp::sys::error_str({}), "Success");
|
||||||
EXPECT_EQ(imp::sys::error_str({false, EINVAL}), "Invalid argument");
|
EXPECT_EQ(imp::sys::error_str({false, EINVAL}), "Invalid argument");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(system, conf) {
|
||||||
|
EXPECT_EQ(imp::sys::conf(imp::sys::info::page_size), 4096);
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user