forked from p308945/MyNetWorkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySockTask.cpp
More file actions
65 lines (59 loc) · 1.32 KB
/
MySockTask.cpp
File metadata and controls
65 lines (59 loc) · 1.32 KB
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
/*************************************************************************
> File Name: MySockTask.cpp
> Author: huangyun
> Mail: 895175589@qq.com
> Created Time: Fri 07 Aug 2015 08:22:12 AM
************************************************************************/
#include "MySockTask.h"
#include "MySocket.h"
#include <sys/epoll.h>
#include <arpa/inet.h>
namespace MyNameSpace
{
MySockTask::MySockTask(int sock, int id): mSock(sock), mId(id)
{
}
int MySockTask::getMsg()
{
int msgCount = 0;
while(true)
{
int len = 0;
std::vector<char> msg;
len = mSock.readBuffer(msg);
if (len <= 0)
{
if (len < 0)
{
msgCount = -1;
}
break;
}
++msgCount;
std::string str(&msg[0], len);
//std::cerr<<__FUNCTION__<<"("<<__LINE__<<") size :"<<len<<"str :"<<str<<std::endl;
pushMsg(len, &msg[0]);
}
return msgCount;
}
int MySockTask::rcvBuffer()
{
return mSock.rcvBuffer();
}
int MySockTask::addEpollEvent(int epfd, epoll_event & ev)
{
return mSock.addEpollEvent(epfd, ev);
}
int MySockTask::delEpollEvent(int epfd, epoll_event & ev)
{
return mSock.delEpollEvent(epfd, ev);
}
int MySockTask::syncSendBuf()
{
return mSock.syncSendBuf();
}
int MySockTask::sendDataWithBuffer(const char *buf, uint32_t len)
{
return mSock.sendDataWithBuffer(buf, len);
}
}