代码拉取完成,页面将自动刷新
#include <cstdio>
#include <iostream>
#include "HEpoll.h"
#include "AliasRef.h"
/**
* 测试服务端功能
*/
#define CHKRET(r) if(r){printf("line:%d " #r "=%d\n", __LINE__, r); return r;}
atomic_int g_recv_count(0);
atomic_ullong g_recv_bytes(0);
void OnRequest(const string& msg, weak_ptr<ConnectMeta> wconnMeta)
{
//printf("recv Req: %s\n", msg.c_str());
auto connMeta = wconnMeta.lock();
//connMeta->sendMsg(msg);
connMeta->sendMsg("R\n");
//g_recv_count += 1;
//g_recv_bytes += msg.size();
}
void SplitReqest(queue<string>& reqQueue, string& stream, weak_ptr<ConnectMeta>)
{
g_recv_count += 1;
g_recv_bytes += stream.size();
reqQueue.push("R");
printf("recv bytes: %llu count:%d\n", g_recv_bytes.load(), g_recv_count.load());
stream.clear();
}
int main(int argc, char** argv)
{
HEpoll hep;
int ret = hep.init();
CHKRET(ret);
hep.setAliasNameInstance(make_shared<AliasRef<ConnectMetaSPtr>>());
hep.run(true);
auto lisnMeta = hep.addTcpListen(argc > 1? stoi(argv[1]) :8888);
ret = lisnMeta->setKeepAlive(60);
CHKRET(ret);
lisnMeta->onMessageReachFunc = OnRequest;
lisnMeta->splitReqFunc = SplitReqest;
lisnMeta->start();
ConnectMetaSPtr connMeta;
string input;
while (cin >> input, input != "q")
{
if ("r" == input)
{
g_recv_bytes = 0;
g_recv_count = 0;
}
else if ('p' == input[0])
{
printf("hep status=%s\n", hep.toString().c_str());
printf("recv=%llu bytes %d rows\n", g_recv_bytes.load(), g_recv_count.load());
if (input[1] > 0)
{
int fd = stoi(input.c_str()+1);
auto connMeta = hep.find(fd);
if (connMeta)
{
printf("fd=%d : %s\n", fd, connMeta->toString().c_str());
}
}
}
input.clear();
}
printf("notify Exit");
hep.notifyExit();
hep.unInit();
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。