Skip to content

Commit

Permalink
feat: timeout is now 20 seconds. Users can now change the timeout length
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Jul 22, 2024
1 parent 4427d09 commit 601dd45
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
14 changes: 14 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ class DPP_EXPORT cluster {
*/
std::condition_variable terminating;

/**
* @brief The time (in seconds) that a request is allowed to take.
*/
uint16_t request_timeout = 10;

/**
* @brief Constructor for creating a cluster. All but the token are optional.
* @param token The bot token to use for all HTTP commands and websocket connections
Expand Down Expand Up @@ -420,6 +425,15 @@ class DPP_EXPORT cluster {
*/
const shard_list& get_shards();

/**
* @brief Sets the request timeout.
*
* @param timeout The length of time (in seconds) that requests are allowed to take. Default: 20.
*
* @return cluster& Reference to self for chaining.
*/
cluster& set_request_timeout(uint16_t timeout);

/* Functions for attaching to event handlers */

/**
Expand Down
4 changes: 3 additions & 1 deletion include/dpp/queues.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,10 @@ class DPP_EXPORT http_request {

/**
* @brief How many seconds before the connection is considered failed if not finished
*
* @deprecated Please now use dpp::cluster::request_timeout
*/
time_t request_timeout;
DPP_DEPRECATED("Please now use dpp::cluster::request_timeout") time_t request_timeout;

/**
* @brief Constructor. When constructing one of these objects it should be passed to request_queue::post_request().
Expand Down
5 changes: 5 additions & 0 deletions src/dpp/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,9 @@ const shard_list& cluster::get_shards() {
return shards;
}

cluster& cluster::set_request_timeout(uint16_t timeout) {
request_timeout = timeout;
return *this;
}

};
2 changes: 1 addition & 1 deletion src/dpp/queues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ http_request_completion_t http_request::run(cluster* owner) {
}
http_connect_info hci = https_client::get_host_info(_host);
try {
https_client cli(hci.hostname, hci.port, _url, request_verb[method], multipart.body, headers, !hci.is_ssl, request_timeout, protocol);
https_client cli(hci.hostname, hci.port, _url, request_verb[method], multipart.body, headers, !hci.is_ssl, owner->request_timeout, protocol);
rv.latency = dpp::utility::time_f() - start;
if (cli.timed_out) {
rv.error = h_connection;
Expand Down

0 comments on commit 601dd45

Please sign in to comment.