Skip to content

Commit 22c1cdc

Browse files
View request response time.
Added Response Time For Req function
2 parents 7d7f9fc + 81fcdc7 commit 22c1cdc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

auth.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <stdexcept>
3838
#include <string>
3939
#include <array>
40+
#include <chrono>
4041

4142
#include <functional>
4243
#include <vector>
@@ -1085,6 +1086,7 @@ std::string get_str_between_two_str(const std::string& s,
10851086
}
10861087

10871088
std::string KeyAuth::api::req(std::string data, std::string url) {
1089+
auto timestart = std::chrono::high_resolution_clock::now();
10881090
CURL* curl = curl_easy_init();
10891091
if (!curl)
10901092
return XorStr("null");
@@ -1113,6 +1115,8 @@ std::string KeyAuth::api::req(std::string data, std::string url) {
11131115
if (code != CURLE_OK)
11141116
error(curl_easy_strerror(code));
11151117

1118+
auto timeend = std::chrono::high_resolution_clock::now();
1119+
KeyAuth::api::data.responsetime = std::chrono::duration_cast<std::chrono::milliseconds>(timestart - timeend).count();
11161120
return to_return;
11171121
}
11181122
void error(std::string message) {

auth.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace KeyAuth {
4646
std::string expiry;
4747
};
4848

49-
class data_class {
49+
static class data_class {
5050
public:
5151
// app data
5252
std::string numUsers;
@@ -67,12 +67,13 @@ namespace KeyAuth {
6767
std::vector<channel_struct> channeldata;
6868
bool success{};
6969
std::string message;
70+
int responsetime;
7071
};
7172
data_class data;
7273
private:
7374
std::string sessionid, enckey;
7475

75-
static std::string req(std::string data, std::string url);
76+
std::string req(std::string data, std::string url);
7677

7778
void load_user_data(nlohmann::json data) {
7879
api::data.username = data["username"];
@@ -122,7 +123,6 @@ namespace KeyAuth {
122123
api::data.channeldata.push_back(output);
123124
}
124125
}
125-
126126
nlohmann::json response_decoder;
127127

128128
};

0 commit comments

Comments
 (0)