简体   繁体   English

限制 libevent 中的连接

[英]Limit connections in libevent

I want to control limit of possible libevent-http connections per process.我想控制每个进程可能的 libevent-http 连接的限制。

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:然而,在他们的 http 库中,他们将积压工作修复为 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);
        }
    [...]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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