libevent源码学习-第四天
来源:互联网 发布:android 无网络提示 编辑:程序博客网 时间:2024/06/11 23:31
<http-internal.h>
该文件包含libevent内部处理http请求的相关定义。希望基于libevent建立一个http服务器对象,需要使用该文件中的部分定义。但是,相关的结构体在http.h中已经有了声明,
因此对于该文件中的内容可以不必了解。
http服务器对象的结构如下:
struct evhttp {
TAILQ_ENTRY(evhttp) next_vhost;
/* All listeners for this host */
TAILQ_HEAD(boundq, evhttp_bound_socket) sockets;
TAILQ_HEAD(httpcbq, evhttp_cb) callbacks;
/* All live connections on this host. */
struct evconq connections;
TAILQ_HEAD(vhostsq, evhttp) virtualhosts;
TAILQ_HEAD(aliasq, evhttp_server_alias) aliases;
/* NULL if this server is not a vhost */
char *vhost_pattern;
int timeout;
size_t default_max_headers_size;
ev_uint64_t default_max_body_size;
/* Bitmask of all HTTP methods that we accept and pass to user
* callbacks. */
ev_uint16_t allowed_methods;
/* Fallback callback if all the other callbacks for this connection
don't match. */
void (*gencb)(struct evhttp_request *req, void *);
void *gencbarg;
struct event_base *base;
};
1. next_vhost
指向下一个vhost的指针。
2. sockets
当前服务器对象监听的端口列表。
3. callbacks
当前服务器对象的回调函数列表。
4. connections
当前服务器对象上的所有活动连接。
5. default_max_headers_size
默认最大http请求头大小。
6.default_max_body_size;
默认最大http请求体大小。
7.gencb
默认的回调函数。
8.gencbar
默认回调函数的参数。
9.base
服务器对象所属的event_base对象。
<evhttp.h>
提供了使用libevent建立http服务器的相应函数接口。
struct evhttp* evhttp_new(struct event_base* base)
创建一个http的server,并指定相应的event_base,内部调用evhttp_new_object函数生成并初始化evhttp对象。
int evhttp_bind_socket(struct evhttp *http, const char *address, ev_uint16_t port)
为http服务器绑定端口和地址,并执行listen以及accept操作。最大等待连接数量为128(hard code)。本函数执行内会有多轮的函数调用,较为复杂,但实际上该函数执行完之后
可以获取连接请求的相应的信息。当有连接请求时,握手阶段在该过程设置的回调函数内完成。
struct evhttp * evhttp_start(const char *address, unsigned short port)
生成一个http的server,并绑定相应的ip和端口。
To be Continue。。。。
- libevent源码学习-第四天
- libevent源码学习-第二天
- Libevent源码学习---bufferevent
- libevent源码学习研究(libevent-0.1)
- libevent源码学习-第一天
- libevent源码学习-第三天
- libevent源码学习-----Reactor模型
- libevent源码学习-----阅读心得
- libevent源码学习-----时间管理
- libevent源码学习-----event操作
- libevent学习之一:libevent源码的特点和结构
- libevent源码学习_结构体
- libevent源码学习_接口函数
- libevent库源码学习-kqueue( freebsd)
- libevent库源码学习-epoll( linux)
- Libevent源码学习(二) 事件的概念
- Libevent学习---evconnlistener使用和源码分析
- libevent源码学习(一)event事件
- JBOSS AS 性能调整优化
- Apache 性能调优-参考篇
- Apache虚拟主机-解惑篇
- Mysql导入数据时-data truncated for column..
- 探索Oracle 11gR2 DataGuard_02配置
- libevent源码学习-第四天
- 证明可以使用的blazeds推送
- Derby使用3—Embedded模式
- happy every year~
- LCS算法
- 易用的C++ RPC服务框架 - pioneer - 2 - 编译和执行演示程序
- sgu - 518 - Kidnapping(set + dp)
- 对java中package的理解
- IOS学习之路之 音效处理