-
-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathoutgoing_msg.h
80 lines (60 loc) · 2.06 KB
/
outgoing_msg.h
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
#pragma once
#include <napi.h>
#include <forward_list>
#include <functional>
#include "./zmq_inc.h"
namespace zmq {
class Module;
class OutgoingMsg {
public:
class Parts;
/* Avoid copying outgoing messages, since the destructor is not copy safe,
nor should we have to copy messages with the right STL containers. */
OutgoingMsg(const OutgoingMsg&) = delete;
OutgoingMsg& operator=(const OutgoingMsg&) = delete;
OutgoingMsg(OutgoingMsg&&) = delete;
OutgoingMsg& operator=(OutgoingMsg&&) = delete;
/* Outgoing message. Takes a string or buffer argument and releases
the underlying V8 resources whenever the message is sent, or earlier
if the message was copied (small buffers & strings). */
explicit OutgoingMsg(Napi::Value value, std::reference_wrapper<Module> module);
~OutgoingMsg();
zmq_msg_t* get() {
return &msg;
}
private:
class Reference {
Napi::Reference<Napi::Value> persistent;
std::reference_wrapper<Module> module;
public:
explicit Reference(Napi::Value val, std::reference_wrapper<Module> module)
: persistent(Napi::Persistent(val)), module(module) {}
void Recycle();
};
zmq_msg_t msg{};
friend class Module;
};
/* Simple list over outgoing messages. Will take a single v8 value or an array
of values and keep references to these items as necessary. */
class OutgoingMsg::Parts {
std::forward_list<OutgoingMsg> parts;
public:
Parts() = default;
explicit Parts(Napi::Value value, Module& module);
std::forward_list<OutgoingMsg>::iterator begin() {
return parts.begin();
}
std::forward_list<OutgoingMsg>::iterator end() {
return parts.end();
}
#ifdef ZMQ_HAS_POLLABLE_THREAD_SAFE
bool SetGroup(Napi::Value value);
bool SetRoutingId(Napi::Value value);
#endif
void Clear() {
parts.clear();
}
};
} // namespace zmq
static_assert(!std::is_copy_constructible_v<zmq::OutgoingMsg>, "not copyable");
static_assert(!std::is_move_constructible_v<zmq::OutgoingMsg>, "not movable");