-
Notifications
You must be signed in to change notification settings - Fork 240
/
Copy pathRemoteQueue.cpp
68 lines (57 loc) · 1.1 KB
/
RemoteQueue.cpp
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
#include "stdafx.h"
#include "RemoteQueue.h"
CRemoteQueue::CRemoteQueue(char* address) :CMsgQueue()
{
m_pubisher = nullptr;
strncpy(m_Address, address, sizeof(m_Address));
#ifdef _REMOTE
m_ctx = nullptr;
#endif
}
CRemoteQueue::~CRemoteQueue()
{
}
void CRemoteQueue::RunInThread()
{
#ifdef _REMOTE
m_ctx = zctx_new();
m_pubisher = zsocket_new(m_ctx, ZMQ_PUB);
int port = zsocket_bind(m_pubisher, m_Address);
#endif
while (m_bRunning)
{
if (Process())
{
}
else
{
// 空闲时等1ms,如果立即有事件过来就晚了1ms
//this_thread::sleep_for(chrono::milliseconds(1));
// 空闲时过来等1ms,没等到就回去再试
// 如过正好等到了,就立即去试,应当会快一点吧?
unique_lock<mutex> lck(m_mtx);
m_cv.wait_for(lck, std::chrono::seconds(1));
}
}
#ifdef _REMOTE
if (m_ctx)
{
zctx_destroy(&m_ctx);
m_ctx = nullptr;
}
#endif
// 清理线程
m_hThread = nullptr;
m_bRunning = false;
}
void CRemoteQueue::Output(ResponeItem* pItem)
{
#ifdef _REMOTE
// 发送数据
if (pItem->ptr1 && pItem->size1>0)
{
int ret = zsocket_sendmem(m_pubisher, pItem->ptr1, pItem->size1, ZFRAME_DONTWAIT);
}
#endif
return;
}