-
Notifications
You must be signed in to change notification settings - Fork 4
/
CommServer.cpp
49 lines (39 loc) · 1.08 KB
/
CommServer.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
#include "CommServer.h"
namespace CommLib {
CommSockImp::CommSockImp(int sock, boost::shared_ptr<MemPool> pMemPool
, TcpEpollServerImp* pEServ,
int timeOut
)
: TcpEpollSockImp(sock, pEServ),
TimeOut_(timeOut),
pMemPool_(pMemPool) {
LastRecvTime_ = Time::GetCurrentTime();
}
void CommSockImp::SetLastRecvTime() {
LastRecvTime_ = Time::GetCurrentTime();
};
bool CommSockImp::CheckValid() {
Time t = Time::GetCurrentTime();
if (t - LastRecvTime_ > TimeOut_) {
//超时
printf("超时\r\n");
Close();
return false;
}
return true;
}
int CommSockImp::OnRecv() {
SetLastRecvTime();
AllocPack* pack = pMemPool_->Alloc(1024);
if (pack) {
int len = Recv((void*) pack->getbuffer(), pack->getsize());
if (len > 0) {
pack->SetLength(len);
OnRecvPack(pack);
}
pack->release();
return len;
}
return -1;
}
}