From 0c62539a69169a11afa42074dacd2d2de8de8f9b Mon Sep 17 00:00:00 2001 From: SavinSA Date: Mon, 20 May 2024 01:51:18 +0300 Subject: [PATCH] code: added connection timer --- main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.cpp b/main.cpp index e1bfe89..b1636b0 100644 --- a/main.cpp +++ b/main.cpp @@ -67,6 +67,7 @@ download(const string& address) { CURL* curl = curl_easy_init(); if (curl) { CURLcode res; + curl_off_t connect; curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); @@ -75,6 +76,12 @@ download(const string& address) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); exit(1); } + if (CURLE_OK == res) { + res = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME_T, &connect); + if (CURLE_OK == res) { + fprintf(stderr, "connection time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", connect / 1000000, (long)(connect % 1000000)); + } + } curl_easy_cleanup(curl); } return input_data(buffer, false);