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 c开发者_运维知识库an 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);
}
[...]
}
精彩评论