1 Star 0 Fork 34

思变 / CxxConet

forked from cxxjava / CxxConet 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
benchmark.cpp 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
cxxjava 提交于 2017-08-31 17:12 . 文件重命名
#include "es_main.h"
#include "ENaf.hh"
#define LOG(fmt,...) //ESystem::out->println(fmt, ##__VA_ARGS__)
static void onConnection(ESocketSession* session, ESocketAcceptor::Service* service) {
LOG("onConnection: service=%s", service->toString().c_str());
sp<EIoBuffer> request;
try {
request = dynamic_pointer_cast<EIoBuffer>(session->read());
} catch (ESocketTimeoutException& e) {
LOG("session read timeout.");
return;
} catch (EIOException& e) {
LOG("session read error.");
return;
}
if (request == null) {
LOG("session client closed.");
return;
}
// echo.
#define TEST_HTTP_DATA "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nOK!"
int len = strlen(TEST_HTTP_DATA);
sp<EIoBuffer> respone = EIoBuffer::allocate(len);
respone->put(TEST_HTTP_DATA, len);
respone->flip();
session->write(respone);
LOG("Out of Connection.");
}
static void test_echo_performance() {
ESocketAcceptor sa;
sa.setConnectionHandler(onConnection);
sa.setSoTimeout(3000);
sa.setSessionIdleTime(EIdleStatus::WRITER_IDLE, 30);
sa.bind("0.0.0.0", 8888);
sa.listen();
}
MAIN_IMPL(testnaf_benchmark) {
printf("main()\n");
ESystem::init(argc, argv);
ELoggerManager::init("log4e.conf");
printf("inited.\n");
int i = 0;
try {
boolean loop = EBoolean::parseBoolean(ESystem::getProgramArgument("loop"));
do {
test_echo_performance();
} while (1);
}
catch (EException& e) {
e.printStackTrace();
}
catch (...) {
printf("catch all...\n");
}
printf("exit...\n");
ESystem::exit(0);
return 0;
}
C++
1
https://gitee.com/sibian/CxxConet.git
git@gitee.com:sibian/CxxConet.git
sibian
CxxConet
CxxConet
master

搜索帮助