Collection of useful C++ classes and utility functions
I find these useful when writing C++ code.
The classes are:
- FileDescriptor: a reference counted UNIX file descriptor representing an open file
- InetAddress: an interet address (IPv4 for now)
- Socket: a general socket
- UnixSocket: a UNIX Domain socket
- TCPSocket: a TCP socket
- UDPSocket: a UDP socket
- Logger: a level-aware logger that prints in color on TTYs
- MutexLock: an RAII class for handling pthread mutexes
- BitSet: a fixed size set of bits that allows allocation.
In addition, the following functions are provided:
- Hexdump: dump memory in hex
- Now: get the current nanosecond monotonic time.
The Socket classes are coroutine aware and need my coroutine library
Enjoy!
Add this to your WORKSPACE file to download and use toolbelt:
http_archive(
name = "toolbelt",
urls = ["https://github.com/dallison/cpp_toolbelt/archive/refs/tags/A.B.C.tar.gz"],
strip_prefix = "cpp_toolbelt-A.B.C",
)
Replacing A.B.C with the version you want (e.g. 1.0.3).
Add a dependency to your BUILD.bazel targets like this:
deps = [
# ...
"@toolbelt//toolbelt",
],
All the header files are in toolbelt/, so for example:
#include "toolbelt/fd.h
Then you can use it as:
toolbelt::FileDescriptor fd_;