1#ifndef UVW_UTIL_INCLUDE_H 
    2#define UVW_UTIL_INCLUDE_H 
   20enum class uvw_handle_type : std::underlying_type_t<uv_handle_type> {
 
   21    UNKNOWN = UV_UNKNOWN_HANDLE,
 
   24    FS_EVENT = UV_FS_EVENT,
 
   41enum class uvw_clock_id : std::underlying_type_t<uv_clock_id> {
 
   42    MONOTONIC = UV_CLOCK_MONOTONIC,
 
   43    REALTIME = UV_CLOCK_REALTIME
 
   47struct uv_type_wrapper {
 
   50    constexpr uv_type_wrapper()
 
   53    constexpr uv_type_wrapper(Type val)
 
   56    constexpr operator Type() const noexcept {
 
   60    bool operator==(uv_type_wrapper other) 
const noexcept {
 
   61        return value == other.value;
 
   69bool operator==(uv_type_wrapper<T> lhs, uv_type_wrapper<T> rhs) {
 
   83using handle_type = details::uvw_handle_type;                     
 
   88using pid_type = details::uv_type_wrapper<uv_pid_t>;              
 
   89using clock_id = details::uvw_clock_id;                           
 
  127    decltype(uv_passwd_t::
uid) 
uid() const noexcept;
 
  133    decltype(uv_passwd_t::
gid) 
gid() const noexcept;
 
  151    operator 
bool() const noexcept;
 
  154    std::shared_ptr<uv_passwd_t> value;
 
  167    uts_name(std::shared_ptr<uv_utsname_t> init);
 
  179    std::
string release() const noexcept;
 
  185    std::
string version() const noexcept;
 
  191    std::
string machine() const noexcept;
 
  194    std::shared_ptr<uv_utsname_t> uname;
 
  223    using cpu_time = 
decltype(uv_cpu_info_t::cpu_times);
 
  250static constexpr std::size_t DEFAULT_SIZE = 128;
 
  252template<
typename F, 
typename... Args>
 
  253std::string try_read(F &&f, Args &&...args) 
noexcept {
 
  254    std::size_t size = DEFAULT_SIZE;
 
  255    char buf[DEFAULT_SIZE];
 
  257    auto err = std::forward<F>(f)(args..., buf, &size);
 
  259    if(UV_ENOBUFS == err) {
 
  260        std::unique_ptr<char[]> data{
new char[size]};
 
  261        err = std::forward<F>(f)(args..., data.get(), &size);
 
  266    } 
else if(0 == err) {
 
  267        str.assign(buf, size);
 
  273void common_alloc_callback(uv_handle_t *, std::size_t suggested, uv_buf_t *buf);
 
  275sockaddr ip_addr(
const char *addr, 
unsigned int port);
 
  276socket_address sock_addr(
const sockaddr_in &addr);
 
  277socket_address sock_addr(
const sockaddr_in6 &addr);
 
  278socket_address sock_addr(
const sockaddr &addr);
 
  279socket_address sock_addr(
const sockaddr_storage &storage);
 
  289    using malloc_func_type = 
void *(*)(
size_t);
 
  290    using realloc_func_type = 
void *(*)(
void *, 
size_t);
 
  291    using calloc_func_type = 
void *(*)(
size_t, 
size_t);
 
  292    using free_func_type = void (*)(
void *);
 
  330        static std::
string homedir() noexcept;
 
  341        static std::
string tmpdir() noexcept;
 
  349        static std::
string env(const std::
string &name) noexcept;
 
  358        static 
bool env(const std::
string &name, const std::
string &value) noexcept;
 
  373        template<typename Func>
 
  374        static std::enable_if_t<std::is_invocable_v<Func, std::string_view, std::string_view>, 
bool>
 
  375        env(Func func) noexcept {
 
  376            uv_env_item_t *items = 
nullptr;
 
  379            const bool ret = (uv_os_environ(&items, &count) == 0);
 
  382                for(
int pos = 0; pos < count; ++pos) {
 
  383                    func(std::string_view{items[pos].name}, std::string_view{items[pos].value});
 
  386                uv_os_free_environ(items, count);
 
  515    static std::
string index_to_name(
unsigned int index) noexcept;
 
  527    static std::
string index_to_iid(
unsigned int index) noexcept;
 
  552    static 
bool replace_allocator(malloc_func_type malloc_func, realloc_func_type realloc_func, calloc_func_type calloc_func, free_func_type free_func) noexcept;
 
  558    static std::array<
double, 3> load_average() noexcept;
 
  567    static 
char **setup_args(
int argc, 
char **argv);
 
  573    static std::
string process_title();
 
  580    static 
bool process_title(const std::
string &title);
 
  586    static uint64_t total_memory() noexcept;
 
  599    static uint64_t constrained_memory() noexcept;
 
  605    static uint64_t available_memory() noexcept;
 
  611    static 
double uptime() noexcept;
 
  636    static uint64_t hrtime() noexcept;
 
  642    static std::
string path() noexcept;
 
  648    static std::
string cwd() noexcept;
 
  655    static 
bool chdir(const std::
string &dir) noexcept;
 
  668    static 
void sleep(
unsigned int msec) noexcept;
 
  675    static 
unsigned int available_parallelism() noexcept;
 
  682template<class... Func>
 
  684    using Func::operator()...;
 
  691template<
class... Func>
 
details::uv_type_wrapper< uv_os_fd_t > os_file_descriptor
details::uv_type_wrapper< uv_file > file_handle
details::uv_type_wrapper< uv_pid_t > pid_type
constexpr file_handle std_in
details::uv_type_wrapper< uv_handle_type > handle_category
uv_timespec64_t timespec64
constexpr file_handle std_err
details::uv_type_wrapper< uv_os_sock_t > os_socket_handle
uv_rusage_t resource_usage
constexpr file_handle std_out
Helper type for visitors.
decltype(uv_passwd_t::uid) uid() const noexcept
Gets the uid.
decltype(uv_passwd_t::gid) gid() const noexcept
Gets the gid.
std::string shell() const noexcept
Gets the shell.
std::string username() const noexcept
Gets the username.
std::string homedir() const noexcept
Gets the homedir.
static std::string hostname() noexcept
Returns the hostname.
static pid_type pid() noexcept
Returns the current process id.
std::string sysname() const noexcept
Gets the operating system name (like "Linux").
Windows size representation.