return non zero if error */
| 401 | |
| 402 | /* return non zero if error */ |
| 403 | static int http_open_cnx(URLContext *h, AVDictionary **options) |
| 404 | { |
| 405 | HTTPAuthType cur_auth_type, cur_proxy_auth_type; |
| 406 | HTTPContext *s = h->priv_data; |
| 407 | int ret, conn_attempts = 1, auth_attempts = 0, redirects = 0; |
| 408 | int reconnect_delay = 0; |
| 409 | int reconnect_delay_total = 0; |
| 410 | uint64_t off; |
| 411 | char *cached; |
| 412 | |
| 413 | redo: |
| 414 | |
| 415 | cached = redirect_cache_get(s); |
| 416 | if (cached) { |
| 417 | if (redirects++ >= s->max_redirects) |
| 418 | return AVERROR(EIO); |
| 419 | |
| 420 | av_free(s->location); |
| 421 | s->location = av_strdup(cached); |
| 422 | if (!s->location) { |
| 423 | ret = AVERROR(ENOMEM); |
| 424 | goto fail; |
| 425 | } |
| 426 | goto redo; |
| 427 | } |
| 428 | |
| 429 | av_dict_copy(options, s->chained_options, 0); |
| 430 | |
| 431 | cur_auth_type = s->auth_state.auth_type; |
| 432 | cur_proxy_auth_type = s->auth_state.auth_type; |
| 433 | |
| 434 | off = s->off; |
| 435 | ret = http_open_cnx_internal(h, options); |
| 436 | if (ret < 0) { |
| 437 | if (!http_should_reconnect(s, ret) || |
| 438 | reconnect_delay > s->reconnect_delay_max || |
| 439 | (s->reconnect_max_retries >= 0 && conn_attempts > s->reconnect_max_retries) || |
| 440 | reconnect_delay_total > s->reconnect_delay_total_max) |
| 441 | goto fail; |
| 442 | |
| 443 | /* Both fields here are in seconds. */ |
| 444 | if (s->respect_retry_after && s->retry_after > 0) { |
| 445 | reconnect_delay = s->retry_after; |
| 446 | if (reconnect_delay > s->reconnect_delay_max) |
| 447 | goto fail; |
| 448 | s->retry_after = 0; |
| 449 | s->nb_retries++; |
| 450 | } |
| 451 | |
| 452 | av_log(h, AV_LOG_WARNING, "Will reconnect at %"PRIu64" in %d second(s).\n", off, reconnect_delay); |
| 453 | ret = ff_network_sleep_interruptible(1000U * 1000 * reconnect_delay, &h->interrupt_callback); |
| 454 | if (ret != AVERROR(ETIMEDOUT)) |
| 455 | goto fail; |
| 456 | reconnect_delay_total += reconnect_delay; |
| 457 | reconnect_delay = 1 + 2 * reconnect_delay; |
| 458 | s->nb_reconnects++; |
| 459 | conn_attempts++; |
| 460 |
no test coverage detected