warmcat / libwebsockets

canonical libwebsockets.org networking library

Home Page:https://libwebsockets.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to change the timeout of http/1.1 keepalive?

lestLyy opened this issue · comments

    struct lws_context_creation_info info;
    memset(&info, 0, sizeof(info));
    // info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT ;
    info.port = CONTEXT_PORT_NO_LISTEN;
    info.protocols = protocols;
    info.fd_limit_per_thread = 1 + 1 + 1;
    info.connect_timeout_secs = 20;
    info.keepalive_timeout = 10;
    info.options |= LWS_SERVER_OPTION_LIBEVENT;   // use libevent
    foreign_loops[0] = loop_event;
    info.foreign_loops = foreign_loops;
    g_context = lws_create_context(&info);


    struct lws_client_connect_info ccinfo = {0};
    ccinfo.alpn = "http/1.1";
    ccinfo.address = "warmcat.com";
    ccinfo.port = 443;
    ccinfo.path = "/";
    ccinfo.context = g_context;
    ccinfo.host = ccinfo.address;
    ccinfo.origin = ccinfo.address;
    ccinfo.method = http_method[METHOD_GET];
    ccinfo.local_protocol_name = HTTP_PROTOCOL;
    ccinfo.ssl_connection = LCCSCF_USE_SSL; //use ssl 
    ccinfo.ssl_connection |= LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK | LCCSCF_ALLOW_INSECURE ; //accepting non-trusted certificate
    ccinfo.ssl_connection |=LCCSCF_PIPELINE; //keepalive
    ccinfo.keep_warm_secs = 10;

I set the create_info and connect_info like that,and I set keepalive_timeout and keep_warm_secs to 10,but when I run the demo,the http connect still closed within 5s. How can I keep HTTP from being closed within 10 or 20 seconds, even without any action.

The peer server has just as much say as the client side in how long it's willing to sit idle. If it's configured to allow 5s then any longer timeout on the client side is moot - the server will have already hung up on it at 5s or whatever.

The peer server has just as much say as the client side in how long it's willing to sit idle. If it's configured to allow 5s then any longer timeout on the client side is moot - the server will have already hung up on it at 5s or whatever.

You're right, I tried switching to a different HTTP server and got the result I wanted