首页 > 代码库 > libevent(十)evhttp

libevent(十)evhttp

用libevent构建一个http server非常方便,可参考libevent(七)http server。

主要涉及的一个结构体是 evhttp:

struct evhttp {
    /* Next vhost, if this is a vhost. */
    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;
};

 

libevent(十)evhttp