Linux server-side TFO: Clean-up upon code review

This commit is contained in:
gavin.smith@coralbay.tv 2019-01-03 22:06:59 +00:00
commit 0eb6269c70
2 changed files with 5 additions and 15 deletions

View file

@ -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().

View file

@ -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;