-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.cpp
More file actions
112 lines (86 loc) · 2.53 KB
/
demo.cpp
File metadata and controls
112 lines (86 loc) · 2.53 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "demo.h"
#include <stdio.h>
#include "base/wshandller.h"
using namespace base;
using namespace std;
DemoSvr::DemoSvr()
{
}
DemoSvr::~DemoSvr()
{
}
void DemoSvr::admin_test(void* para,int argc, char **argv, std::ostream& os)
{
DemoSvr* pSelf = (DemoSvr*)para;
if (argc < 2)
{
os<<"found invalid param"<<endl;
return;
}
os<<"test succefully:para count:"<<argc<<",para:";
for (int i = 0 ; i < argc;++i)
{
os<<argv[i]<<",";
}
os<<endl;
}
void DemoSvr::init_admin()
{
ServerAdmin& as = getServerAdmin();
AdminCmdInfo aa;
aa.func_para = this;
aa.desc = "usage:test_admin para1 para2";
aa.func = DemoSvr::admin_test;
as.addCommand("test_admin", aa);
}
void DemoSvr::init(const char *conf_file)throw(runtime_error)
{
try
{
m_strConfigFile = conf_file;
Server::init(conf_file);
m_confMgr.Init(conf_file);
string logpath = m_confMgr["zeus\\Log\\Name"];
unsigned int logsize = s2u(m_confMgr["zeus\\Log\\Size"]);
unsigned int lognum = s2u(m_confMgr["zeus\\Log\\Num"]);
unsigned int log_level = s2u(m_confMgr["zeus\\Log\\Level"]);
m_pRollLog = new base::Logger(logpath.c_str(), logsize, lognum,Logger::DEBUG_LOG, true, false);
m_pRollLog->normal("system start success!");
init_admin();
}
catch (conf_load_error &ex)
{
//m_pRollLog->error("DemoSvr::init: init fail : %s", (char*)(ex.what()));
throw ex;
}
catch (conf_not_find& ex)
{
//m_pRollLog->error("DemoSvr::init: conf_not_find: %s" ,(char*)(ex.what()));
throw ex;
}
}
void DemoSvr::connectionMade(Connection* pConn)
{
m_pRollLog->debug("sproxy:connection made:%d,%s", pConn->fd(),(char*)(pConn->getIPStr().c_str()));
}
void DemoSvr::connectionLost(Connection* pConn)
{
m_pRollLog->debug("sproxy:connection lost:%d,%s", pConn->fd(),(char*)(pConn->getIPStr().c_str()));
}
void DemoSvr::timeoutHandller(time_t now)
{
}
void DemoSvr::dataReceived(Connection* pConn,const char* data,unsigned int nLength)
{
m_pRollLog->debug("DemoSvr::dataReceived:ip:%s,recv data len:%d",pConn->getIPStr().c_str(),nLength);
if (pConn->isWebSocket())
{
//pConn->
cout<<"DemoSvr::dataReceived:websocket receive :"<<pConn->getPayLoadLen()<<"bytes,data:"<<pConn->getPayLoad()<<endl;
char bufOut[8*1024]={'\0'};
int nLenOut = 8*1024;
WSHandller::packData(pConn->getPayLoad(), pConn->getPayLoadLen(), bufOut, nLenOut);
cout <<"rsponse:len:"<<nLenOut<<endl;
pConn->sendMessage(bufOut,nLenOut);
}
}