summaryrefslogtreecommitdiffhomepage
path: root/plugins/fcgi/socket.h
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/fcgi/socket.h')
-rw-r--r--plugins/fcgi/socket.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/plugins/fcgi/socket.h b/plugins/fcgi/socket.h
new file mode 100644
index 0000000..b4ec54b
--- /dev/null
+++ b/plugins/fcgi/socket.h
@@ -0,0 +1,70 @@
+#pragma once
+
+#include "fcgiid.h"
+
+#include <boost/asio.hpp>
+
+#include <cstdint>
+#include <mutex>
+#include <set>
+#include <string>
+
+class fcgi_eof_error: public std::runtime_error
+{
+public:
+ fcgi_eof_error(const std::string& what_arg): std::runtime_error(what_arg) {}
+};
+
+class Socket
+{
+ std::mutex m_mutex; // guard socket use in different threads
+ FCGI_ID m_fcgi_id;
+
+public:
+ virtual ~Socket() {}
+
+ std::mutex& getMutex();
+
+ FCGI_ID& fcgi_id();
+
+ virtual void open() = 0;
+ virtual void close() = 0;
+ virtual bool is_open() = 0;
+ virtual size_t write(const std::vector<char>& data) = 0;
+ virtual size_t read(std::vector<char>& data) = 0;
+};
+
+class SocketFactory
+{
+ boost::asio::io_context m_io_context;
+
+public:
+ SocketFactory();
+ std::shared_ptr<Socket> create(const std::string& name);
+};
+
+class TCPSocket: public Socket
+{
+ boost::asio::io_context& m_io_context;
+ std::string m_host;
+ std::string m_port;
+ boost::asio::ip::tcp::socket m_socket;
+
+public:
+ TCPSocket(const std::string& host, const std::string& port, boost::asio::io_context& io_context);
+ ~TCPSocket() override;
+
+ void open() override;
+ void close() override;
+ bool is_open() override;
+ size_t write(const std::vector<char>& data) override;
+ size_t read(std::vector<char>& data) override;
+};
+
+#if 0
+class FileSocket: public Socket
+{
+ ~FileSocket() override;
+};
+#endif
+