From feece3ce45e769660e36f9cd347f54003c95babf Mon Sep 17 00:00:00 2001 From: Eion Robb Date: Thu, 17 Jan 2019 22:15:06 +1300 Subject: Add a delay when re-requesting a url to not trigger rate-limiting --- steam-mobile/steam_connection.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/steam-mobile/steam_connection.c b/steam-mobile/steam_connection.c index 2f845c3..0bc3816 100644 --- a/steam-mobile/steam_connection.c +++ b/steam-mobile/steam_connection.c @@ -183,6 +183,17 @@ static void steam_update_cookies(SteamAccount *sa, const gchar *headers) } } +static gboolean +steam_connection_requeue_delay(gpointer data) +{ + SteamConnection *steamcon = data; + + if (steamcon && steamcon->sa && steamcon->sa->waiting_conns) + g_queue_push_head(steamcon->sa->waiting_conns, steamcon); + + return FALSE; +} + static void steam_connection_process_data(SteamConnection *steamcon) { gssize len; @@ -220,15 +231,16 @@ static void steam_connection_process_data(SteamConnection *steamcon) if (strstr(steamcon->rx_buf, "429 Too Many Requests")) { g_free(steamcon->rx_buf); steamcon->rx_buf = NULL; + steamcon->rx_len = 0; g_free(tmp); //We got rate-limited, try again SteamConnection *steamcon_dup = g_memdup(steamcon, sizeof(steamcon)); - steamcon_dup->request = steamcon->request; steamcon->request = NULL; - steamcon_dup->url = steamcon->url; steamcon->url = NULL; - steamcon_dup->hostname = steamcon->hostname; steamcon->hostname = NULL; + steamcon->request = NULL; + steamcon->url = NULL; + steamcon->hostname = NULL; - g_queue_push_head(steamcon->sa->waiting_conns, steamcon_dup); + purple_timeout_add_seconds(1, steam_connection_requeue_delay, steamcon_dup); return; } } -- cgit v1.2.3