uvw 2.12.1
Loading...
Searching...
No Matches
uvw::Utilities Struct Reference

Miscellaneous utilities. More...

#include <util.h>

Classes

struct  OS
 OS dedicated utilities. More...
 

Static Public Member Functions

static HandleType guessHandle (HandleCategory category) noexcept
 Gets the type of the handle given a category.
 
static HandleType guessHandle (FileHandle file) noexcept
 Gets the type of the stream to be used with the given descriptor.
 
static std::vector< CPUInfocpuInfo () noexcept
 Gets information about the CPUs on the system.
 
static std::vector< InterfaceAddressinterfaceAddresses () noexcept
 Gets a set of descriptors of all the available interfaces.
 
static std::string indexToName (unsigned int index) noexcept
 IPv6-capable implementation of if_indextoname.
 
static std::string indexToIid (unsigned int index) noexcept
 Retrieves a network interface identifier.
 
static bool replaceAllocator (MallocFuncType mallocFunc, ReallocFuncType reallocFunc, CallocFuncType callocFunc, FreeFuncType freeFunc) noexcept
 Override the use of some standard library’s functions.
 
static std::array< double, 3 > loadAverage () noexcept
 Gets the load average.
 
static char ** setupArgs (int argc, char **argv)
 Store the program arguments.
 
static std::string processTitle ()
 Gets the title of the current process.
 
static bool processTitle (const std::string &title)
 Sets the current process title.
 
static uint64_t totalMemory () noexcept
 Gets memory information (in bytes).
 
static uint64_t constrainedMemory () noexcept
 Gets the amount of memory available to the process (in bytes).
 
static double uptime () noexcept
 Gets the current system uptime.
 
static RUsage rusage () noexcept
 Gets the resource usage measures for the current process.
 
static uint64_t hrtime () noexcept
 Gets the current high-resolution real time.
 
static std::string path () noexcept
 Gets the executable path.
 
static std::string cwd () noexcept
 Gets the current working directory.
 
static bool chdir (const std::string &dir) noexcept
 Changes the current working directory.
 
static TimeVal64 timeOfDay () noexcept
 Cross-platform implementation of gettimeofday
 
static void sleep (unsigned int msec) noexcept
 Causes the calling thread to sleep for a while.
 
static unsigned int availableParallelism () noexcept
 Returns an estimate of the amount of parallelism a program should use (always a non-zero value).
 

Detailed Description

Miscellaneous utilities.

Miscellaneous functions that don’t really belong to any other class.

Definition at line 460 of file util.h.

Member Function Documentation

◆ availableParallelism()

static unsigned int uvw::Utilities::availableParallelism ( )
staticnoexcept

Returns an estimate of the amount of parallelism a program should use (always a non-zero value).

Returns
Estimate of the amount of parallelism a program should use.

◆ chdir()

static bool uvw::Utilities::chdir ( const std::string & dir)
staticnoexcept

Changes the current working directory.

Parameters
dirThe working directory to be set.
Returns
True in case of success, false otherwise.

◆ constrainedMemory()

static uint64_t uvw::Utilities::constrainedMemory ( )
staticnoexcept

Gets the amount of memory available to the process (in bytes).

Gets the amount of memory available to the process based on limits imposed by the OS. If there is no such constraint, or the constraint is unknown, 0 is returned.
Note that it is not unusual for this value to be less than or greater than totalMemory.

Returns
Amount of memory available to the process.

◆ cpuInfo()

static std::vector< CPUInfo > uvw::Utilities::cpuInfo ( )
staticnoexcept

Gets information about the CPUs on the system.

This function can be used to query the underlying system and get a set of descriptors of all the available CPUs.

Returns
A set of descriptors of all the available CPUs.

◆ cwd()

static std::string uvw::Utilities::cwd ( )
staticnoexcept

Gets the current working directory.

Returns
The current working directory, an empty string in case of errors.

◆ guessHandle() [1/2]

static HandleType uvw::Utilities::guessHandle ( FileHandle file)
staticnoexcept

Gets the type of the stream to be used with the given descriptor.

Returns the type of stream that should be used with a given file descriptor.
Usually this will be used during initialization to guess the type of the stdio streams.

Parameters
fileA valid descriptor.
Returns
One of the following types:
  • HandleType::UNKNOWN
  • HandleType::PIPE
  • HandleType::TCP
  • HandleType::TTY
  • HandleType::UDP
  • HandleType::FILE

