请求超时的正确打开姿势 -美图大佬
1.客户端相关接口
index | 函数原型 | 函数的作用 |
1 | ||
2 | void evhttp_connection_set_closecb( struct evhttp_connection* evcon,void(*)(struct evhttp_connection*, void* ),void* ); | 设置一个连接关闭的回调 |
3 | char* evhttp_decode_uri( const char* uri ); | 解码URI,返回值必须自己释放掉 |
4 | char* evhttp_encode_uri( const char* uri) | 编码URI,返回值需要释放 |
5 | char* evhttp_htmlescape( const char* html ) | 忽略html的字符 |
6 | void evhttp_parse_query( const char* uri,struct evkeyvalq*) | 解析请求里的参数 |
7 | struct evhttp_request_free( struct evhttp_request* req ) | 释放http请求 |
8 | void evhttp_set_time_out ( struct evhttp*,int timeout_in_sec); | 设置HTTP请求超时时间 |
9 |
| 设置回调函数,在包头读取完成后回调 |
10 | void evhttp_request_set_chunked_cb (struct evhttp_request *, void(*cb)(struct evhttp_request *, void *)) | 设置回调函数,在body有数据返回后回调 |
11 | struct evhttp_request* evhttp_request_new( void(*)(struct evhttp_request*, void*)cb,void* arg ); | 参数中的回调函数在完成一个请求的时候或者发生错误时调用 |
12 | evhttp_request_get_output_headers | 获取请求的header |
13 | int evhttp_add_header(struct evkeyvalq *headers, const char *key, const char *value); | 有选择的向evhttp_request添加包头字段 |
2.服务器端相关接口
index | ||
1 | 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_free( struct evhttp* hrttp ); | 释放创建的HTTP server | |
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* ) | 给所有的请求(不包含上面的特定回调的)设置的回调函数 | |
9 | void evhttp_send_error ( struct evhttp_request* req,int error,const char* reason); | 发送一个html错误消息给客户端 error: http错误码 reason:错误的简单描述 |
10 | void evhttp_send_reply( struct evhttp_request* req,int code,const char* reason,struct evbuffer* databuf) | 发送一个html回复给客户端 code : HTTP返回码 reason : 返回码的消息 databuf : 返回内容的body部分 |
1 | struct evhttp* evhttp_new(struct event_base* base) | 创建一个新的HTTP server |