aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-10-11 14:59:25 +0200
committerGitHub <[email protected]>2023-10-11 14:59:25 +0200
commit11f7f70b825c5b6784f5e2609463a1a9d1a0dabc (patch)
tree98f65537f52327c354193afa98a29f9f838b42ff /src/plugins
parenthide HttpAsioServer interface behind factory function (#463) (diff)
downloadzen-11f7f70b825c5b6784f5e2609463a1a9d1a0dabc.tar.xz
zen-11f7f70b825c5b6784f5e2609463a1a9d1a0dabc.zip
pluggable asio transport (#460)
added pluggable transport based on asio. This is in an experimental state and is not yet a replacement for httpasio even though that is the ultimate goal also moved plugin API header into dedicated part of the tree to clarify that it is meant to be usable in isolation, without any dependency on zencore et al moved transport implementations into dedicated source directory in zenhttp note that this adds code to the build but nothing should change at runtime since the instantiation of the new code is conditional and is inactive by default
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/include/transportplugin.h111
-rw-r--r--src/plugins/winsock/winsock.cpp2
-rw-r--r--src/plugins/winsock/xmake.lua10
-rw-r--r--src/plugins/xmake.lua7
4 files changed, 123 insertions, 7 deletions
diff --git a/src/plugins/include/transportplugin.h b/src/plugins/include/transportplugin.h
new file mode 100644
index 000000000..aee5b2e7a
--- /dev/null
+++ b/src/plugins/include/transportplugin.h
@@ -0,0 +1,111 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include <stdint.h>
+
+// Important note: this header is meant to compile standalone
+// and should therefore not depend on anything from the Zen codebase
+
+namespace zen {
+
+class TransportConnection;
+class TransportPlugin;
+class TransportServerConnection;
+class TransportServer;
+
+/*************************************************************************
+
+ The following interfaces are implemented on the server side, and instances
+ are provided to the plugins.
+
+*************************************************************************/
+
+/** Plugin-server interface for connection
+
+ This is returned by a call to TransportServer::CreateConnectionHandler
+ and there should be one instance created per established connection
+
+ The plugin uses this interface to feed data into the server side
+ protocol implementation which will parse the incoming messages and
+ dispatch to appropriate request handlers and ultimately call into
+ TransportConnection functions which write data back to the client
+ */
+class TransportServerConnection
+{
+public:
+ virtual uint32_t AddRef() const = 0;
+ virtual uint32_t Release() const = 0;
+ virtual void OnBytesRead(const void* Buffer, size_t DataSize) = 0;
+};
+
+/** Server interface
+
+ There will be one instance of this provided by the system to the transport plugin
+
+ The plugin can use this to register new connections
+
+ */
+class TransportServer
+{
+public:
+ virtual TransportServerConnection* CreateConnectionHandler(TransportConnection* Connection) = 0;
+};
+
+/*************************************************************************
+
+ The following interfaces are to be implemented by transport plugins.
+
+*************************************************************************/
+
+/** Interface which needs to be implemented by a transport plugin
+
+ This is responsible for setting up and running the communication
+ for a given transport.
+
+ Once initialized, the plugin should be ready to accept connections
+ using its own execution resources (threads, thread pools etc)
+ */
+class TransportPlugin
+{
+public:
+ virtual uint32_t AddRef() const = 0;
+ virtual uint32_t Release() const = 0;
+ virtual void Initialize(TransportServer* ServerInterface) = 0;
+ virtual void Shutdown() = 0;
+
+ /** Check whether this transport is usable.
+ */
+ virtual bool IsAvailable() = 0;
+};
+
+/** A transport plugin provider needs to implement this interface
+
+ The plugin should create one instance of this per established
+ connection and register it with the TransportServer instance
+ CreateConnectionHandler() function. The server will subsequently
+ use this interface to write response data back to the client and
+ to manage the connection life cycle in general
+*/
+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;
+};
+
+} // namespace zen
+
+#if defined(_MSC_VER)
+# define DLL_TRANSPORT_API __declspec(dllexport)
+#else
+# define DLL_TRANSPORT_API
+#endif
+
+extern "C"
+{
+ DLL_TRANSPORT_API zen::TransportPlugin* CreateTransportPlugin();
+}
+
+typedef zen::TransportPlugin* (*PfnCreateTransportPlugin)();
diff --git a/src/plugins/winsock/winsock.cpp b/src/plugins/winsock/winsock.cpp
index 3ee3f0ccd..a6cfed1e3 100644
--- a/src/plugins/winsock/winsock.cpp
+++ b/src/plugins/winsock/winsock.cpp
@@ -24,6 +24,8 @@ ZEN_THIRD_PARTY_INCLUDES_END
//////////////////////////////////////////////////////////////////////////
+using namespace zen;
+
class SocketTransportPlugin : public TransportPlugin, zen::RefCounted
{
public:
diff --git a/src/plugins/winsock/xmake.lua b/src/plugins/winsock/xmake.lua
index a4ef02a98..408a248b1 100644
--- a/src/plugins/winsock/xmake.lua
+++ b/src/plugins/winsock/xmake.lua
@@ -4,15 +4,11 @@ target("winsock")
set_kind("shared")
add_headerfiles("**.h")
add_files("**.cpp")
- add_includedirs(".", "../../zenhttp/include/zenhttp", "../../zencore/include")
+ add_links("Ws2_32")
+ add_includedirs(".", "../../zencore/include")
set_symbols("debug")
-
- add_cxxflags("/showIncludes")
+ add_deps("plugins")
if is_mode("release") then
set_optimize("fastest")
end
-
- if is_plat("windows") then
- add_links("Ws2_32")
- end
diff --git a/src/plugins/xmake.lua b/src/plugins/xmake.lua
new file mode 100644
index 000000000..9e4d49685
--- /dev/null
+++ b/src/plugins/xmake.lua
@@ -0,0 +1,7 @@
+-- Copyright Epic Games, Inc. All Rights Reserved.
+
+target('plugins')
+ set_kind("headeronly")
+ set_group("plugins")
+ add_headerfiles("**.h")
+ add_includedirs("include", {public=true})