commit - 8b30e45a42543cb275e00d9380d46163b6a567bf
commit + 9c066781cbe07d00c86d7e86b65c9c6b6bdea02a
blob - 76903d42f07e07e8a0ee8e39b465e147beb59913
blob + b3f83890c4effab7d20d410118e4c18cd4ad7214
--- vostok/transport.cc
+++ vostok/transport.cc
class PrintIfError
{
public:
- explicit PrintIfError(czstring error) : m_error{error} {}
+ explicit PrintIfError(czstring error, const ssize_t *pret=nullptr)
+ : m_error{error}
+ , m_pret{pret}
+ {
+ }
+
void operator() () const
{
+ if (m_pret)
+ error::g_log << "Return value: " << std::dec << *m_pret;
+ if (m_pret && m_error)
+ error::g_log << ". ";
if (m_error)
error::g_log << "Error: " << m_error;
}
private:
czstring m_error;
+ const ssize_t *m_pret;
};
return;
}
- {
- std::array<char, 128> addr_str{};
- auto printable = inet_ntop(AF_INET, &addr.sin_addr, &addr_str[0], addr_str.size());
- if (printable)
- error::g_log << printable << " ";
- }
-
struct tls *ctx = nullptr;
if (tls_accept_socket(server_ctx, &ctx, m_fd.get()) == -1)
{
auto ret = tls_write(ctx, buff.begin(), buff.size());
if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT)
continue;
- if (ret == 0)
+ if ((ret == 0) || (ret == -1))
{
- error::occurred("Checking that TLS write did not return 0", PrintIfError{tls_error(ctx)});
+ error::occurred("TLS write", PrintIfError{tls_error(ctx), &ret});
return false;
}
- if (ret == -1)
- {
- error::occurred("TLS write", PrintIfError{tls_error(ctx)});
- return false;
- }
-
buff = buff.subspan(ret);
}
return true;
blob - 1f2d24834571a516c40c27cc8314984a1332dc16
blob + 5bf0f7168ca12925f06e65023d88a6a3ab3193ab
--- vostok/vostok.cc
+++ vostok/vostok.cc
{
-void put_time_prefix()
-{
- const std::time_t t{std::time(nullptr)};
- struct tm converted{};
- gmtime_r(&t, &converted);
- error::g_log
- << std::dec << std::setw(2) << std::setfill('0') << converted.tm_hour
- << ":"
- << std::dec << std::setw(2) << std::setfill('0') << converted.tm_min
- << ":"
- << std::dec << std::setw(2) << std::setfill('0') << converted.tm_sec
- << " ";
-}
-
-
-struct LogThreadId
-{
- LogThreadId()
- {
- put_time_prefix();
- error::g_log << "+" << std::hex << m_thread_id << " ";
- }
- ~LogThreadId()
- {
- put_time_prefix();
- error::g_log << "-" << std::hex << m_thread_id << std::endl;
- }
-
- const std::thread::id m_thread_id{std::this_thread::get_id()};
-};
-
-
namespace meta
{
const std::string TEXT_GEMINI{"text/gemini"};
void client_thread(const transport::AcceptedClient *accepted_client, int directory_fd, const Mime &mime)
{
- LogThreadId _log_thread_id;
-
assert(accepted_client);
std::unique_ptr<const transport::AcceptedClient> accepted_client_deleter{accepted_client};
break;
}
- put_time_prefix();
error::g_log << "20 " << meta_string << " \"" << path << "\"" << std::endl;
}
bool server_loop(int server_socket, NotNull<struct tls *>server_ctx, int directory_fd, const Mime &mime)
{
- LogThreadId _log_thread_id;
-
error::g_log << "🚀 Vostok server listening..." << std::endl;
for (; ; )
{