資源簡介
event_init();
//創建一個http server
struct evhttp *httpd;
httpd = evhttp_start(httpd_option_listen, httpd_option_port);
evhttp_set_timeout(httpd, httpd_option_timeout);
//指定generic callback
evhttp_set_gencb(httpd, httpd_handler, NULL);
//也可以為特定的URI指定callback
//evhttp_set_cb(httpd, "/", specific_handler, NULL);
//循環處理events
event_dispatch();
evhttp_free(httpd);
代碼片段和文件信息
????#include?
????#include?
????#include??????//for?getopt?fork
????#include??????//for?strcat
????//for?struct?evkeyvalq
????#include?
????#include?
????//for?http
????#include?
????#include?
?
????#define?MYHTTPD_SIGNATURE???“myhttpd?v?0.0.1“
?
????//處理模塊
????void?httpd_handler(struct?evhttp_request?*req?void?*arg)?{
????????char?output[2048]?=?“\0“;
????????char?tmp[1024];
?
????????//獲取客戶端請求的URI(使用evhttp_request_uri或直接req->uri)
????????const?char?*uri;
????????uri?=?evhttp_request_uri(req);
????????sprintf(tmp?“uri=%s\n“?uri);
????????strcat(output?tmp);
?
????????sprintf(tmp?“uri=%s\n“?req->uri);
????????strcat(output?tmp);
????????//decoded?uri
????????char?*decoded_uri;
????????decoded_uri?=?evhttp_decode_uri(uri);
????????sprintf(tmp?“decoded_uri=%s\n“?decoded_uri);
????????strcat(output?tmp);
?
????????//解析URI的參數(即GET方法的參數)
????????struct?evkeyvalq?par
- 上一篇:UNIX環境高級編程
- 下一篇:CTP-Api行情Demo版源碼
評論
共有 條評論