opal-up 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +66 -51
  3. data/ext/up_ext/App.h +665 -544
  4. data/ext/up_ext/AsyncSocket.h +307 -284
  5. data/ext/up_ext/AsyncSocketData.h +35 -51
  6. data/ext/up_ext/BloomFilter.h +37 -42
  7. data/ext/up_ext/ChunkedEncoding.h +174 -175
  8. data/ext/up_ext/ClientApp.h +20 -23
  9. data/ext/up_ext/HttpContext.h +476 -381
  10. data/ext/up_ext/HttpContextData.h +20 -20
  11. data/ext/up_ext/HttpErrors.h +14 -10
  12. data/ext/up_ext/HttpParser.h +631 -563
  13. data/ext/up_ext/HttpResponse.h +526 -460
  14. data/ext/up_ext/HttpResponseData.h +59 -55
  15. data/ext/up_ext/HttpRouter.h +328 -310
  16. data/ext/up_ext/Loop.h +174 -168
  17. data/ext/up_ext/LoopData.h +60 -67
  18. data/ext/up_ext/MoveOnlyFunction.h +71 -80
  19. data/ext/up_ext/PerMessageDeflate.h +218 -198
  20. data/ext/up_ext/ProxyParser.h +100 -99
  21. data/ext/up_ext/QueryParser.h +91 -84
  22. data/ext/up_ext/TopicTree.h +273 -268
  23. data/ext/up_ext/Utilities.h +25 -25
  24. data/ext/up_ext/WebSocket.h +376 -310
  25. data/ext/up_ext/WebSocketContext.h +487 -372
  26. data/ext/up_ext/WebSocketContextData.h +74 -62
  27. data/ext/up_ext/WebSocketData.h +53 -46
  28. data/ext/up_ext/WebSocketExtensions.h +194 -178
  29. data/ext/up_ext/WebSocketHandshake.h +115 -110
  30. data/ext/up_ext/WebSocketProtocol.h +441 -398
  31. data/ext/up_ext/extconf.rb +1 -1
  32. data/ext/up_ext/libuwebsockets.cpp +1262 -1292
  33. data/ext/up_ext/libuwebsockets.h +337 -201
  34. data/ext/up_ext/up_ext.c +853 -163
  35. data/lib/up/bun/rack_env.rb +1 -13
  36. data/lib/up/bun/server.rb +93 -19
  37. data/lib/up/cli.rb +3 -0
  38. data/lib/up/client.rb +68 -0
  39. data/lib/up/ruby/cluster.rb +62 -0
  40. data/lib/up/ruby/rack_cluster.rb +1 -1
  41. data/lib/up/ruby/rack_server.rb +0 -1
  42. data/lib/up/u_web_socket/cluster.rb +18 -3
  43. data/lib/up/u_web_socket/server.rb +108 -15
  44. data/lib/up/version.rb +1 -1
  45. metadata +4 -15
  46. data/bin/up_node +0 -12
  47. data/bin/up_node_cluster +0 -12
  48. data/lib/up/node/cluster.rb +0 -39
  49. data/lib/up/node/cluster_cli.rb +0 -15
  50. data/lib/up/node/rack_cluster.rb +0 -25
  51. data/lib/up/node/rack_env.rb +0 -106
  52. data/lib/up/node/rack_server.rb +0 -25
  53. data/lib/up/node/server.rb +0 -84
  54. data/lib/up/node/server_cli.rb +0 -15
  55. data/lib/up/ruby/rack_env.rb +0 -97
  56. data/lib/up/u_web_socket/rack_env.rb +0 -101
