diff options
| author | Stefan Boberg <[email protected]> | 2023-12-05 08:51:53 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-12-05 08:51:53 +0100 |
| commit | 0b9d89f5beb889c1785a8f22b586c59bcca0b3ea (patch) | |
| tree | b0359fb51b002b28d9b480813d308cc93c1e220f /src | |
| parent | 0.2.36-pre3 (diff) | |
| download | zen-0b9d89f5beb889c1785a8f22b586c59bcca0b3ea.tar.xz zen-0b9d89f5beb889c1785a8f22b586c59bcca0b3ea.zip | |
HTTP plugin request debug logging (#587)
* added log level control/query to LoggerRef
* added debug logging to http plugin implementation
* added GetDebugName() to transport plugin interfaces
* added debug name to log output
Diffstat (limited to 'src')
| -rw-r--r-- | src/transports/transport-sdk/include/transportplugin.h | 18 | ||||
| -rw-r--r-- | src/transports/winsock/winsock.cpp | 32 | ||||
| -rw-r--r-- | src/zencore/include/zencore/logbase.h | 3 | ||||
| -rw-r--r-- | src/zencore/logging.cpp | 12 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpserver.h | 10 | ||||
| -rw-r--r-- | src/zenhttp/servers/httpasio.cpp | 5 | ||||
| -rw-r--r-- | src/zenhttp/servers/httpmulti.cpp | 5 | ||||
| -rw-r--r-- | src/zenhttp/servers/httpmulti.h | 2 | ||||
| -rw-r--r-- | src/zenhttp/servers/httpnull.cpp | 3 | ||||
| -rw-r--r-- | src/zenhttp/servers/httpnull.h | 2 | ||||
| -rw-r--r-- | src/zenhttp/servers/httpplugin.cpp | 169 | ||||
| -rw-r--r-- | src/zenhttp/servers/httpsys.cpp | 5 | ||||
| -rw-r--r-- | src/zenhttp/transports/asiotransport.cpp | 20 | ||||
| -rw-r--r-- | src/zenhttp/transports/dlltransport.cpp | 82 | ||||
| -rw-r--r-- | src/zenhttp/transports/winsocktransport.cpp | 32 | ||||
| -rw-r--r-- | src/zenserver/zenserver.cpp | 2 |
16 files changed, 256 insertions, 146 deletions
diff --git a/src/transports/transport-sdk/include/transportplugin.h b/src/transports/transport-sdk/include/transportplugin.h index 2a3b8075f..4347868e6 100644 --- a/src/transports/transport-sdk/include/transportplugin.h +++ b/src/transports/transport-sdk/include/transportplugin.h @@ -77,11 +77,12 @@ public: class TransportPlugin { public: - virtual uint32_t AddRef() const = 0; - virtual uint32_t Release() const = 0; - virtual void Configure(const char* OptionTag, const char* OptionValue) = 0; - virtual void Initialize(TransportServer* ServerInterface) = 0; - virtual void Shutdown() = 0; + virtual uint32_t AddRef() const = 0; + virtual uint32_t Release() const = 0; + virtual void Configure(const char* OptionTag, const char* OptionValue) = 0; + virtual void Initialize(TransportServer* ServerInterface) = 0; + virtual void Shutdown() = 0; + virtual const char* GetDebugName() = 0; /** Check whether this transport is usable. */ @@ -99,9 +100,10 @@ public: class TransportConnection { public: - virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) = 0; - virtual void Shutdown(bool Receive, bool Transmit) = 0; - virtual void CloseConnection() = 0; + virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) = 0; + virtual void Shutdown(bool Receive, bool Transmit) = 0; + virtual void CloseConnection() = 0; + virtual const char* GetDebugName() = 0; }; } // namespace zen diff --git a/src/transports/winsock/winsock.cpp b/src/transports/winsock/winsock.cpp index 28ac10ec1..7ee2b5ed1 100644 --- a/src/transports/winsock/winsock.cpp +++ b/src/transports/winsock/winsock.cpp @@ -51,12 +51,13 @@ public: // TransportPlugin implementation - virtual uint32_t AddRef() const override; - virtual uint32_t Release() const override; - virtual void Configure(const char* OptionTag, const char* OptionValue) override; - virtual void Initialize(TransportServer* ServerInterface) override; - virtual void Shutdown() override; - virtual bool IsAvailable() override; + virtual uint32_t AddRef() const override; + virtual uint32_t Release() const override; + virtual void Configure(const char* OptionTag, const char* OptionValue) override; + virtual void Initialize(TransportServer* ServerInterface) override; + virtual void Shutdown() override; + virtual const char* GetDebugName() override; + virtual bool IsAvailable() override; private: TransportServer* m_ServerInterface = nullptr; @@ -80,9 +81,10 @@ public: // TransportConnection implementation - virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; - virtual void Shutdown(bool Receive, bool Transmit) override; - virtual void CloseConnection() override; + virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; + virtual void Shutdown(bool Receive, bool Transmit) override; + virtual void CloseConnection() override; + virtual const char* GetDebugName() override; private: zen::Ref<TransportServerConnection> m_ConnectionHandler; @@ -153,6 +155,12 @@ WinsockTransportConnection::CloseConnection() m_ClientSocket = 0; } +const char* +WinsockTransportConnection::GetDebugName() +{ + return nullptr; +} + int64_t WinsockTransportConnection::WriteBytes(const void* Buffer, size_t DataSize) { @@ -342,6 +350,12 @@ WinsockTransportPlugin::Shutdown() } } +const char* +WinsockTransportPlugin::GetDebugName() +{ + return nullptr; +} + bool WinsockTransportPlugin::IsAvailable() { diff --git a/src/zencore/include/zencore/logbase.h b/src/zencore/include/zencore/logbase.h index ad873aa51..00af68b0a 100644 --- a/src/zencore/include/zencore/logbase.h +++ b/src/zencore/include/zencore/logbase.h @@ -90,6 +90,9 @@ struct LoggerRef bool ShouldLog(int Level) const; inline operator bool() const { return SpdLogger != nullptr; } + void SetLogLevel(logging::level::LogLevel NewLogLevel); + logging::level::LogLevel GetLogLevel(); + spdlog::logger* SpdLogger = nullptr; }; diff --git a/src/zencore/logging.cpp b/src/zencore/logging.cpp index 434c461ae..025ed4262 100644 --- a/src/zencore/logging.cpp +++ b/src/zencore/logging.cpp @@ -320,6 +320,18 @@ LoggerRef::ShouldLog(int Level) const return SpdLogger->should_log(static_cast<spdlog::level::level_enum>(Level)); } +void +LoggerRef::SetLogLevel(logging::level::LogLevel NewLogLevel) +{ + SpdLogger->set_level(to_spdlog_level(NewLogLevel)); +} + +logging::level::LogLevel +LoggerRef::GetLogLevel() +{ + return logging::level::to_logging_level(SpdLogger->level()); +} + thread_local ScopedActivityBase* t_ScopeStack = nullptr; ScopedActivityBase* diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h index eabad4728..1089dd221 100644 --- a/src/zenhttp/include/zenhttp/httpserver.h +++ b/src/zenhttp/include/zenhttp/httpserver.h @@ -175,11 +175,11 @@ private: class HttpServer : public RefCounted { public: - virtual void RegisterService(HttpService& Service) = 0; - virtual int Initialize(int BasePort) = 0; - virtual void Run(bool IsInteractiveSession) = 0; - virtual void RequestExit() = 0; - virtual void Close() = 0; + virtual void RegisterService(HttpService& Service) = 0; + virtual int Initialize(int BasePort, std::filesystem::path DataDir) = 0; + virtual void Run(bool IsInteractiveSession) = 0; + virtual void RequestExit() = 0; + virtual void Close() = 0; }; struct HttpServerConfig diff --git a/src/zenhttp/servers/httpasio.cpp b/src/zenhttp/servers/httpasio.cpp index c62aca001..9fca314b3 100644 --- a/src/zenhttp/servers/httpasio.cpp +++ b/src/zenhttp/servers/httpasio.cpp @@ -941,7 +941,7 @@ public: ~HttpAsioServer(); virtual void RegisterService(HttpService& Service) override; - virtual int Initialize(int BasePort) override; + virtual int Initialize(int BasePort, std::filesystem::path DataDir) override; virtual void Run(bool IsInteractiveSession) override; virtual void RequestExit() override; virtual void Close() override; @@ -992,8 +992,9 @@ HttpAsioServer::RegisterService(HttpService& Service) } int -HttpAsioServer::Initialize(int BasePort) +HttpAsioServer::Initialize(int BasePort, std::filesystem::path DataDir) { + ZEN_UNUSED(DataDir); m_BasePort = m_Impl->Start(gsl::narrow<uint16_t>(BasePort), m_ForceLoopback, m_ThreadCount); return m_BasePort; } diff --git a/src/zenhttp/servers/httpmulti.cpp b/src/zenhttp/servers/httpmulti.cpp index d8ebdc9c0..2a6a90d2e 100644 --- a/src/zenhttp/servers/httpmulti.cpp +++ b/src/zenhttp/servers/httpmulti.cpp @@ -28,15 +28,16 @@ HttpMultiServer::RegisterService(HttpService& Service) } int -HttpMultiServer::Initialize(int BasePort) +HttpMultiServer::Initialize(int BasePort, std::filesystem::path DataDir) { + ZEN_UNUSED(DataDir); ZEN_ASSERT(!m_IsInitialized); int EffectivePort = 0; for (auto& Server : m_Servers) { - const int InitializeResult = Server->Initialize(BasePort); + const int InitializeResult = Server->Initialize(BasePort, DataDir); if (!EffectivePort) { diff --git a/src/zenhttp/servers/httpmulti.h b/src/zenhttp/servers/httpmulti.h index d5b21d3c3..53cf57568 100644 --- a/src/zenhttp/servers/httpmulti.h +++ b/src/zenhttp/servers/httpmulti.h @@ -16,7 +16,7 @@ public: ~HttpMultiServer(); virtual void RegisterService(HttpService& Service) override; - virtual int Initialize(int BasePort) override; + virtual int Initialize(int BasePort, std::filesystem::path DataDir) override; virtual void Run(bool IsInteractiveSession) override; virtual void RequestExit() override; virtual void Close() override; diff --git a/src/zenhttp/servers/httpnull.cpp b/src/zenhttp/servers/httpnull.cpp index 7d3e9079a..9ac1c61ce 100644 --- a/src/zenhttp/servers/httpnull.cpp +++ b/src/zenhttp/servers/httpnull.cpp @@ -25,8 +25,9 @@ HttpNullServer::RegisterService(HttpService& Service) } int -HttpNullServer::Initialize(int BasePort) +HttpNullServer::Initialize(int BasePort, std::filesystem::path DataDir) { + ZEN_UNUSED(DataDir); return BasePort; } diff --git a/src/zenhttp/servers/httpnull.h b/src/zenhttp/servers/httpnull.h index 965e729f7..818020604 100644 --- a/src/zenhttp/servers/httpnull.h +++ b/src/zenhttp/servers/httpnull.h @@ -18,7 +18,7 @@ public: ~HttpNullServer(); virtual void RegisterService(HttpService& Service) override; - virtual int Initialize(int BasePort) override; + virtual int Initialize(int BasePort, std::filesystem::path DataDir) override; virtual void Run(bool IsInteractiveSession) override; virtual void RequestExit() override; virtual void Close() override; diff --git a/src/zenhttp/servers/httpplugin.cpp b/src/zenhttp/servers/httpplugin.cpp index 4ae7cd87a..8795fbcaa 100644 --- a/src/zenhttp/servers/httpplugin.cpp +++ b/src/zenhttp/servers/httpplugin.cpp @@ -7,7 +7,11 @@ # include "httpparser.h" # include <zencore/except.h> +# include <zencore/filesystem.h> +# include <zencore/fmtutils.h> # include <zencore/logging.h> +# include <zencore/scopeguard.h> +# include <zencore/session.h> # include <zencore/thread.h> # include <zencore/trace.h> # include <zenhttp/httpserver.h> @@ -15,6 +19,8 @@ # include <memory> # include <string_view> +# include <fmt/format.h> + # if ZEN_PLATFORM_WINDOWS # include <conio.h> # endif @@ -38,17 +44,21 @@ using namespace std::literals; struct HttpPluginConnectionHandler : public TransportServerConnection, public HttpRequestParserCallbacks, RefCounted { + HttpPluginConnectionHandler(); + ~HttpPluginConnectionHandler(); + + // TransportServerConnection + virtual uint32_t AddRef() const override; virtual uint32_t Release() const override; - - virtual void OnBytesRead(const void* Buffer, size_t DataSize) override; + virtual void OnBytesRead(const void* Buffer, size_t DataSize) override; // HttpRequestParserCallbacks virtual void HandleRequest() override; virtual void TerminateConnection() override; - void Initialize(TransportConnection* Transport, HttpPluginServerImpl& Server); + void Initialize(TransportConnection* Transport, HttpPluginServerImpl& Server, uint32_t ConnectionId); private: enum class RequestState @@ -65,7 +75,8 @@ private: RequestState m_RequestState = RequestState::kInitialState; HttpRequestParser m_RequestParser{*this}; - uint32_t m_ConnectionId = 0; + uint32_t m_ConnectionId = 0; + std::atomic_uint32_t m_RequestCounter = 0; Ref<IHttpPackageHandler> m_PackageHandler; TransportConnection* m_TransportConnection = nullptr; @@ -82,7 +93,7 @@ struct HttpPluginServerImpl : public HttpPluginServer, TransportServer // HttpPluginServer virtual void RegisterService(HttpService& Service) override; - virtual int Initialize(int BasePort) override; + virtual int Initialize(int BasePort, std::filesystem::path DataDir) override; virtual void Run(bool IsInteractiveSession) override; virtual void RequestExit() override; virtual void Close() override; @@ -92,6 +103,8 @@ struct HttpPluginServerImpl : public HttpPluginServer, TransportServer HttpService* RouteRequest(std::string_view Url); + void WriteDebugPayload(std::string_view Filename, const std::span<const IoBuffer> Payload); + struct ServiceEntry { std::string ServiceUrlPath; @@ -103,6 +116,11 @@ struct HttpPluginServerImpl : public HttpPluginServer, TransportServer std::vector<ServiceEntry> m_UriHandlers; std::vector<Ref<TransportPlugin>> m_Plugins; Event m_ShutdownEvent; + bool m_IsRequestLoggingEnabled = false; + LoggerRef m_RequestLog; + std::atomic_uint32_t m_ConnectionIdCounter{0}; + std::filesystem::path m_DataDir; // Application data directory + std::filesystem::path m_PayloadDir; // Request debugging payload directory // TransportServer @@ -147,14 +165,20 @@ public: HttpPluginResponse() = default; explicit HttpPluginResponse(HttpContentType ContentType) : m_ContentType(ContentType) {} + HttpPluginResponse(const HttpPluginResponse&) = delete; + HttpPluginResponse& operator=(const HttpPluginResponse&) = delete; + void InitializeForPayload(uint16_t ResponseCode, std::span<IoBuffer> BlobList); - inline uint16_t ResponseCode() const { return m_ResponseCode; } - inline uint64_t ContentLength() const { return m_ContentLength; } + inline uint16_t ResponseCode() const { return m_ResponseCode; } + inline uint64_t ContentLength() const { return m_ContentLength; } + inline HttpContentType ContentType() const { return m_ContentType; } const std::vector<IoBuffer>& ResponseBuffers() const { return m_ResponseBuffers; } void SuppressPayload() { m_ResponseBuffers.resize(1); } + std::string_view GetHeaders(); + private: uint16_t m_ResponseCode = 0; bool m_IsKeepAlive = true; @@ -162,8 +186,6 @@ private: uint64_t m_ContentLength = 0; std::vector<IoBuffer> m_ResponseBuffers; ExtendableStringBuilder<160> m_Headers; - - std::string_view GetHeaders(); }; void @@ -210,27 +232,55 @@ HttpPluginResponse::InitializeForPayload(uint16_t ResponseCode, std::span<IoBuff std::string_view HttpPluginResponse::GetHeaders() { - m_Headers << "HTTP/1.1 " << ResponseCode() << " " << ReasonStringForHttpResultCode(ResponseCode()) << "\r\n" - << "Content-Type: " << MapContentTypeToString(m_ContentType) << "\r\n" - << "Content-Length: " << ContentLength() << "\r\n"sv; - - if (!m_IsKeepAlive) + if (m_Headers.Size() == 0) { - m_Headers << "Connection: close\r\n"sv; - } + m_Headers << "HTTP/1.1 " << ResponseCode() << " " << ReasonStringForHttpResultCode(ResponseCode()) << "\r\n" + << "Content-Type: " << MapContentTypeToString(m_ContentType) << "\r\n" + << "Content-Length: " << ContentLength() << "\r\n"sv; + + if (!m_IsKeepAlive) + { + m_Headers << "Connection: close\r\n"sv; + } - m_Headers << "\r\n"sv; + m_Headers << "\r\n"sv; + } return m_Headers; } ////////////////////////////////////////////////////////////////////////// +HttpPluginConnectionHandler::HttpPluginConnectionHandler() +{ +} + +HttpPluginConnectionHandler::~HttpPluginConnectionHandler() +{ + if (m_Server) + { + ZEN_LOG_TRACE(m_Server->m_RequestLog, "END connection #{}", m_ConnectionId); + } +} + void -HttpPluginConnectionHandler::Initialize(TransportConnection* Transport, HttpPluginServerImpl& Server) +HttpPluginConnectionHandler::Initialize(TransportConnection* Transport, HttpPluginServerImpl& Server, uint32_t ConnectionId) { m_TransportConnection = Transport; m_Server = &Server; + m_ConnectionId = ConnectionId; + + std::string_view ConnectionName; + if (const char* Name = Transport->GetDebugName()) + { + ConnectionName = Name; + } + else + { + ConnectionName = "anonymous"; + } + + ZEN_LOG_TRACE(m_Server->m_RequestLog, "NEW connection #{} ('')", m_ConnectionId, ConnectionName); } uint32_t @@ -248,13 +298,19 @@ HttpPluginConnectionHandler::Release() const void HttpPluginConnectionHandler::OnBytesRead(const void* Buffer, size_t AvailableBytes) { + ZEN_ASSERT(m_Server); + + ZEN_LOG_TRACE(m_Server->m_RequestLog, "connection #{} OnBytesRead: {}", m_ConnectionId, AvailableBytes); + while (AvailableBytes) { const size_t ConsumedBytes = m_RequestParser.ConsumeData((const char*)Buffer, AvailableBytes); if (ConsumedBytes == ~0ull) { - // terminate connection + // request parser error -- terminate connection + + ZEN_LOG_TRACE(m_Server->m_RequestLog, "connection #{} terminating due to request parsing error", m_ConnectionId); return TerminateConnection(); } @@ -269,15 +325,21 @@ HttpPluginConnectionHandler::OnBytesRead(const void* Buffer, size_t AvailableByt void HttpPluginConnectionHandler::HandleRequest() { + ZEN_ASSERT(m_Server); + + const uint32_t RequestNumber = m_RequestCounter.fetch_add(1); + + ZEN_LOG_TRACE(m_Server->m_RequestLog, "connection #{} ENTER HandleRequest #{}", m_ConnectionId, RequestNumber); + auto $Exit = + MakeGuard([&] { ZEN_LOG_TRACE(m_Server->m_RequestLog, "connection #{} EXIT HandleRequest #{}", m_ConnectionId, RequestNumber); }); + if (!m_RequestParser.IsKeepAlive()) { // Once response has been written, connection is done m_RequestState = RequestState::kWritingFinal; - // We're not going to read any more data from this socket - - const bool Receive = true; - const bool Transmit = false; + const bool Receive = true; // We're not going to read any more data from this socket + const bool Transmit = false; // We will write more data however m_TransportConnection->Shutdown(Receive, Transmit); } else @@ -300,6 +362,23 @@ HttpPluginConnectionHandler::HandleRequest() HttpPluginServerRequest Request(m_RequestParser, *Service, m_RequestParser.Body()); + const HttpVerb RequestVerb = Request.RequestVerb(); + const std::string_view Uri = Request.RelativeUri(); + + { + ZEN_LOG_TRACE(m_Server->m_RequestLog, + "connection #{} Handling Request: {} {} ({} bytes ({}), accept: {})", + m_ConnectionId, + ToString(RequestVerb), + Uri, + Request.ContentLength(), + ToString(Request.RequestContentType()), + ToString(Request.AcceptContentType())); + + m_Server->WriteDebugPayload(fmt::format("request_{}_{}.bin", m_ConnectionId, RequestNumber), + std::vector<IoBuffer>{Request.ReadPayload()}); + } + if (!HandlePackageOffers(*Service, Request, m_PackageHandler)) { try @@ -340,6 +419,17 @@ HttpPluginConnectionHandler::HandleRequest() if (std::unique_ptr<HttpPluginResponse> Response = std::move(Request.m_Response)) { + { + const uint16_t ResponseCode = Response->ResponseCode(); + ZEN_LOG_TRACE(m_Server->m_RequestLog, + "connection #{} Response: {} {} ({} bytes, {})", + m_ConnectionId, + ResponseCode, + ToString(HttpResponseCode(ResponseCode)), + Response->ContentLength(), + ToString(Response->ContentType())); + } + // Transmit the response if (m_RequestParser.RequestVerb() == HttpVerb::kHead) @@ -349,10 +439,16 @@ HttpPluginConnectionHandler::HandleRequest() const std::vector<IoBuffer>& ResponseBuffers = Response->ResponseBuffers(); - //// TODO: should cork/uncork for Linux? + m_Server->WriteDebugPayload(fmt::format("response_{}_{}.bin", m_ConnectionId, RequestNumber), ResponseBuffers); for (const IoBuffer& Buffer : ResponseBuffers) { + ZEN_LOG_TRACE(m_Server->m_RequestLog, + "connection #{} SEND: {} bytes, {}", + m_ConnectionId, + Buffer.GetSize(), + ToString(Buffer.GetContentType())); + int64_t SentBytes = SendBuffer(Buffer); if (SentBytes < 0) @@ -558,8 +654,9 @@ HttpPluginServerRequest::TryGetRanges(HttpRanges& Ranges) ////////////////////////////////////////////////////////////////////////// -HttpPluginServerImpl::HttpPluginServerImpl() +HttpPluginServerImpl::HttpPluginServerImpl() : m_RequestLog(logging::Get("http_requests")) { + m_RequestLog.SetLogLevel(logging::level::Trace); } HttpPluginServerImpl::~HttpPluginServerImpl() @@ -570,13 +667,19 @@ TransportServerConnection* HttpPluginServerImpl::CreateConnectionHandler(TransportConnection* Connection) { HttpPluginConnectionHandler* Handler{new HttpPluginConnectionHandler()}; - Handler->Initialize(Connection, *this); + const uint32_t ConnectionId = m_ConnectionIdCounter.fetch_add(1); + Handler->Initialize(Connection, *this, ConnectionId); return Handler; } int -HttpPluginServerImpl::Initialize(int BasePort) +HttpPluginServerImpl::Initialize(int BasePort, std::filesystem::path DataDir) { + m_DataDir = DataDir; + m_PayloadDir = DataDir / "debug" / GetSessionIdString(); + + ZEN_INFO("any debug payloads will be written to '{}'", m_PayloadDir); + try { RwLock::ExclusiveLockScope _(m_Lock); @@ -742,6 +845,18 @@ HttpPluginServerImpl::RouteRequest(std::string_view Url) return CandidateService; } +void +HttpPluginServerImpl::WriteDebugPayload(std::string_view Filename, const std::span<const IoBuffer> Payload) +{ + std::vector<const IoBuffer*> Buffers; + for (auto& Io : Payload) + { + Buffers.push_back(&Io); + } + + WriteFile(m_PayloadDir / Filename, Buffers.data(), Buffers.size()); +} + ////////////////////////////////////////////////////////////////////////// struct HttpPluginServerImpl; diff --git a/src/zenhttp/servers/httpsys.cpp b/src/zenhttp/servers/httpsys.cpp index 0b11d396b..d2cb63cd7 100644 --- a/src/zenhttp/servers/httpsys.cpp +++ b/src/zenhttp/servers/httpsys.cpp @@ -43,7 +43,7 @@ public: // HttpServer interface implementation - virtual int Initialize(int BasePort) override; + virtual int Initialize(int BasePort, std::filesystem::path DataDir) override; virtual void Run(bool TestMode) override; virtual void RequestExit() override; virtual void RegisterService(HttpService& Service) override; @@ -2012,8 +2012,9 @@ InitialRequestHandler::HandleCompletion(ULONG IoResult, ULONG_PTR NumberOfBytesT // int -HttpSysServer::Initialize(int BasePort) +HttpSysServer::Initialize(int BasePort, std::filesystem::path DataDir) { + ZEN_UNUSED(DataDir); if (int EffectivePort = InitializeServer(BasePort)) { StartServer(); diff --git a/src/zenhttp/transports/asiotransport.cpp b/src/zenhttp/transports/asiotransport.cpp index ab053a748..a9a782821 100644 --- a/src/zenhttp/transports/asiotransport.cpp +++ b/src/zenhttp/transports/asiotransport.cpp @@ -34,12 +34,13 @@ public: AsioTransportPlugin(); ~AsioTransportPlugin(); - virtual uint32_t AddRef() const override; - virtual uint32_t Release() const override; - virtual void Configure(const char* OptionTag, const char* OptionValue) override; - virtual void Initialize(TransportServer* ServerInterface) override; - virtual void Shutdown() override; - virtual bool IsAvailable() override; + virtual uint32_t AddRef() const override; + virtual uint32_t Release() const override; + virtual void Configure(const char* OptionTag, const char* OptionValue) override; + virtual void Initialize(TransportServer* ServerInterface) override; + virtual void Shutdown() override; + virtual const char* GetDebugName() override { return nullptr; } + virtual bool IsAvailable() override; private: bool m_IsOk = true; @@ -63,9 +64,10 @@ struct AsioTransportConnection : public TransportConnection, std::enable_shared_ // TransportConnectionInterface - virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; - virtual void Shutdown(bool Receive, bool Transmit) override; - virtual void CloseConnection() override; + virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; + virtual void Shutdown(bool Receive, bool Transmit) override; + virtual void CloseConnection() override; + virtual const char* GetDebugName() override { return nullptr; } private: void EnqueueRead(); diff --git a/src/zenhttp/transports/dlltransport.cpp b/src/zenhttp/transports/dlltransport.cpp index dd4479e39..e09e62ec5 100644 --- a/src/zenhttp/transports/dlltransport.cpp +++ b/src/zenhttp/transports/dlltransport.cpp @@ -19,69 +19,6 @@ ZEN_THIRD_PARTY_INCLUDES_END namespace zen { -struct DllTransportConnection : public TransportConnection -{ -public: - DllTransportConnection(); - ~DllTransportConnection(); - - void Initialize(TransportServerConnection& ServerConnection); - void HandleConnection(); - - // TransportConnection - - virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; - virtual void Shutdown(bool Receive, bool Transmit) override; - virtual void CloseConnection() override; - -private: - Ref<TransportServerConnection> m_ConnectionHandler; - bool m_IsTerminated = false; -}; - -DllTransportConnection::DllTransportConnection() -{ -} - -DllTransportConnection::~DllTransportConnection() -{ -} - -void -DllTransportConnection::Initialize(TransportServerConnection& ServerConnection) -{ - m_ConnectionHandler = &ServerConnection; // TODO: this is awkward -} - -void -DllTransportConnection::HandleConnection() -{ -} - -void -DllTransportConnection::CloseConnection() -{ - if (m_IsTerminated) - { - return; - } - - m_IsTerminated = true; -} - -int64_t -DllTransportConnection::WriteBytes(const void* Buffer, size_t DataSize) -{ - ZEN_UNUSED(Buffer, DataSize); - return DataSize; -} - -void -DllTransportConnection::Shutdown(bool Receive, bool Transmit) -{ - ZEN_UNUSED(Receive, Transmit); -} - ////////////////////////////////////////////////////////////////////////// struct LoadedDll @@ -97,12 +34,13 @@ public: DllTransportPluginImpl(); ~DllTransportPluginImpl(); - virtual uint32_t AddRef() const override; - virtual uint32_t Release() const override; - virtual void Configure(const char* OptionTag, const char* OptionValue) override; - virtual void Initialize(TransportServer* ServerInterface) override; - virtual void Shutdown() override; - virtual bool IsAvailable() override; + virtual uint32_t AddRef() const override; + virtual uint32_t Release() const override; + virtual void Configure(const char* OptionTag, const char* OptionValue) override; + virtual void Initialize(TransportServer* ServerInterface) override; + virtual void Shutdown() override; + virtual const char* GetDebugName() override; + virtual bool IsAvailable() override; virtual void LoadDll(std::string_view Name) override; virtual void ConfigureDll(std::string_view Name, const char* OptionTag, const char* OptionValue) override; @@ -179,6 +117,12 @@ DllTransportPluginImpl::Shutdown() } } +const char* +DllTransportPluginImpl::GetDebugName() +{ + return nullptr; +} + bool DllTransportPluginImpl::IsAvailable() { diff --git a/src/zenhttp/transports/winsocktransport.cpp b/src/zenhttp/transports/winsocktransport.cpp index 2397dd7cf..7407c55dd 100644 --- a/src/zenhttp/transports/winsocktransport.cpp +++ b/src/zenhttp/transports/winsocktransport.cpp @@ -31,9 +31,10 @@ public: // TransportConnection - virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; - virtual void Shutdown(bool Receive, bool Transmit) override; - virtual void CloseConnection() override; + virtual int64_t WriteBytes(const void* Buffer, size_t DataSize) override; + virtual void Shutdown(bool Receive, bool Transmit) override; + virtual void CloseConnection() override; + virtual const char* GetDebugName() override; private: Ref<TransportServerConnection> m_ConnectionHandler; @@ -103,6 +104,12 @@ SocketTransportConnection::CloseConnection() m_ClientSocket = 0; } +const char* +SocketTransportConnection::GetDebugName() +{ + return nullptr; +} + int64_t SocketTransportConnection::WriteBytes(const void* Buffer, size_t DataSize) { @@ -157,12 +164,13 @@ public: SocketTransportPluginImpl(); ~SocketTransportPluginImpl(); - virtual uint32_t AddRef() const override; - virtual uint32_t Release() const override; - virtual void Configure(const char* OptionTag, const char* OptionValue) override; - virtual void Initialize(TransportServer* ServerInterface) override; - virtual void Shutdown() override; - virtual bool IsAvailable() override; + virtual uint32_t AddRef() const override; + virtual uint32_t Release() const override; + virtual void Configure(const char* OptionTag, const char* OptionValue) override; + virtual void Initialize(TransportServer* ServerInterface) override; + virtual void Shutdown() override; + virtual const char* GetDebugName() override; + virtual bool IsAvailable() override; private: TransportServer* m_ServerInterface = nullptr; @@ -337,6 +345,12 @@ SocketTransportPluginImpl::Shutdown() } } +const char* +SocketTransportPluginImpl::GetDebugName() +{ + return nullptr; +} + ////////////////////////////////////////////////////////////////////////// TransportPlugin* diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index fafbe8304..2aeb6a4d5 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -162,7 +162,7 @@ ZenServer::Initialize(const ZenServerOptions& ServerOptions, ZenServerState::Zen // Ok so now we're configured, let's kick things off m_Http = CreateHttpServer(ServerOptions.HttpServerConfig); - int EffectiveBasePort = m_Http->Initialize(ServerOptions.BasePort); + int EffectiveBasePort = m_Http->Initialize(ServerOptions.BasePort, ServerOptions.DataDir); // Setup authentication manager { |