llarp::util
Classes
| Name | |
|---|---|
| class | llarp::util::Barrier Barrier class that blocks all threads until the high water mark of threads (set during construction) is reached, then releases them all. |
| class | llarp::util::bind_socket_error |
| struct | llarp::util::ContentionKiller |
| struct | llarp::util::DecayingHashSet |
| struct | llarp::util::DecayingHashTable |
| struct | llarp::util::FD RAII wrapper for auto-closing a file descriptor. |
| struct | llarp::util::FileHash |
| class | llarp::util::GeoIPHelper GeoIP helper class. |
| struct | llarp::util::IOCTL |
| struct | llarp::util::MultithreadedHasher |
| struct | llarp::util::NonBlocking sets nonblocking on a FD. |
| struct | llarp::util::NullLock a lock that does nothing |
| struct | llarp::util::NullMutex a mutex that does nothing |
| class | llarp::util::permission_error |
| class | llarp::util::Semaphore |
| class | llarp::util::source_location |
Types
| Name | |
|---|---|
| using std::error_code | error_code_t |
| template <typename T ,typename Container =std::vector using std::priority_queue< T, Container, std::greater< typename Container::value_type > > |
descending_priority_queue priority queue that sorts in descending order, basically a normal priority queue in reverse. |
| using std::shared_timed_mutex | Mutex Default mutex type, supporting shared and exclusive locks. |
| using std::lock_guard< Mutex > | Lock Basic RAII lock type for the default mutex type. |
Functions
| Name | |
|---|---|
| std::string | slurp_file(const fs::path & filename) Reads a binary file from disk into a string. Throws on error. |
| size_t | slurp_file(const fs::path & filename, char * buffer, size_t buffer_size) Reads a binary file from disk directly into a buffer. |
| template <typename Char ,std::enable_if_t< sizeof(Char)==1 and not std::is_same_v< Char, char >, int > =1> size_t |
slurp_file(const fs::path & filename, Char * buffer, size_t buffer_size) Same, but for some non-char but single-byte char type (e.g. byte_t, std::byte, unsigned char). |
| void | dump_file(const fs::path & filename, std::string_view contents) Dumps binary string contents to disk. |
| template <typename Char ,std::enable_if_t< sizeof(Char)==1, int > =0> void |
dump_file(const fs::path & filename, const Char * buffer, size_t buffer_size) Same as above, but works via char-like buffer. |
| std::string | filepath(const fs::path & f) |
| error_code_t | EnsurePrivateFile(const fs::path & pathname) Ensure that a file exists and has correct permissions return any error code or success. |
| template <typename T > std::optional< T > |
OpenFileStream(const fs::path & pathname, std::ios::openmode mode) open a stream to a file and ensure it exists before open sets any permissions on creation |
| template <typename PathVisitor > void |
IterDir(const fs::path & _path, PathVisitor visit) |
| std::shared_ptr< GeoIPHelper > | GeoIPHelperInstance() get singleton geoip helper instance. |
| template <typename Return ,typename Class ,typename Derived ,typename... Arg,typename =std::enable_if_t auto |
memFn(Return(Class::*)(Arg...) f, Derived * self) |
| template <typename Return ,typename Class ,typename Derived ,typename... Arg,typename =std::enable_if_t auto |
memFn(Return(Class::*)(Arg...) const f, const Derived * self) |
| template <typename Return ,typename Class ,typename Derived ,typename... Arg,typename =std::enable_if_t auto |
memFn(Return(Class::*)(Arg...) f, std::shared_ptr< Derived > self) |
| template <typename T ,typename Visit_t ,typename Queue_t =std::priority_queue auto |
with_inplace_priority_queue(Container_t & vec, Visit_t && visit, const typename Queue_t::value_compare & compare =typename Queue_t::value_compare{}) |
| template <typename... Mutex> auto |
unique_locks(Mutex &... lockables) Obtains multiple unique locks simultaneously and atomically. |
| void | SetThreadName(const std::string & name) |
| pid_t | GetPid() |
Attributes
| Name | |
|---|---|
| constexpr auto | erase_if remove items from a container if a predicate is true return the number of items removed |
Types Documentation
using error_code_t
using llarp::util::error_code_t = typedef std::error_code;
using descending_priority_queue
template <typename T ,
typename Container =std::vector<T>>
using llarp::util::descending_priority_queue = typedef std::priority_queue<T, Container, std::greater<typename Container::value_type> >;
priority queue that sorts in descending order, basically a normal priority queue in reverse.
using Mutex
using llarp::util::Mutex = typedef std::shared_timed_mutex;
Default mutex type, supporting shared and exclusive locks.
using Lock
using llarp::util::Lock = typedef std::lock_guard<Mutex>;
Basic RAII lock type for the default mutex type.
Functions Documentation
function slurp_file
std::string slurp_file(
const fs::path & filename
)
Reads a binary file from disk into a string. Throws on error.
function slurp_file
size_t slurp_file(
const fs::path & filename,
char * buffer,
size_t buffer_size
)
Reads a binary file from disk directly into a buffer.
Throws a std::length_error if the file is bigger than the buffer. Returns the bytes copied on success.
function slurp_file
template <typename Char ,
std::enable_if_t< sizeof(Char)==1 and not std::is_same_v< Char, char >, int > =1>
inline size_t slurp_file(
const fs::path & filename,
Char * buffer,
size_t buffer_size
)
Same, but for some non-char but single-byte char type (e.g. byte_t, std::byte, unsigned char).
function dump_file
void dump_file(
const fs::path & filename,
std::string_view contents
)
Dumps binary string contents to disk.
The file is overwritten if it already exists. Throws on error.
function dump_file
template <typename Char ,
std::enable_if_t< sizeof(Char)==1, int > =0>
inline void dump_file(
const fs::path & filename,
const Char * buffer,
size_t buffer_size
)
Same as above, but works via char-like buffer.
function filepath
std::string filepath(
const fs::path & f
)
function EnsurePrivateFile
error_code_t EnsurePrivateFile(
const fs::path & pathname
)
Ensure that a file exists and has correct permissions return any error code or success.
function OpenFileStream
template <typename T >
std::optional< T > OpenFileStream(
const fs::path & pathname,
std::ios::openmode mode
)
open a stream to a file and ensure it exists before open sets any permissions on creation
function IterDir
template <typename PathVisitor >
static void IterDir(
const fs::path & _path,
PathVisitor visit
)
function GeoIPHelperInstance
std::shared_ptr< GeoIPHelper > GeoIPHelperInstance()
get singleton geoip helper instance.
function memFn
template <typename Return ,
typename Class ,
typename Derived ,
typename... Arg,
typename =std::enable_if_t<std::is_base_of<Class, Derived>::value>>
auto memFn(
Return(Class::*)(Arg...) f,
Derived * self
)
function memFn
template <typename Return ,
typename Class ,
typename Derived ,
typename... Arg,
typename =std::enable_if_t<std::is_base_of<Class, Derived>::value>>
auto memFn(
Return(Class::*)(Arg...) const f,
const Derived * self
)
function memFn
template <typename Return ,
typename Class ,
typename Derived ,
typename... Arg,
typename =std::enable_if_t<std::is_base_of<Class, Derived>::value>>
auto memFn(
Return(Class::*)(Arg...) f,
std::shared_ptr< Derived > self
)
function with_inplace_priority_queue
template <typename T ,
typename Visit_t ,
typename Queue_t =std::priority_queue<T>,
typename Container_t =std::vector<T>>
inline auto with_inplace_priority_queue(
Container_t & vec,
Visit_t && visit,
const typename Queue_t::value_compare & compare =typename Queue_t::value_compare{}
)
function unique_locks
template <typename... Mutex>
auto unique_locks(
Mutex &... lockables
)
Obtains multiple unique locks simultaneously and atomically.
Returns a tuple of all the held locks.
function SetThreadName
void SetThreadName(
const std::string & name
)
function GetPid
inline pid_t GetPid()
Attributes Documentation
variable erase_if
constexpr auto erase_if = [](auto& container, auto&& pred) -> std::size_t {
std::size_t removed = 0;
for (auto itr = container.begin(); itr != container.end();)
{
if (pred(*itr))
{
itr = container.erase(itr);
removed++;
}
else
itr++;
}
return removed;
};
remove items from a container if a predicate is true return the number of items removed
Updated on 2026-01-10 at 22:49:45 +0000