@@ -82,7 +82,7 @@ namespace ofats {
82
82
 
83
83
  namespace any_detail {
84
84
 
85
- using buffer = std::aligned_storage_t<sizeof(void*) * 2, alignof(void*)>;
85
+ using buffer = std::aligned_storage_t<sizeof(void *) * 2, alignof(void *)>;
86
86
 
87
87
  template <class T>
88
88
  inline constexpr bool is_small_object_v =
@@ -90,66 +90,62 @@ inline constexpr bool is_small_object_v =
90
90
  std::is_nothrow_move_constructible_v<T>;
91
91
 
92
92
  union storage {
93
- void* ptr_ = nullptr;
93
+ void *ptr_ = nullptr;
94
94
  buffer buf_;
95
95
  };
96
96
 
97
97
  enum class action { destroy, move };
98
98
 
99
- template <class R, class... ArgTypes>
100
- struct handler_traits {
101
- template <class Derived>
102
- struct handler_base {
103
- static void handle(action act, storage* current, storage* other = nullptr) {
99
+ template <class R, class... ArgTypes> struct handler_traits {
100
+ template <class Derived> struct handler_base {
101
+ static void handle(action act, storage *current, storage *other = nullptr) {
104
102
  switch (act) {
105
- case (action::destroy):
106
- Derived::destroy(*current);
107
- break;
108
- case (action::move):
109
- Derived::move(*current, *other);
110
- break;
103
+ case (action::destroy):
104
+ Derived::destroy(*current);
105
+ break;
106
+ case (action::move):
107
+ Derived::move(*current, *other);
108
+ break;
111
109
  }
112
110
  }
113
111
  };
114
112
 
115
- template <class T>
116
- struct small_handler : handler_base<small_handler<T>> {
117
- template <class... Args>
118
- static void create(storage& s, Args&&... args) {
119
- new (static_cast<void*>(&s.buf_)) T(std::forward<Args>(args)...);
113
+ template <class T> struct small_handler : handler_base<small_handler<T>> {
114
+ template <class... Args> static void create(storage &s, Args &&...args) {
115
+ new (static_cast<void *>(&s.buf_)) T(std::forward<Args>(args)...);
120
116
  }
121
117
 
122
- static void destroy(storage& s) noexcept {
123
- T& value = *static_cast<T*>(static_cast<void*>(&s.buf_));
118
+ static void destroy(storage &s) noexcept {
119
+ T &value = *static_cast<T *>(static_cast<void *>(&s.buf_));
124
120
  value.~T();
125
121
  }
126
122
 
127
- static void move(storage& dst, storage& src) noexcept {
128
- create(dst, std::move(*static_cast<T*>(static_cast<void*>(&src.buf_))));
123
+ static void move(storage &dst, storage &src) noexcept {
124
+ create(dst, std::move(*static_cast<T *>(static_cast<void *>(&src.buf_))));
129
125
  destroy(src);
130
126
  }
131
127
 
132
- static R call(storage& s, ArgTypes... args) {
133
- return std::invoke(*static_cast<T*>(static_cast<void*>(&s.buf_)),
128
+ static R call(storage &s, ArgTypes... args) {
129
+ return std::invoke(*static_cast<T *>(static_cast<void *>(&s.buf_)),
134
130
  std::forward<ArgTypes>(args)...);
135
131
  }
136
132
  };
137
133
 
138
- template <class T>
139
- struct large_handler : handler_base<large_handler<T>> {
140
- template <class... Args>
141
- static void create(storage& s, Args&&... args) {
134
+ template <class T> struct large_handler : handler_base<large_handler<T>> {
135
+ template <class... Args> static void create(storage &s, Args &&...args) {
142
136
  s.ptr_ = new T(std::forward<Args>(args)...);
143
137
  }
144
138
 
145
- static void destroy(storage& s) noexcept { delete static_cast<T*>(s.ptr_); }
139
+ static void destroy(storage &s) noexcept {
140
+ delete static_cast<T *>(s.ptr_);
141
+ }
146
142
 
147
- static void move(storage& dst, storage& src) noexcept {
143
+ static void move(storage &dst, storage &src) noexcept {
148
144
  dst.ptr_ = src.ptr_;
149
145
  }
150
146
 
151
- static R call(storage& s, ArgTypes... args) {
152
- return std::invoke(*static_cast<T*>(s.ptr_),
147
+ static R call(storage &s, ArgTypes... args) {
148
+ return std::invoke(*static_cast<T *>(s.ptr_),
153
149
  std::forward<ArgTypes>(args)...);
154
150
  }
155
151
  };
@@ -159,8 +155,7 @@ struct handler_traits {
159
155
  large_handler<T>>;
160
156
  };
161
157
 
162
- template <class T>
163
- struct is_in_place_type : std::false_type {};
158
+ template <class T> struct is_in_place_type : std::false_type {};
164
159
 
165
160
  template <class T>
166
161
  struct is_in_place_type<std::in_place_type_t<T>> : std::true_type {};
@@ -176,16 +171,16 @@ class any_invocable_impl {
176
171
 
177
172
  using storage = any_detail::storage;
178
173
  using action = any_detail::action;
179
- using handle_func = void (*)(any_detail::action, any_detail::storage*,
180
- any_detail::storage*);
181
- using call_func = R (*)(any_detail::storage&, ArgTypes...);
174
+ using handle_func = void (*)(any_detail::action, any_detail::storage *,
175
+ any_detail::storage *);
176
+ using call_func = R (*)(any_detail::storage &, ArgTypes...);
182
177
 
183
- public:
178
+ public:
184
179
  using result_type = R;
185
180
 
186
181
  any_invocable_impl() noexcept = default;
187
182
  any_invocable_impl(std::nullptr_t) noexcept {}
188
- any_invocable_impl(any_invocable_impl&& rhs) noexcept {
183
+ any_invocable_impl(any_invocable_impl &&rhs) noexcept {
189
184
  if (rhs.handle_) {
190
185
  handle_ = rhs.handle_;
191
186
  handle_(action::move, &storage_, &rhs.storage_);
@@ -194,18 +189,18 @@ class any_invocable_impl {
194
189
  }
195
190
  }
196
191
 
197
- any_invocable_impl& operator=(any_invocable_impl&& rhs) noexcept {
192
+ any_invocable_impl &operator=(any_invocable_impl &&rhs) noexcept {
198
193
  any_invocable_impl{std::move(rhs)}.swap(*this);
199
194
  return *this;
200
195
  }
201
- any_invocable_impl& operator=(std::nullptr_t) noexcept {
196
+ any_invocable_impl &operator=(std::nullptr_t) noexcept {
202
197
  destroy();
203
198
  return *this;
204
199
  }
205
200
 
206
201
  ~any_invocable_impl() { destroy(); }
207
202
 
208
- void swap(any_invocable_impl& rhs) noexcept {
203
+ void swap(any_invocable_impl &rhs) noexcept {
209
204
  if (handle_) {
210
205
  if (rhs.handle_) {
211
206
  storage tmp;
@@ -227,9 +222,8 @@ class any_invocable_impl {
227
222
 
228
223
  explicit operator bool() const noexcept { return handle_ != nullptr; }
229
224
 
230
- protected:
231
- template <class F, class... Args>
232
- void create(Args&&... args) {
225
+ protected:
226
+ template <class F, class... Args> void create(Args &&...args) {
233
227
  using hdl = handler<F>;
234
228
  hdl::create(storage_, std::forward<Args>(args)...);
235
229
  handle_ = &hdl::handle;
@@ -247,24 +241,24 @@ class any_invocable_impl {
247
241
  return call_(storage_, std::forward<ArgTypes>(args)...);
248
242
  }
249
243
 
250
- friend bool operator==(const any_invocable_impl& f, std::nullptr_t) noexcept {
244
+ friend bool operator==(const any_invocable_impl &f, std::nullptr_t) noexcept {
251
245
  return !f;
252
246
  }
253
- friend bool operator==(std::nullptr_t, const any_invocable_impl& f) noexcept {
247
+ friend bool operator==(std::nullptr_t, const any_invocable_impl &f) noexcept {
254
248
  return !f;
255
249
  }
256
- friend bool operator!=(const any_invocable_impl& f, std::nullptr_t) noexcept {
250
+ friend bool operator!=(const any_invocable_impl &f, std::nullptr_t) noexcept {
257
251
  return static_cast<bool>(f);
258
252
  }
259
- friend bool operator!=(std::nullptr_t, const any_invocable_impl& f) noexcept {
253
+ friend bool operator!=(std::nullptr_t, const any_invocable_impl &f) noexcept {
260
254
  return static_cast<bool>(f);
261
255
  }
262
256
 
263
- friend void swap(any_invocable_impl& lhs, any_invocable_impl& rhs) noexcept {
257
+ friend void swap(any_invocable_impl &lhs, any_invocable_impl &rhs) noexcept {
264
258
  lhs.swap(rhs);
265
259
  }
266
260
 
267
- private:
261
+ private:
268
262
  storage storage_;
269
263
  handle_func handle_ = nullptr;
270
264
  call_func call_;
@@ -282,10 +276,9 @@ using can_convert = std::conjunction<
282
276
  std::is_nothrow_invocable_r_v<R, FCall, ArgTypes...>)>,
283
277
  std::is_constructible<std::decay_t<F>, F>>;
284
278
 
285
- } // namespace any_detail
279
+ } // namespace any_detail
286
280
 
287
- template <class Signature>
288
- class any_invocable;
281
+ template <class Signature> class any_invocable;
289
282
 
290
283
  #define __OFATS_ANY_INVOCABLE(cv, ref, noex, inv_quals) \
291
284
  template <class R, class... ArgTypes> \
@@ -293,14 +286,14 @@ class any_invocable;
293
286
  : public any_detail::any_invocable_impl<R, noex, ArgTypes...> { \
294
287
  using base_type = any_detail::any_invocable_impl<R, noex, ArgTypes...>; \
295
288
  \
296
- public: \
289
+ public: \
297
290
  using base_type::base_type; \
298
291
  \
299
292
  template < \
300
293
  class F, \
301
294
  class = std::enable_if_t<any_detail::can_convert< \
302
295
  any_invocable, F, noex, R, F inv_quals, ArgTypes...>::value>> \
303
- any_invocable(F&& f) { \
296
+ any_invocable(F &&f) { \
304
297
  base_type::template create<std::decay_t<F>>(std::forward<F>(f)); \
305
298
  } \
306
299
  \
@@ -311,33 +304,32 @@ class any_invocable;
311
304
  std::is_invocable_r_v<R, VT inv_quals, ArgTypes...> && \
312
305
  (!noex || std::is_nothrow_invocable_r_v<R, VT inv_quals, \
313
306
  ArgTypes...>)>> \
314
- explicit any_invocable(std::in_place_type_t<T>, Args&&... args) { \
307
+ explicit any_invocable(std::in_place_type_t<T>, Args &&...args) { \
315
308
  base_type::template create<VT>(std::forward<Args>(args)...); \
316
309
  } \
317
310
  \
318
- template < \
319
- class T, class U, class... Args, class VT = std::decay_t<T>, \
320
- class = std::enable_if_t< \
321
- std::is_move_constructible_v<VT> && \
322
- std::is_constructible_v<VT, std::initializer_list<U>&, Args...> && \
323
- std::is_invocable_r_v<R, VT inv_quals, ArgTypes...> && \
324
- (!noex || \
325
- std::is_nothrow_invocable_r_v<R, VT inv_quals, ArgTypes...>)>> \
311
+ template <class T, class U, class... Args, class VT = std::decay_t<T>, \
312
+ class = std::enable_if_t< \
313
+ std::is_move_constructible_v<VT> && \
314
+ std::is_constructible_v<VT, std::initializer_list<U> &, \
315
+ Args...> && \
316
+ std::is_invocable_r_v<R, VT inv_quals, ArgTypes...> && \
317
+ (!noex || std::is_nothrow_invocable_r_v<R, VT inv_quals, \
318
+ ArgTypes...>)>> \
326
319
  explicit any_invocable(std::in_place_type_t<T>, \
327
- std::initializer_list<U> il, Args&&... args) { \
320
+ std::initializer_list<U> il, Args &&...args) { \
328
321
  base_type::template create<VT>(il, std::forward<Args>(args)...); \
329
322
  } \
330
323
  \
331
324
  template <class F, class FDec = std::decay_t<F>> \
332
325
  std::enable_if_t<!std::is_same_v<FDec, any_invocable> && \
333
326
  std::is_move_constructible_v<FDec>, \
334
- any_invocable&> \
335
- operator=(F&& f) { \
327
+ any_invocable &> \
328
+ operator=(F &&f) { \
336
329
  any_invocable{std::forward<F>(f)}.swap(*this); \
337
330
  return *this; \
338
331
  } \
339
- template <class F> \
340
- any_invocable& operator=(std::reference_wrapper<F> f) { \
332
+ template <class F> any_invocable &operator=(std::reference_wrapper<F> f) { \
341
333
  any_invocable{f}.swap(*this); \
342
334
  return *this; \
343
335
  } \
@@ -357,21 +349,20 @@ __OFATS_ANY_INVOCABLE(, &, false, &) // 010
357
349
  __OFATS_ANY_INVOCABLE(, &, true, &) // 011
358
350
  __OFATS_ANY_INVOCABLE(, &&, false, &&) // 020
359
351
  __OFATS_ANY_INVOCABLE(, &&, true, &&) // 021
360
- __OFATS_ANY_INVOCABLE(const, , false, const&) // 100
361
- __OFATS_ANY_INVOCABLE(const, , true, const&) // 101
362
- __OFATS_ANY_INVOCABLE(const, &, false, const&) // 110
363
- __OFATS_ANY_INVOCABLE(const, &, true, const&) // 111
364
- __OFATS_ANY_INVOCABLE(const, &&, false, const&&) // 120
365
- __OFATS_ANY_INVOCABLE(const, &&, true, const&&) // 121
352
+ __OFATS_ANY_INVOCABLE(const, , false, const &) // 100
353
+ __OFATS_ANY_INVOCABLE(const, , true, const &) // 101
354
+ __OFATS_ANY_INVOCABLE(const, &, false, const &) // 110
355
+ __OFATS_ANY_INVOCABLE(const, &, true, const &) // 111
356
+ __OFATS_ANY_INVOCABLE(const, &&, false, const &&) // 120
357
+ __OFATS_ANY_INVOCABLE(const, &&, true, const &&) // 121
366
358
 
367
359
  #undef __OFATS_ANY_INVOCABLE
368
360
 
369
- } // namespace ofats
361
+ } // namespace ofats
370
362
 
371
363
  /* We, uWebSockets define our own type */
372
364
  namespace uWS {
373
- template <class T>
374
- using MoveOnlyFunction = ofats::any_invocable<T>;
365
+ template <class T> using MoveOnlyFunction = ofats::any_invocable<T>;
375
366
  }
376
367
 
377
- #endif // _ANY_INVOKABLE_H_
368
+ #endif // _ANY_INVOKABLE_H_