ehttp基于 epoll 的輕量級(jí) http server
ehttp 組件是為了使用c++方便快速的構(gòu)建http server,編寫基于http協(xié)議json格式的接口,和nginx等傳統(tǒng)服務(wù)器相比,更加重視開發(fā)的便捷性,項(xiàng)目參考restbed 實(shí)現(xiàn)。
特點(diǎn)
-
linux 2.6 +
-
多線程 + epoll
-
強(qiáng)調(diào)簡(jiǎn)潔實(shí)用
依賴
-
simple_log 日志組件
-
jsoncpp json序列化組件
性能
-
qps 12000+ (短連接 ab -c 10 -n 10000 localhost:3490/hello)
-
qps 16000+ (長(zhǎng)連接 ab -c 10 -n 10000 -k localhost:3490/hello)
構(gòu)建 && 測(cè)試
make && make test && ./output/bin/http_server_test 3490 curl "localhost:3490/hello"
功能列表
-
http 1.0/1.1(keep-alive 支持) GET/POST請(qǐng)求
-
便捷的開發(fā)形式
-
Json格式的數(shù)據(jù)返回
例子
#include
#include
#include "simple_log.h"
#include "http_server.h"
void login(Request &request, Json::Value &root) {
std::string name = request.get_param("name");
std::string pwd = request.get_param("pwd");
LOG_DEBUG("login user which name:%s, pwd:%s", name.c_str(), pwd.c_str());
root["code"] = 0;
root["msg"] = "login success!";
}
int main() {
HttpServer http_server;
http_server.add_mapping("/login", login, POST_METHOD);
http_server.set_port(3456);
http_server.start_sync();
return 0;
}
運(yùn)行
liao@ubuntu:~/workspace/simple_server$ curl "localhost:3490/login" -d "name=tom&pwd=3"
{"code":0,"msg":"login success!"}評(píng)論
圖片
表情
