Skip to content

set_connection_timeout() unexpected results #1878

@Yimyom3

Description

@Yimyom3

I verified that the connection timeout was accurate by getting the timestamp of the remote service, here is my code:

#include <iostream>
#include "httplib.h"
using namespace std;
using namespace httplib;

long long Get_Server_Time()
{
    auto url = ("http://api.pinduoduo.com");
    Client cli(url);
    auto res = cli.Get("/api/server/_stm");
    string content = res->body;
    smatch match;
    regex_search(content, match, regex("\\d+"));
    long long result = stoll(match[0]);
    return result;
}

int main()
{
    long long T1 = Get_Server_Time();
    Client X("http://www.baidu.com:9999");
    X.set_connection_timeout(10, 0); 
    X.Get("/");
    long long T2 = Get_Server_Time();
    cout << "T1: " << T1 << endl;
    cout << "T2: " << T2 << endl;
    cout << T2 - T1 << endl;
    return 0;
}

The expected timeout is 10 seconds, but the actual result does not match the expectation.
The result of running on my arm64 win11 and macOS is

T1: 1720509275196
T2: 1720509295308
20112

T1: 1720512589129
T2: 1720512609233
20104
image image

The results of running on the other two amd64 win11 machines are

T1:1720511647341
T2:1720511687532
40191

T1:1720512744571
T2:1720512824922
80351
image image

None of the results were as expected,I want to know what caused this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions