-
Notifications
You must be signed in to change notification settings - Fork 0
/
t_eventpipe.cpp
69 lines (62 loc) · 1.58 KB
/
t_eventpipe.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
69
#include "t_eventpipe.hpp"
#include "t_worktask.hpp"
namespace T_TCP
{
PipeConn::PipeConn(int ifd, void* pData): ConnBase(ifd), m_pData(pData)
{
}
//
PipeConn::~PipeConn()
{
}
bool PipeConn::AddEvent(struct event_base *pEvBase, int iEvent, void *arg)
{
if (pEvBase == NULL)
{
return false;
}
if (EV_READ & iEvent)
{
event_assign(&m_stREvent, pEvBase, m_iFd, iEvent, ReadCallBack, this);
event_add(&m_stREvent, NULL);
}
else if (iEvent & EV_WRITE)
{
event_assign(&m_stWEvent, pEvBase, m_iFd, iEvent, WriteCallBack, this);
event_add(&m_stWEvent, NULL);
}
else
{
}
return true;
}
void PipeConn::WriteCallBack(int iFd, short sEvent, void *pData)
{
}
void PipeConn::ReadCallBack(int iFd, short sEvent, void *pData)
{
char buf[1];
if (::read(iFd, buf, 1) != 1)
{
std::cout << "read buf from pipe fail" << std::endl;
return ;
}
PipeConn* pConn = (PipeConn*) pData;
if (pConn == NULL)
{
std::cout << "input param is empty" << std::endl;
return;
}
pConn->DoRead(buf, sizeof(buf));
}
void PipeConn::DoRead(char *pData, int iLen)
{
WorkerTask* pTask = (WorkerTask*)m_pData;
pTask->NotifyRecvConn(pData, iLen);
}
//TODO:
bool PipeConn::DelEvent(struct event_base *pEvBase, int iEvent, void *arg)
{
return true;
}
}