简体   繁体   中英

Limit connections in libevent

I want to control limit of possible libevent-http connections per process.

How can i do that?

I didn't found any info in documentation, please help!

I think that if i didn't limit number of connections - system can crash. Project is very high load.

ev_base = event_init();
ev_http = evhttp_new(ev_base);
// limit http connections here... how can i do that?
struct evconnlistener *
evconnlistener_new(struct event_base *base,
    evconnlistener_cb cb, void *ptr, unsigned flags, int backlog,
    evutil_socket_t fd)

The backlog is what you want to modify. Internally they call:

listen(fd, backlog)

However in their http library they fix the backlog to 128:

evhttp_bind_socket_with_handle(struct evhttp *http, const char *address, ev_uint16_t port)
{
    [...]
        if (listen(fd, 128) == -1) {
                event_sock_warn(fd, "%s: listen", __func__);
                evutil_closesocket(fd);
                return (NULL);
        }
    [...]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM