commit - 230a46c6267df18bb9b48a66399e9db3b3ece434
commit + f2a85a75526335d0b3c26a79bd9c50f7f5ef98a6
blob - c4d8e6eb13092ac9ee2254406b5ffab30ed5ca1c
blob + a1791a32da6f24b2d3a3060d95fb971e744eaecd
--- shared/error.h
+++ shared/error.h
/** Empty error code printer */
-inline void no_error_code() {}
+struct none
+{
+ void operator() () const {}
+};
-/** Error handler: print action, print error, return `false` */
+/** Error handler: print action, print error */
template<
typename TPrintAction,
typename TPrintError
TPrintError print_error
)
{
- occurred([=](){g_log << action;}, print_error);
+ occurred(
+ [action]
+ {
+ g_log << action;
+ },
+ print_error
+ );
}
blob - ef50e08bc2f5a86b92048b4cb1f110df6803ff2c
blob + ff03f00b2d778d4c85fb427b0ce7a9aa43609ff2
--- shared/transport.cc
+++ shared/transport.cc
{
if (tls_init() == -1)
{
- error::occurred("TLS initialization", error::no_error_code);
+ error::occurred("TLS initialization", error::none{});
return false;
}
config_t cfg{tls_config_new(), tls_config_free};
if (!cfg)
{
- error::occurred("Create TLS configuration", error::no_error_code);
+ error::occurred("Create TLS configuration", error::none{});
return;
}
if (tls_config_set_protocols(cfg.get(), protocols) == -1)
{
- error::occurred("Allow TLS 1.2 and TLS 1.3 protocols", error::no_error_code);
+ error::occurred("Allow TLS 1.2 and TLS 1.3 protocols", error::none{});
return;
}
if (tls_config_set_cert_file(cfg.get(), cert_file) == -1)
{
error::occurred(
- [=](){error::g_log << "Load certificate file " << cert_file;},
- error::no_error_code
+ [cert_file]
+ {
+ error::g_log << "Load certificate file " << cert_file;
+ },
+ error::none{}
);
return;
}
if (tls_config_set_key_file(cfg.get(), key_file) == -1)
{
error::occurred(
- [=](){error::g_log << "Load key file " << key_file;},
- error::no_error_code
+ [key_file]
+ {
+ error::g_log << "Load key file " << key_file;
+ },
+ error::none{}
);
return;
}
context_t ctx{tls_server(), tls_free};
if (!ctx)
{
- error::occurred("Create TLS server context", error::no_error_code);
+ error::occurred("Create TLS server context", error::none{});
return;
}
auto config_error = tls_config_error(cfg.get());
error::occurred(
"Configure TLS context",
- [=](){if (config_error) error::g_log << "Error: " << config_error << std::endl;}
+ [config_error]
+ {
+ if (config_error)
+ error::g_log << "Error: " << config_error << std::endl;
+ }
);
return;
}
struct tls *client_ctx = nullptr;
if (tls_accept_socket(server_ctx, &client_ctx, client_socket) == -1)
{
- error::occurred("TLS accept", error::no_error_code);
+ error::occurred("TLS accept", error::none{});
ret_ctx.reset();
return;
}
blob - 33d9148d832623c639854216d5b805f0452db1e2
blob + 0a39a90119400afb1373a43976637682d7e806e2
--- vostokd/vostokd.cc
+++ vostokd/vostokd.cc
bool server_loop(int server_socket, struct tls *ctx)
{
- error::g_log << "Enter to server loop..." << std::endl;
-
for (; ; )
{
if (listen(server_socket, 1024) == -1)
if (!client_socket)
{
error::occurred("Accept socket", error::print{});
- return false;
+ continue;
}
transport::context_t client_ctx{nullptr, tls_free};
transport::accept(ctx, client_socket.get(), client_ctx);
if (!client_ctx)
- return false;
+ continue;
- error::g_log << inet_ntoa(addr.sin_addr) << " accepted" << std::endl;
+ try
+ {
+ }
+ catch (const std::system_error &e)
+ {
+ error::occurred(
+ "Create client thread",
+ [&e]
+ {
+ error::g_log << "Error: " << std::dec << e.code()
+ << ". " << e.what() << std::endl;
+ }
+ );
+ }
}
return true;
}
if (bind(server_socket.get(), (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1)
{
error::occurred(
- [=](){error::g_log << "Bind to " << args.m_addr << ":" << std::dec << args.m_port;},
+ [&args]
+ {
+ error::g_log << "Bind to " << args.m_addr << ":" << std::dec << args.m_port;
+ },
error::print{}
);
return false;