Loading Builder/src/main.cpp +0 −4 Original line number Diff line number Diff line Loading @@ -193,10 +193,6 @@ int main(int argc, char *argv[]) { acceptor.accept(client_stream.next_layer()); client_stream.accept(); // Use keep alive, which hopefully detect badly disconnected clients boost::asio::socket_base::keep_alive keep_alive(true); socket.set_option(keep_alive); Logger::info("Setting the websocket stream to handle binary data and have an unlimited(uint64_t) message size"); client_stream.binary(true); client_stream.read_message_max(0); Loading BuilderQueue/include/Connection.h +3 −7 Original line number Diff line number Diff line Loading @@ -16,13 +16,7 @@ class Connection : public std::enable_shared_from_this<Connection> { public: explicit Connection(tcp::socket socket, BuilderQueue &queue) : stream(std::move(socket)), queue(queue) { // Use keep alive, which hopefully detect badly disconnected clients boost::asio::socket_base::keep_alive keep_alive(true); boost::system::error_code ec; socket.set_option(keep_alive, ec); if(ec) { Logger::error("Error setting keep alive on socket"); } enable_keep_alive(); }; ~Connection() { Loading @@ -40,6 +34,8 @@ private: beast::flat_buffer buffer; boost::optional<BuilderData> builder; void enable_keep_alive(); void read_request_string(); void request_builder(); Loading BuilderQueue/src/Connection.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,28 @@ using namespace std::placeholders; void Connection::enable_keep_alive() { auto socket = stream.next_layer().native_handle(); // Enable keep alive int enable = 1; int rc = setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)); // Set keep alive values unsigned interval_milliseconds = 30000; struct timeval tv; tv.tv_sec = interval_milliseconds / 1000; tv.tv_usec = interval_milliseconds % 1000; int max_retry = 5; rc |= setsockopt(socket, SOL_TCP, TCP_KEEPIDLE, &tv, sizeof(tv)); rc |= setsockopt(socket, SOL_TCP, TCP_KEEPINTVL, &tv, sizeof(tv)); rc |= setsockopt(socket, SOL_TCP, TCP_KEEPCNT, &max_retry, sizeof(max_retry)); if(rc != 0) { Logger::error(std::string("Error setting keepalive: ") + strerror(errno)); } } void Connection::wait_for_close() { // Persist this connection auto self(shared_from_this()); Loading Loading
Builder/src/main.cpp +0 −4 Original line number Diff line number Diff line Loading @@ -193,10 +193,6 @@ int main(int argc, char *argv[]) { acceptor.accept(client_stream.next_layer()); client_stream.accept(); // Use keep alive, which hopefully detect badly disconnected clients boost::asio::socket_base::keep_alive keep_alive(true); socket.set_option(keep_alive); Logger::info("Setting the websocket stream to handle binary data and have an unlimited(uint64_t) message size"); client_stream.binary(true); client_stream.read_message_max(0); Loading
BuilderQueue/include/Connection.h +3 −7 Original line number Diff line number Diff line Loading @@ -16,13 +16,7 @@ class Connection : public std::enable_shared_from_this<Connection> { public: explicit Connection(tcp::socket socket, BuilderQueue &queue) : stream(std::move(socket)), queue(queue) { // Use keep alive, which hopefully detect badly disconnected clients boost::asio::socket_base::keep_alive keep_alive(true); boost::system::error_code ec; socket.set_option(keep_alive, ec); if(ec) { Logger::error("Error setting keep alive on socket"); } enable_keep_alive(); }; ~Connection() { Loading @@ -40,6 +34,8 @@ private: beast::flat_buffer buffer; boost::optional<BuilderData> builder; void enable_keep_alive(); void read_request_string(); void request_builder(); Loading
BuilderQueue/src/Connection.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,28 @@ using namespace std::placeholders; void Connection::enable_keep_alive() { auto socket = stream.next_layer().native_handle(); // Enable keep alive int enable = 1; int rc = setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)); // Set keep alive values unsigned interval_milliseconds = 30000; struct timeval tv; tv.tv_sec = interval_milliseconds / 1000; tv.tv_usec = interval_milliseconds % 1000; int max_retry = 5; rc |= setsockopt(socket, SOL_TCP, TCP_KEEPIDLE, &tv, sizeof(tv)); rc |= setsockopt(socket, SOL_TCP, TCP_KEEPINTVL, &tv, sizeof(tv)); rc |= setsockopt(socket, SOL_TCP, TCP_KEEPCNT, &max_retry, sizeof(max_retry)); if(rc != 0) { Logger::error(std::string("Error setting keepalive: ") + strerror(errno)); } } void Connection::wait_for_close() { // Persist this connection auto self(shared_from_this()); Loading