6 Star 15 Fork 7

swair / frpc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Server.h 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
swair 提交于 2021-01-25 22:37 . u
#ifndef __SERVER_H
#define __SERVER_H
#include <stdio.h>
#include "Reactor.h"
#include "Common.h"
#include "LogWrite.h"
class Server
{
public:
void setCallBack(std::function<void(Fson& response, Fson& request, void* args)> cb, void* args)
{
cb_ = cb;
args_ = args;
}
int processHandler(int cfd)
{
auto work = [&]()->int {
Fson request;
Fson response;
int res = recvRequest(cfd, request);
if(res <= 0)
return SOCKET_EXCEPTION;
cb_(response, request, args_);
res = sendRequest(cfd, response);
if(res < 0)
{
logWrite("reply fail\n");
}
return SOCKET_CLOSE;
};
return work();
}
void startRun(const std::string& ip, const std::string& port)
{
Reactor reactor(10);
reactor.runEpollServer(ip.c_str(), port.c_str(), std::bind(&Server::processHandler, this, _1));
}
private:
std::function<void(Fson& response, Fson& request, void* args)> cb_;
void* args_;
};
#endif
C
1
https://gitee.com/swair/frpc.git
git@gitee.com:swair/frpc.git
swair
frpc
frpc
main

搜索帮助