From be6fc14981534c13fda2f753ff99d0c7408a28de Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Mon, 9 Sep 2024 09:32:26 +0800 Subject: [PATCH] change curl_get failed behavior --- main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 19b2212..61927b5 100644 --- a/main.c +++ b/main.c @@ -104,10 +104,7 @@ CURLcode curl_get(const char *const url, struct memory *chunk) status = curl_easy_perform(curl); if (status != CURLE_OK) - { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(status)); - exit(status); - } curl_easy_cleanup(curl); curl_slist_free_all(headers); @@ -146,7 +143,9 @@ char *get_enc() const cJSON *enc = NULL; REGEN_ENC_URL_F(url, current_timestamp()); - curl_get(url, &data); + + if (curl_get(url, &data) != CURLE_OK) + return NULL; DPRINT("%s\n", data.response); @@ -171,13 +170,16 @@ void parise(void *arg) { char url[200]; struct memory json_c = {0}; - const char *enc = get_enc(); + const char *enc = NULL; const cJSON *result = NULL; const cJSON *msg = NULL; const cJSON *data = NULL; const cJSON *errorMsg = NULL; cJSON *json = NULL; + if ((enc = get_enc()) == NULL) + continue; + REGEN_URL_F(url, enc, current_timestamp()); curl_get(url, &json_c);