限制libevent中的连接

发布于 2024-11-17 23:13:51 字数 261 浏览 3 评论 0原文

我想控制每个进程可能的 libevent-http 连接的限制。

我怎样才能做到这一点?

我在文档中没有找到任何信息,请帮忙!

我认为如果我不限制连接数量 - 系统可能会崩溃。项目负荷非常高。

ev_base = event_init();
ev_http = evhttp_new(ev_base);
// limit http connections here... how can i do that?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白首有我共你 2024-11-24 23:13:51
struct evconnlistener *
evconnlistener_new(struct event_base *base,
    evconnlistener_cb cb, void *ptr, unsigned flags, int backlog,
    evutil_socket_t fd)

待办事项是您要修改的内容。
他们在内部调用:

listen(fd, backlog)

但是在他们的 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);
        }
    [...]
}
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);
        }
    [...]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文