-
Notifications
You must be signed in to change notification settings - Fork 1
/
io_result.h
26 lines (20 loc) · 914 Bytes
/
io_result.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once
#include <cstring>
#include <errno.h>
#include <string_view>
namespace quic {
// Return result from a read or write operation that wraps an errno value. It is implicitly
// convertible to bool to test for "is not an error" (which is the inverse of casting a plain
// integer error code value to bool).
struct io_result {
// An error code, typically an errno value
int error_code{0};
// Returns true if this represent a successful result, i.e. an error_code of 0.
operator bool() const { return error_code == 0; }
// Returns true if this is an error value indicating a failure to write without blocking (only
// applied to io_result's capturing an errno).
bool blocked() const { return error_code == EAGAIN || error_code == EWOULDBLOCK; }
// Returns the errno string for the given error code.
std::string_view str() const { return strerror(error_code); }
};
}