Linux server-side TFO: Clean-up upon code review
This commit is contained in:
parent
4d7f3729c3
commit
0eb6269c70
2 changed files with 5 additions and 15 deletions
|
|
@ -351,7 +351,7 @@ namespace SimpleWeb {
|
||||||
std::string address;
|
std::string address;
|
||||||
/// Set to false to avoid binding the socket to an address that is already in use. Defaults to true.
|
/// Set to false to avoid binding the socket to an address that is already in use. Defaults to true.
|
||||||
bool reuse_address = true;
|
bool reuse_address = true;
|
||||||
/// Makes use of RFC 7413 or TCP Fast Open (TFO)
|
/// Make use of RFC 7413 or TCP Fast Open (TFO)
|
||||||
bool fast_open = false;
|
bool fast_open = false;
|
||||||
};
|
};
|
||||||
/// Set before calling start().
|
/// Set before calling start().
|
||||||
|
|
|
||||||
18
utility.hpp
18
utility.hpp
|
|
@ -35,24 +35,14 @@ namespace SimpleWeb {
|
||||||
{
|
{
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
std::ifstream ifs("/proc/sys/net/ipv4/tcp_fastopen");
|
std::ifstream ifs("/proc/sys/net/ipv4/tcp_fastopen");
|
||||||
if (!ifs.is_open()) { return false; }
|
if (!ifs) { return false; }
|
||||||
std::string line;
|
std::string line;
|
||||||
if (!std::getline(ifs, line)) { return false; }
|
if (!std::getline(ifs, line)) { return false; }
|
||||||
std::istringstream iss(line);
|
std::istringstream iss(line);
|
||||||
uint8_t value = 0;
|
int value = 0;
|
||||||
iss >> value;
|
iss >> value;
|
||||||
if (iss.fail()) { return false; } // Should never happen in theory.
|
if (!iss) { return false; } // Should never happen in theory.
|
||||||
auto mode_matches_request = [](const connection_mode mode, const uint8_t value)
|
return (static_cast<int>(mode) & value) != 0;
|
||||||
{
|
|
||||||
const auto m = static_cast<uint8_t>(mode);
|
|
||||||
if (mode == connection_mode::client ||
|
|
||||||
mode == connection_mode::server)
|
|
||||||
{
|
|
||||||
return (m & value) != 0;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
return mode_matches_request(mode, value);
|
|
||||||
#else
|
#else
|
||||||
(void)mode;
|
(void)mode;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue