libevent中一些http相关的操作

更详细可以看这里https://monkey.org/~provos/libevent/doxygen/evhttp_8h.html

 

struct evhttp* evhttp_new(struct event_base* base)

创建一个新的HTTP server

 

int evhttp_accept_socket(struct evhttp* http, int    fd);

使HTTP服务器在指定端口上接受连接。

可以多次调用使server监听多个不同的socket

 

int evhttp_bind_socket( struct evhttp* http,const char*  address,u_short      port);

给服务器绑定一个指定的地址和端口

 

void evhttp_connection_set_closecb(       struct evhttp_connection* evcon,void(*)(struct evhttp_connection*, void* ),void*

);

 设置一个连接关闭的回调

 

char* evhttp_decode_uri( const char* uri );

解码URI,返回值必须自己释放掉

 

char* evhttp_encode_uri( const char* uri)

编码URI,返回值需要释放

 

void evhttp_free( struct evhttp* hrttp );

释放创建的HTTP server

 

char* evhttp_htmlescape( const char* html )

忽略html的字符

 

void evhttp_parse_query(   const char* uri,struct evkeyvalq*)

解析请求里的参数

 

struct evhttp_request_free( struct evhttp_request* req )

释放http请求

 

struct evhttp_request* evhttp_request_new(    void(*)(struct evhttp_request*, void*)cb,void* arg );

 参数中的回调函数在完成一个请求的时候或者发生错误时调用

 

void evhttp_send_error ( struct evhttp_request* req,int error,const char* reason);

 发送一个html错误消息给客户端

error:  http错误码

reason:错误的简单描述

 

void evhttp_send_reply( struct evhttp_request* req,int code,const char* reason,struct evbuffer* databuf)

       发送一个html回复给客户端

       code       : HTTP返回码

       reason    : 返回码的消息

       databuf  : 返回内容的body部分

 

void evhttp_set_time_out ( struct evhttp*,int timeout_in_sec);

设置HTTP请求超时时间

 

struct evhttp* evhttp_start( const char* address, u_short    port);

在指定的地址和端口上启动一个HTTP服务器

 

void evhttp_set_cb(     struct evhttp*,const char*,void(*)(struct evhttp_request* , void*),void* )

 给指定的URI设置的回调

 

void evhttp_set_gencb( struct evhttp*,const char*,void(*)(struct evhttp_request* , void*),void* )

       给所有的请求(不包含上面的特定回调的)设置的回调函数

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值