libevhtp

作者: 亚钧 | 来源:发表于2021-01-28 16:12 被阅读0次

参考:
https://blog.csdn.net/liitdar/article/details/80226815

#include <iostream>
#include "evhtp.h"
 
using namespace std;
 
void testcb(evhtp_request_t *req, void *a)
{
    evbuffer_add_reference(req->buffer_out, "foobar\n", 7, NULL, NULL);
    evhtp_send_reply(req, EVHTP_RES_OK);
}
 
int main(int argc, const char *argv[])
{
    evbase_t *evbase = event_base_new();
    evhtp_t *htp = evhtp_new(evbase, NULL);
    
    /* 设置回调函数 */
    evhtp_set_cb(htp, "/", testcb, NULL);
    /* 监听本地所有IP的8080端口, backlog为1024 */
    evhtp_bind_socket(htp, "0.0.0.0", 8080, 1024);
    /* 进入循环、监听连接,http server开始工作 */
    event_base_loop(evbase, 0);
    
    return 0;
}

相关文章

网友评论

      本文标题:libevhtp

      本文链接:https://www.haomeiwen.com/subject/cdoqtltx.html