diff options
| author | Stefan Boberg <[email protected]> | 2026-02-26 15:26:45 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2026-02-26 15:26:45 +0100 |
| commit | 2425d71ea3629b52925d0bb6fccc1736b4b86204 (patch) | |
| tree | 23abef427307045ad20e74d1e14834c474f06289 /src/zenhttp/servers/httpsys.cpp | |
| parent | removed spurious printf in PathBuilder test (diff) | |
| download | zen-2425d71ea3629b52925d0bb6fccc1736b4b86204.tar.xz zen-2425d71ea3629b52925d0bb6fccc1736b4b86204.zip | |
httpsys websocket using IOCP instead of thread-per-connection
Diffstat (limited to 'src/zenhttp/servers/httpsys.cpp')
| -rw-r--r-- | src/zenhttp/servers/httpsys.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/zenhttp/servers/httpsys.cpp b/src/zenhttp/servers/httpsys.cpp index 0b33bc39c..89d93e258 100644 --- a/src/zenhttp/servers/httpsys.cpp +++ b/src/zenhttp/servers/httpsys.cpp @@ -156,6 +156,7 @@ private: #if ZEN_WITH_HTTPSYS +# include "httpsys_iocontext.h" # include "wshttpsys.h" # include "wsframecodec.h" @@ -385,7 +386,7 @@ public: PTP_IO Iocp(); HANDLE RequestQueueHandle(); - inline OVERLAPPED* Overlapped() { return &m_HttpOverlapped; } + inline OVERLAPPED* Overlapped() { return &m_IoContext.Overlapped; } inline HttpSysServer& Server() { return m_HttpServer; } inline HTTP_REQUEST* HttpRequest() { return m_InitialHttpHandler.HttpRequest(); } @@ -402,8 +403,8 @@ public: }; private: - OVERLAPPED m_HttpOverlapped{}; - HttpSysServer& m_HttpServer; + HttpSysIoContext m_IoContext{}; + HttpSysServer& m_HttpServer; // Tracks which handler is due to handle the next I/O completion event HttpSysRequestHandler* m_CompletionHandler = nullptr; @@ -1560,7 +1561,23 @@ HttpSysTransaction::IoCompletionCallback(PTP_CALLBACK_INSTANCE Instance, // than one thread at any given moment. This means we need to be careful about what // happens in here - HttpSysTransaction* Transaction = CONTAINING_RECORD(pOverlapped, HttpSysTransaction, m_HttpOverlapped); + HttpSysIoContext* IoContext = CONTAINING_RECORD(pOverlapped, HttpSysIoContext, Overlapped); + + switch (IoContext->ContextType) + { + case HttpSysIoContext::Type::kWebSocketRead: + static_cast<WsHttpSysConnection*>(IoContext->Owner)->OnReadCompletion(IoResult, NumberOfBytesTransferred); + return; + + case HttpSysIoContext::Type::kWebSocketWrite: + static_cast<WsHttpSysConnection*>(IoContext->Owner)->OnWriteCompletion(IoResult, NumberOfBytesTransferred); + return; + + case HttpSysIoContext::Type::kTransaction: + break; + } + + HttpSysTransaction* Transaction = CONTAINING_RECORD(IoContext, HttpSysTransaction, m_IoContext); if (Transaction->HandleCompletion(IoResult, NumberOfBytesTransferred) == HttpSysTransaction::Status::kDone) { @@ -2344,7 +2361,8 @@ InitialRequestHandler::HandleCompletion(ULONG IoResult, ULONG_PTR NumberOfBytesT WebSocketEndServerHandshake(WsHandle); WebSocketDeleteHandle(WsHandle); - Ref<WsHttpSysConnection> WsConn(new WsHttpSysConnection(RequestQueueHandle, RequestId, *WsHandler)); + Ref<WsHttpSysConnection> WsConn( + new WsHttpSysConnection(RequestQueueHandle, RequestId, *WsHandler, Transaction().Iocp())); Ref<WebSocketConnection> WsConnRef(WsConn.Get()); WsHandler->OnWebSocketOpen(std::move(WsConnRef)); |