|
Sponge
CS144's user-space TCP library
|
Go to the documentation of this file. 1 #ifndef SPONGE_LIBSPONGE_UTIL_HH
2 #define SPONGE_LIBSPONGE_UTIL_HH
12 #include <system_error>
43 int SystemCall(
const char *attempt,
const int return_value,
const int errno_mask = 0);
62 void add(std::string_view data);
63 uint16_t
value()
const;
67 void hexdump(
const char *data,
const size_t len,
const size_t indent = 0);
70 void hexdump(
const uint8_t *data,
const size_t len,
const size_t indent = 0);
72 #endif // SPONGE_LIBSPONGE_UTIL_HH
std::mt19937 get_random_generator()
Seed a fast random generator.
const char * what() const noexcept override
Returns a C string describing the error.
void hexdump(const char *data, const size_t len, const size_t indent=0)
Hexdump the contents of a packet (or any other sequence of bytes)
void add(std::string_view data)
std::system_error plus the name of what was being attempted
unix_error(const std::string &attempt, const int error=errno)
std::string _attempt_and_error
What was attempted, and what happened.
uint64_t timestamp_ms()
Get the time in milliseconds since the program began.
InternetChecksum(const uint32_t initial_sum=0)
int SystemCall(const char *attempt, const int return_value, const int errno_mask=0)
Error-checking wrapper for most syscalls.
tagged_error(const std::error_category &category, const std::string &attempt, const int error_code)
Construct from a category, an attempt, and an error code.
a tagged_error for syscalls
The internet checksum algorithm.