an-tao / trantor

a non-blocking I/O tcp network lib based on c++14/17
Other
392 stars 134 forks source link

consider adding TCP_KEEPCNT, TCP_KEEPIDLE,TCP_KEEPINTVL settings from environment variable? #252

Closed nqf closed 1 year ago

nqf commented 1 year ago

Sometimes we need to set these three values, But we are unable to modify the system configuration, Currently, the trantor does not provide an interface to set it up

if(const char* env_p = std::getenv("TRANTOR_TCP_KEEPCNT")) {
    int optval = std::atoi(env_p)
    setsockopt(sockfd, SOL_TCP, TCP_KEEPCNT, &optval, optlen);
    // setsockopt(sockfd, SOL_TCP, TCP_KEEPIDLE, &optval, optlen);
    // setsockopt(sockfd, SOL_TCP, TCP_KEEPINTVL, &optval, optlen);
}
nqf commented 1 year ago

@an-tao 不考虑增加这个设置吗

an-tao commented 1 year ago

I prefer to add getFd() method to the TcpConnection class. what do you think?

nqf commented 1 year ago

I prefer to add getFd() method to the TcpConnection class. what do you think?

我最终目的是期望可以在drogon中httpclient设置它,有办法在drogon中设置它吗,我们将drogon服务部署到aws上面了,但是aws nlb默认350秒会切断连接,所以需要设置自己的keepalive间隔

an-tao commented 1 year ago

httpclient要增加API处理getFd拿到的描述符

nqf commented 1 year ago

httpclient要增加API处理getFd拿到的描述符

最好是可以提供一些回调 或者 构造参数之类的

auto http_client_ptr = drogon::HttpClient::newHttpClient();
http_client_ptr->setsockopt([](int fd) {
    // 
});