libevent 写了一个简单地web服务器
2016-04-21 15:35
501 查看
<span style="font-size:18px;">void DateDeal { } void httpd_handler(struct evhttp_request *req, void *arg) { const char *uri; uri = evhttp_request_uri(req); char *post_data = (char *) EVBUFFER_DATA(req->input_buffer); string result=DataDeal(uri,post_data); //url 和数据的处理函数 cout<<"result==="<<result.c_str()<<endl; //HTTP header evhttp_add_header(req->output_headers, "Server", MYHTTPD_SIGNATURE); evhttp_add_header(req->output_headers, "Content-Type", "text/plain; charset=UTF-8"); evhttp_add_header(req->output_headers, "Connection", "close"); struct evbuffer *buf; buf = evbuffer_new(); evbuffer_add_printf(buf, "%s\n",result.c_str()); evhttp_send_reply(req, HTTP_OK, "OK", buf); evbuffer_free(buf); } int main() { event_init(); //http server struct evhttp *httpd; httpd = evhttp_start(g_JsServerIp, g_JsServerPt); printf("ip===%s\nport=%d\n",g_JsServerIp,g_JsServerPt); printf("success\n"); //generic callback int httpd_option_timeout = 120; evhttp_set_timeout(httpd, httpd_option_timeout); evhttp_set_gencb(httpd, httpd_handler, NULL);//处理post请求的http内容 //callback event_dispatch(); evhttp_free(httpd); } </span>
相关文章推荐
- 深入理解javascript的闭包
- IE 浏览器下英文 微软雅黑 不起作用
- 公共POI导出Excel方法--java
- javascript数组
- 【小松教你手游开发】【unity实用技能】对象的简单平移与旋转
- java中的多态总结
- Mac下Lua Sublime Text3 开发环境搭建
- [FAQ13934]如何添加Static Library (静态库)到Share Library(共享库)
- 深度学习之图像分割 《Fully Convolutional Networks for Semantic Segmentation》—FCN
- HDU 1180 诡异的楼梯
- DAY6
- Android里Service的bindService()和startService()混合使用深入分析
- 移动端设计尺寸基础知识
- 恢复误删的桌面 回收站
- 批处理实现自动删除过期文件的定期操作
- WEB-INF文件夹的位置和作用
- Tomcat使用数据源(JNDI/直接使用)
- 字符串最后一个单词的长度
- 专题二 · 1005
- sscanf函数和正则表达式