Skip to content

Commit feafd62

Browse files
authored
feat: timeout is now 20 seconds. Users can now change the timeout length (#1208)
1 parent 142e67c commit feafd62

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

include/dpp/cluster.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ class DPP_EXPORT cluster {
202202
*/
203203
std::condition_variable terminating;
204204

205+
/**
206+
* @brief The time (in seconds) that a request is allowed to take.
207+
*/
208+
uint16_t request_timeout = 20;
209+
205210
/**
206211
* @brief Constructor for creating a cluster. All but the token are optional.
207212
* @param token The bot token to use for all HTTP commands and websocket connections
@@ -420,6 +425,15 @@ class DPP_EXPORT cluster {
420425
*/
421426
const shard_list& get_shards();
422427

428+
/**
429+
* @brief Sets the request timeout.
430+
*
431+
* @param timeout The length of time (in seconds) that requests are allowed to take. Default: 20.
432+
*
433+
* @return cluster& Reference to self for chaining.
434+
*/
435+
cluster& set_request_timeout(uint16_t timeout);
436+
423437
/* Functions for attaching to event handlers */
424438

425439
/**

include/dpp/queues.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,10 @@ class DPP_EXPORT http_request {
296296

297297
/**
298298
* @brief How many seconds before the connection is considered failed if not finished
299+
*
300+
* @deprecated Please now use dpp::cluster::request_timeout
299301
*/
300-
time_t request_timeout;
302+
DPP_DEPRECATED("Please now use dpp::cluster::request_timeout") time_t request_timeout;
301303

302304
/**
303305
* @brief Constructor. When constructing one of these objects it should be passed to request_queue::post_request().

src/dpp/cluster.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,9 @@ const shard_list& cluster::get_shards() {
456456
return shards;
457457
}
458458

459+
cluster& cluster::set_request_timeout(uint16_t timeout) {
460+
request_timeout = timeout;
461+
return *this;
462+
}
463+
459464
};

src/dpp/queues.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ http_request_completion_t http_request::run(cluster* owner) {
176176
}
177177
http_connect_info hci = https_client::get_host_info(_host);
178178
try {
179-
https_client cli(hci.hostname, hci.port, _url, request_verb[method], multipart.body, headers, !hci.is_ssl, request_timeout, protocol);
179+
https_client cli(hci.hostname, hci.port, _url, request_verb[method], multipart.body, headers, !hci.is_ssl, owner->request_timeout, protocol);
180180
rv.latency = dpp::utility::time_f() - start;
181181
if (cli.timed_out) {
182182
rv.error = h_connection;

0 commit comments

Comments
 (0)