| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <aws/common/ref_count.h> |
| 6 |
#include <aws/io/io.h> |
| 7 |
#include <aws/io/retry_strategy.h> |
| 8 |
|
| 9 |
struct aws_retry_strategy_no_retries { |
| 10 |
struct aws_retry_strategy base; |
| 11 |
struct aws_shutdown_callback_options shutdown_options; |
| 12 |
}; |
| 13 |
|
| 14 |
static void s_no_retry_destroy(struct aws_retry_strategy *retry_strategy) { |
| 15 |
if (retry_strategy) { |
| 16 |
struct aws_retry_strategy_no_retries *strategy = retry_strategy->impl; |
| 17 |
aws_simple_completion_callback *completion_callback = strategy->shutdown_options.shutdown_callback_fn; |
| 18 |
void *completion_user_data = strategy->shutdown_options.shutdown_callback_user_data; |
| 19 |
|
| 20 |
aws_mem_release(retry_strategy->allocator, strategy); |
| 21 |
if (completion_callback != NULL) { |
| 22 |
completion_callback(completion_user_data); |
| 23 |
} |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
static int s_no_retry_acquire_token( |
| 28 |
struct aws_retry_strategy *retry_strategy, |
| 29 |
const struct aws_byte_cursor *partition_id, |
| 30 |
aws_retry_strategy_on_retry_token_acquired_fn *on_acquired, |
| 31 |
void *user_data, |
| 32 |
uint64_t timeout_ms) { |
| 33 |
(void)retry_strategy; |
| 34 |
(void)partition_id; |
| 35 |
(void)on_acquired; |
| 36 |
(void)user_data; |
| 37 |
(void)timeout_ms; |
| 38 |
return aws_raise_error(AWS_IO_RETRY_PERMISSION_DENIED); |
| 39 |
} |
| 40 |
|
| 41 |
static int s_no_retry_schedule_retry( |
| 42 |
struct aws_retry_token *token, |
| 43 |
enum aws_retry_error_type error_type, |
| 44 |
aws_retry_strategy_on_retry_ready_fn *retry_ready, |
| 45 |
void *user_data) { |
| 46 |
(void)token; |
| 47 |
(void)error_type; |
| 48 |
(void)retry_ready; |
| 49 |
(void)user_data; |
| 50 |
AWS_FATAL_ASSERT(0 && "schedule_retry must not be called for no_retries retry strategy"); |
| 51 |
} |
| 52 |
|
| 53 |
static int s_no_retry_record_success(struct aws_retry_token *token) { |
| 54 |
(void)token; |
| 55 |
AWS_FATAL_ASSERT(0 && "record_success must not be called for no_retries retry strategy"); |
| 56 |
} |
| 57 |
|
| 58 |
static void s_no_retry_release_token(struct aws_retry_token *token) { |
| 59 |
(void)token; |
| 60 |
AWS_FATAL_ASSERT(0 && "release_token must not be called for no_retries retry strategy"); |
| 61 |
} |
| 62 |
|
| 63 |
static struct aws_retry_strategy_vtable s_exponential_retry_vtable = { |
| 64 |
.destroy = s_no_retry_destroy, |
| 65 |
.acquire_token = s_no_retry_acquire_token, |
| 66 |
.schedule_retry = s_no_retry_schedule_retry, |
| 67 |
.record_success = s_no_retry_record_success, |
| 68 |
.release_token = s_no_retry_release_token, |
| 69 |
}; |
| 70 |
|
| 71 |
struct aws_retry_strategy *aws_retry_strategy_new_no_retry( |
| 72 |
struct aws_allocator *allocator, |
| 73 |
const struct aws_no_retry_options *config) { |
| 74 |
struct aws_retry_strategy_no_retries *strategy = |
| 75 |
aws_mem_calloc(allocator, 1, sizeof(struct aws_retry_strategy_no_retries)); |
| 76 |
strategy->base.allocator = allocator; |
| 77 |
strategy->base.impl = strategy; |
| 78 |
strategy->base.vtable = &s_exponential_retry_vtable; |
| 79 |
aws_atomic_init_int(&strategy->base.ref_count, 1); |
| 80 |
|
| 81 |
if (config != NULL && config->shutdown_options) { |
| 82 |
strategy->shutdown_options = *config->shutdown_options; |
| 83 |
} |
| 84 |
return &strategy->base; |
| 85 |
} |