Skip to content

tryor/evhttpd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English

evhttpd

evhttpd 是一个基于libev网络库,用C++语言编写的一个轻量级HTTP服务框架。

使用evhttpd需要的条件:

  • GCC > 4.7
  • libev > 4.0

操作系统

=======

  • linux

安装依赖

 wget http://dist.schmorp.de/libev/libev-4.24.tar.gz
 tar xzvf libev-4.24.tar.gz 
 cd libev-4.24
 ./configure
 make & make install

安装evhttpd库

 wget https://github.com/tryor/evhttpd/releases/download/0.0.4/libevhttp-0.0.4.tar.gz
 tar xzvf libevhttp-0.0.4.tar.gz
 cd libevhttp-0.0.4
 ./configure
 make & make install

例子

#include <evhttp/HttpServer.h>
#include <evhttp/Config.h>
#include <evhttp/HttpServletFactory.h>
using namespace std;

class HelloHttpServlet : public HttpServlet{
public:
    HelloHttpServlet(){}
    virtual ~HelloHttpServlet(){}
    virtual void service(Request& req, Response& resp){
        resp.setContentType("text/html; charset=utf-8");
        resp.write("Hello World!");
    }
};

class TestHttpServletFactory : public HttpServletFactory{
public:
    TestHttpServletFactory(){}
    virtual ~TestHttpServletFactory(){}
    virtual HttpServlet* create(const char* path){
        return new HelloHttpServlet();
    }
    void free(HttpServlet* servlet){
        delete servlet;
    }
};

int main(int argc, char** argv) {
    Config config;
    config.workProcessCount = 3;
    TestHttpServletFactory servletFactory;
    HttpServer httpServer(3080, &servletFactory, &config);
    if(!httpServer.start()){
        return 1;
    }
    HttpServer::loop();
}

更多: @see (https://github.com/tryor/evhttpd/releases/download/0.0.4/evhttpd_example.zip)

注意

如果找不到libev或libevhttp库,可试着执行下:ldconfig /usr/local/lib 或 ldconfig /usr/local/lib64