blob: b4ec54b396b4a9d98787cc68c86ddc287ba5e381 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
|