diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-02-09 21:25:27 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-02-09 21:25:27 +0100 |
commit | a8e20fe04d0ab35ab7a881f8a4ec72aa9d06b314 (patch) | |
tree | 6e46fb81962658f7533c84919c0616f7df65eecd /src | |
parent | 0f936b4aac6e9fa6c0304bca7aff2103cfd1f3d4 (diff) |
set curl timeout when long-polling
Diffstat (limited to 'src')
-rw-r--r-- | src/bank/mb_credit.c | 2 | ||||
-rw-r--r-- | src/lib/merchant_api_get_kyc.c | 17 | ||||
-rw-r--r-- | src/lib/merchant_api_get_orders.c | 24 | ||||
-rw-r--r-- | src/lib/merchant_api_merchant_get_order.c | 31 | ||||
-rw-r--r-- | src/lib/merchant_api_wallet_get_order.c | 41 |
5 files changed, 51 insertions, 64 deletions
diff --git a/src/bank/mb_credit.c b/src/bank/mb_credit.c index f7b09350..65c48ac8 100644 --- a/src/bank/mb_credit.c +++ b/src/bank/mb_credit.c @@ -308,7 +308,7 @@ TALER_MERCHANT_BANK_credit_history ( GNUNET_break (CURLE_OK == curl_easy_setopt (eh, CURLOPT_TIMEOUT_MS, - (long) tms)); + (long) (tms + 100L))); } hh->job = GNUNET_CURL_job_add2 (ctx, eh, diff --git a/src/lib/merchant_api_get_kyc.c b/src/lib/merchant_api_get_kyc.c index 2590745f..a9aabbe0 100644 --- a/src/lib/merchant_api_get_kyc.c +++ b/src/lib/merchant_api_get_kyc.c @@ -262,17 +262,19 @@ kyc_get (struct GNUNET_CURL_Context *ctx, struct TALER_MERCHANT_KycGetHandle *kyc; CURL *eh; char timeout_ms[32]; + unsigned int tms; kyc = GNUNET_new (struct TALER_MERCHANT_KycGetHandle); kyc->ctx = ctx; kyc->cb = cb; kyc->cb_cls = cb_cls; + tms = (unsigned int) (timeout.rel_value_us + / GNUNET_TIME_UNIT_MILLISECONDS. + rel_value_us); GNUNET_snprintf (timeout_ms, sizeof (timeout_ms), - "%llu", - (unsigned long long) (timeout.rel_value_us - / GNUNET_TIME_UNIT_MILLISECONDS. - rel_value_us)); + "%u", + tms); kyc->url = TALER_url_join (url, "kyc", "h_wire", @@ -300,6 +302,13 @@ kyc_get (struct GNUNET_CURL_Context *ctx, "Requesting URL '%s'\n", kyc->url); eh = TALER_MERCHANT_curl_easy_get_ (kyc->url); + if (0 != tms) + { + GNUNET_break (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_TIMEOUT_MS, + (long) (tms + 100L))); + } kyc->job = GNUNET_CURL_job_add (ctx, eh, &handle_get_kyc_finished, diff --git a/src/lib/merchant_api_get_orders.c b/src/lib/merchant_api_get_orders.c index ecddc455..af2b46d9 100644 --- a/src/lib/merchant_api_get_orders.c +++ b/src/lib/merchant_api_get_orders.c @@ -271,8 +271,8 @@ TALER_MERCHANT_orders_get3 ( { struct TALER_MERCHANT_OrdersGetHandle *ogh; CURL *eh; - unsigned int timeout_ms = timeout.rel_value_us - / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us; + unsigned int tms = timeout.rel_value_us + / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us; GNUNET_assert (NULL != backend_url); if (0 == delta) @@ -298,8 +298,8 @@ TALER_MERCHANT_orders_get3 ( GNUNET_snprintf (tbuf, sizeof (tbuf), - "%llu", - (unsigned long long) timeout_ms); + "%u", + tms); GNUNET_snprintf (dbuf, sizeof (dbuf), "%lld", @@ -354,7 +354,7 @@ TALER_MERCHANT_orders_get3 ( ? dbuf : NULL, "timeout_ms", - (0 != timeout_ms) + (0 != tms) ? tbuf : NULL, "session_id", @@ -377,6 +377,20 @@ TALER_MERCHANT_orders_get3 ( "Requesting URL '%s'\n", ogh->url); eh = TALER_MERCHANT_curl_easy_get_ (ogh->url); + if (NULL == eh) + { + GNUNET_break (0); + GNUNET_free (ogh->url); + GNUNET_free (ogh); + return NULL; + } + if (0 != tms) + { + GNUNET_break (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_TIMEOUT_MS, + (long) (tms + 100L))); + } ogh->job = GNUNET_CURL_job_add (ctx, eh, &handle_get_orders_finished, diff --git a/src/lib/merchant_api_merchant_get_order.c b/src/lib/merchant_api_merchant_get_order.c index 9f10c347..f410ee50 100644 --- a/src/lib/merchant_api_merchant_get_order.c +++ b/src/lib/merchant_api_merchant_get_order.c @@ -409,17 +409,10 @@ TALER_MERCHANT_merchant_order_get (struct GNUNET_CURL_Context *ctx, void *cb_cls) { struct TALER_MERCHANT_OrderMerchantGetHandle *omgh; - unsigned long long tms; - long tlong; - - tms = (unsigned long long) (timeout.rel_value_us - / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us); - /* set curl timeout to *our* long poll timeout plus one minute - (for network latency and processing delays) */ - tlong = (long) (GNUNET_TIME_relative_add (timeout, - GNUNET_TIME_UNIT_MINUTES). - rel_value_us - / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us); + unsigned int tms; + + tms = (unsigned int) (timeout.rel_value_us + / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us); omgh = GNUNET_new (struct TALER_MERCHANT_OrderMerchantGetHandle); omgh->ctx = ctx; omgh->cb = cb; @@ -430,7 +423,7 @@ TALER_MERCHANT_merchant_order_get (struct GNUNET_CURL_Context *ctx, GNUNET_snprintf (timeout_ms, sizeof (timeout_ms), - "%llu", + "%u", tms); GNUNET_asprintf (&path, "private/orders/%s", @@ -461,16 +454,12 @@ TALER_MERCHANT_merchant_order_get (struct GNUNET_CURL_Context *ctx, GNUNET_free (omgh); return NULL; } - if (CURLE_OK != - curl_easy_setopt (eh, - CURLOPT_TIMEOUT_MS, - tlong)) + if (0 != tms) { - GNUNET_break (0); - curl_easy_cleanup (eh); - GNUNET_free (omgh->url); - GNUNET_free (omgh); - return NULL; + GNUNET_break (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_TIMEOUT_MS, + (long) (tms + 100L))); } GNUNET_log (GNUNET_ERROR_TYPE_INFO, diff --git a/src/lib/merchant_api_wallet_get_order.c b/src/lib/merchant_api_wallet_get_order.c index b0a4d9b9..763b2c83 100644 --- a/src/lib/merchant_api_wallet_get_order.c +++ b/src/lib/merchant_api_wallet_get_order.c @@ -205,8 +205,7 @@ TALER_MERCHANT_wallet_order_get ( void *cb_cls) { struct TALER_MERCHANT_OrderWalletGetHandle *owgh; - unsigned long long tms; - long tlong; + unsigned int tms; GNUNET_assert (NULL != backend_url); GNUNET_assert (NULL != order_id); @@ -214,14 +213,8 @@ TALER_MERCHANT_wallet_order_get ( owgh->ctx = ctx; owgh->cb = cb; owgh->cb_cls = cb_cls; - tms = (unsigned long long) (timeout.rel_value_us - / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us); - /* set curl timeout to *our* long poll timeout plus one minute - (for network latency and processing delays) */ - tlong = (long) (GNUNET_TIME_relative_add (timeout, - GNUNET_TIME_UNIT_MINUTES). - rel_value_us - / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us); + tms = (unsigned int) (timeout.rel_value_us + / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us); { char timeout_ms[32]; struct GNUNET_CRYPTO_HashAsciiEncoded h_contract_s; @@ -231,7 +224,7 @@ TALER_MERCHANT_wallet_order_get ( &h_contract_s); GNUNET_snprintf (timeout_ms, sizeof (timeout_ms), - "%llu", + "%u", tms); GNUNET_asprintf (&path, "orders/%s", @@ -271,28 +264,10 @@ TALER_MERCHANT_wallet_order_get ( eh = TALER_MERCHANT_curl_easy_get_ (owgh->url); if (0 != tms) { - if (CURLE_OK != - curl_easy_setopt (eh, - CURLOPT_TIMEOUT_MS, - (long) tms)) - { - GNUNET_break (0); - curl_easy_cleanup (eh); - GNUNET_free (owgh->url); - GNUNET_free (owgh); - return NULL; - } - } - if (CURLE_OK != - curl_easy_setopt (eh, - CURLOPT_TIMEOUT_MS, - tlong)) - { - GNUNET_break (0); - curl_easy_cleanup (eh); - GNUNET_free (owgh->url); - GNUNET_free (owgh); - return NULL; + GNUNET_break (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_TIMEOUT_MS, + (long) (tms + 100L))); } GNUNET_log (GNUNET_ERROR_TYPE_INFO, |