◆ guessHandle() [2/2]

static HandleType uvw::Utilities::guessHandle ( HandleCategory category)
staticnoexcept

Gets the type of the handle given a category.

Parameters
categoryA properly initialized handle category.
Returns
The actual type of the handle as defined by HandleType

◆ hrtime()

static uint64_t uvw::Utilities::hrtime ( )
staticnoexcept

Gets the current high-resolution real time.

The time is expressed in nanoseconds. It is relative to an arbitrary time in the past. It is not related to the time of the day and therefore not subject to clock drift. The primary use is for measuring performance between interval.

Returns
The current high-resolution real time.

◆ indexToIid()

static std::string uvw::Utilities::indexToIid ( unsigned int index)
staticnoexcept

Retrieves a network interface identifier.

See the official documentation for further details.

Parameters
indexNetwork interface index.
Returns
Network interface identifier.

◆ indexToName()

static std::string uvw::Utilities::indexToName ( unsigned int index)
staticnoexcept

IPv6-capable implementation of if_indextoname.

Mapping between network interface names and indexes.

See the official documentation for further details.

Parameters
indexNetwork interface index.
Returns
Network interface name.

◆ interfaceAddresses()

static std::vector< InterfaceAddress > uvw::Utilities::interfaceAddresses ( )
staticnoexcept

Gets a set of descriptors of all the available interfaces.

This function can be used to query the underlying system and get a set of descriptors of all the available interfaces, either internal or not.

Returns
A set of descriptors of all the available interfaces.

◆ loadAverage()

static std::array< double, 3 > uvw::Utilities::loadAverage ( )
staticnoexcept

Gets the load average.

Returns
[0,0,0] on Windows (not available), the load average otherwise.

◆ path()

static std::string uvw::Utilities::path ( )
staticnoexcept

Gets the executable path.

Returns
The executable path, an empty string in case of errors.

◆ processTitle() [1/2]

static std::string uvw::Utilities::processTitle ( )
static

Gets the title of the current process.

Returns
The process title.

◆ processTitle() [2/2]

static bool uvw::Utilities::processTitle ( const std::string & title)
static

Sets the current process title.

Parameters
titleThe process title to be set.
Returns
True in case of success, false otherwise.

◆ replaceAllocator()

static bool uvw::Utilities::replaceAllocator ( MallocFuncType mallocFunc,
ReallocFuncType reallocFunc,
CallocFuncType callocFunc,
FreeFuncType freeFunc )
staticnoexcept

Override the use of some standard library’s functions.

Override the use of the standard library’s memory allocation functions.
This method must be invoked before any other uvw function is called or after all resources have been freed and thus the underlying library doesn’t reference any allocated memory chunk.

If any of the function pointers is null, the invokation will fail.

Note
There is no protection against changing the allocator multiple times. If the user changes it they are responsible for making sure the allocator is changed while no memory was allocated with the previous allocator, or that they are compatible.
Parameters
mallocFuncReplacement function for malloc.
reallocFuncReplacement function for realloc.
callocFuncReplacement function for calloc.
freeFuncReplacement function for free.
Returns
True in case of success, false otherwise.

◆ rusage()

static RUsage uvw::Utilities::rusage ( )
staticnoexcept

Gets the resource usage measures for the current process.

Returns
Resource usage measures, zeroes-filled object in case of errors.

◆ setupArgs()

static char ** uvw::Utilities::setupArgs ( int argc,
char ** argv )
static

Store the program arguments.

Required for getting / setting the process title.

Returns
Arguments that haven't been consumed internally.

◆ sleep()

static void uvw::Utilities::sleep ( unsigned int msec)
staticnoexcept

Causes the calling thread to sleep for a while.

Parameters
msecNumber of milliseconds to sleep.

◆ timeOfDay()

static TimeVal64 uvw::Utilities::timeOfDay ( )
staticnoexcept

Cross-platform implementation of gettimeofday

Returns
The current time.

◆ totalMemory()

static uint64_t uvw::Utilities::totalMemory ( )
staticnoexcept

Gets memory information (in bytes).

Returns
Memory information.

◆ uptime()

static double uvw::Utilities::uptime ( )
staticnoexcept

Gets the current system uptime.

Returns
The current system uptime or 0 in case of errors.

The documentation for this struct was generated from the following file: