Skip to content

Commit b5828b9

Browse files
committed
Zmq.hpp
1 parent 934fdd9 commit b5828b9

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

section5/Zmq.hpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright (c) 2020 by Chrono
22

3-
#ifndef _SPIN_LOCK_HPP
4-
#define _SPIN_LOCK_HPP
3+
#ifndef _ZMQ_HPP
4+
#define _ZMQ_HPP
55

66
#include "cpplang.hpp"
77

8+
// /usr/include/zmq.hpp
89
#include <zmq.hpp>
910

1011
BEGIN_NAMESPACE(cpp_study)
@@ -30,19 +31,26 @@ class ZmqContext final
3031
return ctx;
3132
}
3233
public:
33-
zmq_socket_type socket(int mode, size_t hwm = 1000) const
34+
zmq_socket_type recv_sock(size_t hwm = 1000) const
3435
{
35-
zmq_socket_type sock(context(), mode);
36+
zmq_socket_type sock(context(), ZMQ_PULL);
3637

37-
sock.setsockopt(
38-
mode == ZMQ_PULL ? ZMQ_RCVHWM : ZMQ_SNDHWM,
39-
hwm);
38+
sock.setsockopt(ZMQ_RCVHWM, hwm);
39+
40+
return sock;
41+
}
42+
43+
zmq_socket_type send_sock(size_t hwm = 1000) const
44+
{
45+
zmq_socket_type sock(context(), ZMQ_PUSH);
46+
47+
sock.setsockopt(ZMQ_SNDHWM, hwm);
4048

4149
return sock;
4250
}
4351
};
4452

4553
END_NAMESPACE(cpp_study)
4654

47-
#endif //_SPIN_LOCK_HPP
55+
#endif //_ZMQ_HPP
4856

section5/config.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
-- copyright (c) 2020 chrono
22

3-
-- it is more flexible than json
3+
-- lua is more flexible than json
4+
45
config = {
56

67
max_buf_size = 4 * 1024,
78

9+
zmq_ipc_addr = "tcp://127.0.0.1:5555",
10+
11+
http_addr = "http://localhost/cpp_study?token=cpp@2020",
12+
813
keyword = "super",
914

1015
sold_criteria = 100,

0 commit comments

Comments
 (0)