Skip to content

Commit a8751a0

Browse files
committed
Zmq.hpp
1 parent e02bf1f commit a8751a0

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

section5/SpinLock.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
BEGIN_NAMESPACE(cpp_study)
99

10+
// atomic spinlock with TAS
1011
class SpinLock final
1112
{
1213
public:
@@ -43,6 +44,8 @@ class SpinLock final
4344
atomic_type m_lock {false};
4445
};
4546

47+
// RAII for lock
48+
// you can change it to a template class
4649
class SpinLockGuard final
4750
{
4851
public:

section5/Zmq.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ class ZmqContext final
3232
}
3333
public:
3434
static
35-
zmq_socket_type recv_sock(int hwm = 1000)
35+
zmq_socket_type recv_sock(int hwm = 1000, int linger = 10)
3636
{
3737
zmq_socket_type sock(context(), ZMQ_PULL);
3838

3939
sock.setsockopt(ZMQ_RCVHWM, hwm);
40-
sock.setsockopt(ZMQ_LINGER, 10); // wait for 10ms
40+
sock.setsockopt(ZMQ_LINGER, linger); // wait for 10ms
4141

4242
return sock;
4343
}
4444

4545
static
46-
zmq_socket_type send_sock(int hwm = 1000)
46+
zmq_socket_type send_sock(int hwm = 1000, int linger = 10)
4747
{
4848
zmq_socket_type sock(context(), ZMQ_PUSH);
4949

5050
sock.setsockopt(ZMQ_SNDHWM, hwm);
51-
sock.setsockopt(ZMQ_LINGER, 10); // wait for 10ms
51+
sock.setsockopt(ZMQ_LINGER, linger); // wait for 10ms
5252

5353
return sock;
5454
}

0 commit comments

Comments
 (0)