forked from solidoss/solidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipcconfiguration.hpp
249 lines (190 loc) · 6.98 KB
/
ipcconfiguration.hpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
// solid/frame/ipc/ipcconfiguration.hpp
//
// Copyright (c) 2015 Valentin Palade (vipalade @ gmail . com)
//
// This file is part of SolidFrame framework.
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.
//
#ifndef SOLID_FRAME_IPC_IPCCONFIGURATION_HPP
#define SOLID_FRAME_IPC_IPCCONFIGURATION_HPP
#include <vector>
#include "solid/system/function.hpp"
#include "solid/system/socketaddress.hpp"
#include "solid/frame/ipc/ipcmessage.hpp"
#include "solid/frame/aio/aioreactor.hpp"
#include "solid/frame/aio/openssl/aiosecurecontext.hpp"
#include "solid/frame/aio/aioreactorcontext.hpp"
#include "solid/frame/scheduler.hpp"
#include "solid/frame/ipc/ipcprotocol.hpp"
namespace solid{
namespace frame{
namespace aio{
class Resolver;
}
namespace ipc{
class Service;
class MessageWriter;
struct ConnectionContext;
using AddressVectorT = std::vector<SocketAddressInet>;
using ResolveCompleteFunctionT = FUNCTION<void(AddressVectorT &&)>;
using AsyncResolveFunctionT = FUNCTION<void(const std::string&, ResolveCompleteFunctionT&)>;
using ConnectionStopFunctionT = FUNCTION<void(ConnectionContext &)>;
using ConnectionStartFunctionT = FUNCTION<void(ConnectionContext &)>;
using AllocateBufferFunctionT = FUNCTION<char*(const uint16_t)>;
using FreeBufferFunctionT = FUNCTION<void(char*)>;
using CompressFunctionT = FUNCTION<size_t(char*, size_t, ErrorConditionT &)>;
using UncompressFunctionT = FUNCTION<size_t(char*, const char*, size_t, ErrorConditionT &)>;
//using ResetSerializerLimitsFunctionT = FUNCTION<void(ConnectionContext &, serialization::binary::Limits&)>;
using SecureContextT = frame::aio::openssl::Context;
using AioSchedulerT = frame::Scheduler<frame::aio::Reactor>;
using ConnectionEnterActiveCompleteFunctionT = FUNCTION<MessagePointerT(ConnectionContext&, ErrorConditionT const&)>;
using ConnectionEnterPassiveCompleteFunctionT = FUNCTION<void(ConnectionContext&, ErrorConditionT const&)>;
using ConnectionSecureHandhakeCompleteFunctionT = FUNCTION<void(ConnectionContext&, ErrorConditionT const&)>;
using ConnectionSendRawDataCompleteFunctionT = FUNCTION<void(ConnectionContext&, ErrorConditionT const&)>;
using ConnectionRecvRawDataCompleteFunctionT = FUNCTION<void(ConnectionContext&, const char*, size_t&, ErrorConditionT const&)>;
using ConnectionOnEventFunctionT = FUNCTION<void(ConnectionContext&, Event&)>;
enum struct ConnectionState{
Raw,
Passive,
Active
};
struct ReaderConfiguration{
ReaderConfiguration();
size_t max_message_count_multiplex;
UncompressFunctionT decompress_fnc;
};
struct WriterConfiguration{
WriterConfiguration();
size_t max_message_count_multiplex;
size_t max_message_count_response_wait;
size_t max_message_continuous_packet_count;
CompressFunctionT inplace_compress_fnc;
//ResetSerializerLimitsFunctionT reset_serializer_limits_fnc;
};
struct Configuration{
private:
Configuration& operator=(const Configuration&) = delete;
Configuration& operator=(Configuration&&) = default;
public:
Configuration(
AioSchedulerT &_rsch,
ipc::Protocol *_pproto = nullptr
);
Configuration& reset(Configuration &&_ucfg){
*this = std::move(_ucfg);
prepare();
return *this;
}
AioSchedulerT & scheduler(){
return *pscheduler;
}
bool isServer()const{
return listener_address_str.size() != 0;
}
bool isClient()const{
return not FUNCTION_EMPTY(name_resolve_fnc);
}
bool isServerOnly()const{
return isServer() && !isClient();
}
bool isClientOnly()const{
return !isServer() && isClient();
}
bool hasSecureContext()const{
return secure_context.isValid();
}
int listenerPort()const{
return listener_port;
}
char* allocateRecvBuffer(uint8_t &_rbuffer_capacity_kb)const;
void freeRecvBuffer(char *_pb)const;
char* allocateSendBuffer(uint8_t &_rbuffer_capacity_kb)const;
void freeSendBuffer(char *_pb)const;
size_t connectionReconnectTimeoutSeconds(
const uint8_t _retry_count,
const bool _failed_create_connection_object,
const bool _last_connection_was_connected,
const bool _last_connection_was_active,
const bool _last_connection_was_secured
)const;
ErrorConditionT check() const;
size_t connetionReconnectTimeoutSeconds()const;
size_t pool_max_active_connection_count;
size_t pool_max_pending_connection_count;
size_t pool_max_message_queue_size;
size_t pools_mutex_count;
ReaderConfiguration reader;
WriterConfiguration writer;
size_t connection_reconnect_timeout_seconds;
uint32_t connection_inactivity_timeout_seconds;
uint32_t connection_keepalive_timeout_seconds;
ConnectionState connection_start_state;
bool connection_start_secure;
uint32_t connection_inactivity_keepalive_count; //server error if receives more than inactivity_keepalive_count keep alive
//messages during inactivity_timeout_seconds interval
uint8_t connection_recv_buffer_start_capacity_kb;
uint8_t connection_recv_buffer_max_capacity_kb;
uint8_t connection_send_buffer_start_capacity_kb;
uint8_t connection_send_buffer_max_capacity_kb;
AsyncResolveFunctionT name_resolve_fnc;
ConnectionStartFunctionT connection_start_incoming_fnc;
ConnectionStartFunctionT connection_start_outgoing_fnc;
ConnectionStopFunctionT connection_stop_fnc;
ConnectionOnEventFunctionT connection_on_event_fnc;
AllocateBufferFunctionT connection_recv_buffer_allocate_fnc;
AllocateBufferFunctionT connection_send_buffer_allocate_fnc;
FreeBufferFunctionT connection_recv_buffer_free_fnc;
FreeBufferFunctionT connection_send_buffer_free_fnc;
std::string listener_address_str;
std::string listener_service_str;
SecureContextT secure_context;
ProtocolPointerT protocol_ptr;
Protocol& protocol(){
return *protocol_ptr;
}
const Protocol& protocol()const{
return *protocol_ptr;
}
private:
void prepare();
private:
enum WriterFunctions{
WriterNoCompressE = 0,
WriterCompress01kE,
WriterCompress02kE,
WriterCompress04kE,
WriterCompress08kE,
WriterCompress12kE,
WriterCompress16kE,
WriterCompress20kE,
WriterCompress24kE,
WriterCompress32kE,
WriterCompress36kE,
WriterCompress64kE,
WriterCompress96kE,
};
WriterFunctions writerfunctionidx;
AioSchedulerT *pscheduler;
private:
friend class Service;
//friend class MessageWriter;
Configuration():pscheduler(nullptr){}
int listener_port;
};
struct InternetResolverF{
aio::Resolver &rresolver;
std::string default_service;
SocketInfo::Family family;
InternetResolverF(
aio::Resolver &_rresolver,
const char *_default_service,
SocketInfo::Family _family = SocketInfo::AnyFamily
): rresolver(_rresolver), default_service(_default_service), family(_family){}
void operator()(const std::string&, ResolveCompleteFunctionT&);
};
}//namespace ipc
}//namespace frame
}//namespace solid
#endif