Skip to content

Commit 42baac7

Browse files
committed
Zmq.hpp
1 parent 50ea6ba commit 42baac7

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

section5/SalesData.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ class SalesData final
5858
uint_type m_sold = 0;
5959
uint_type m_revenue = 0;
6060

61+
public:
62+
void inc_sold(uint_type s) noexcept
63+
{
64+
m_sold += s;
65+
}
66+
67+
void inc_revenue(currency_type r) noexcept
68+
{
69+
m_revenue += r;
70+
}
6171
public:
6272
string_view_type id() const noexcept
6373
{

section5/Zmq.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99

1010
BEGIN_NAMESPACE(cpp_study)
1111

12+
using zmq_context_type = zmq::context_t;
13+
using zmq_socket_type = zmq::socket_t;
14+
using zmq_message_type = zmq::message_t;
15+
1216
template<int thread_num = 1>
1317
class ZmqContext final
1418
{
19+
#if 0
1520
public:
1621
using zmq_context_type = zmq::context_t;
1722
using zmq_socket_type = zmq::socket_t;
1823
using zmq_message_type = zmq::message_t;
24+
#endif
1925
public:
2026
static
2127
zmq_context_type& context()
@@ -24,9 +30,15 @@ class ZmqContext final
2430
return ctx;
2531
}
2632
public:
27-
zmq_socket_type socket(int mode) const
33+
zmq_socket_type socket(int mode, size_t hwm = 1000) const
2834
{
29-
return zmq_socket_type(context(), mode);
35+
zmq_socket_type sock(context(), mode);
36+
37+
sock.setsockopt(
38+
mode == ZMQ_PULL ? ZMQ_RCVHWM : ZMQ_SNDHWM,
39+
hwm);
40+
41+
return sock;
3042
}
3143
};
3244

section5/srv.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "cpplang.hpp"
1010
#include "SalesData.hpp"
1111
#include "SpinLock.hpp"
12+
#include "Zmq.hpp"
1213

1314
int main()
1415
{

0 commit comments

Comments
 (0)