| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include "aws/s3/private/s3_parallel_input_stream.h" |
| 7 |
#include "s3_tester.h" |
| 8 |
#include <aws/common/atomics.h> |
| 9 |
|
| 10 |
struct aws_parallel_input_stream_from_file_failure_impl { |
| 11 |
struct aws_parallel_input_stream base; |
| 12 |
|
| 13 |
struct aws_atomic_var number_read; |
| 14 |
}; |
| 15 |
|
| 16 |
static void s_para_from_file_failure_destroy(struct aws_parallel_input_stream *stream) { |
| 17 |
struct aws_parallel_input_stream_from_file_failure_impl *impl = |
| 18 |
AWS_CONTAINER_OF(stream, struct aws_parallel_input_stream_from_file_failure_impl, base); |
| 19 |
|
| 20 |
aws_future_void_set_result(stream->shutdown_future); |
| 21 |
aws_future_void_release(stream->shutdown_future); |
| 22 |
aws_mem_release(stream->alloc, impl); |
| 23 |
} |
| 24 |
|
| 25 |
struct aws_future_bool *s_para_from_file_failure_read( |
| 26 |
struct aws_parallel_input_stream *stream, |
| 27 |
uint64_t offset, |
| 28 |
size_t max_length, |
| 29 |
struct aws_byte_buf *dest) { |
| 30 |
|
| 31 |
(void)offset; |
| 32 |
(void)max_length; |
| 33 |
|
| 34 |
struct aws_future_bool *future = aws_future_bool_new(stream->alloc); |
| 35 |
struct aws_parallel_input_stream_from_file_failure_impl *impl = |
| 36 |
AWS_CONTAINER_OF(stream, struct aws_parallel_input_stream_from_file_failure_impl, base); |
| 37 |
|
| 38 |
size_t previous_number_read = aws_atomic_fetch_add(&impl->number_read, 1); |
| 39 |
if (previous_number_read == 1) { |
| 40 |
|
| 41 |
aws_future_bool_set_error(future, AWS_ERROR_UNIMPLEMENTED); |
| 42 |
} else { |
| 43 |
struct aws_byte_cursor test_string = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("This is an S3 test."); |
| 44 |
while (dest->len < dest->capacity) { |
| 45 |
size_t remaining_in_buffer = dest->capacity - dest->len; |
| 46 |
if (remaining_in_buffer < test_string.len) { |
| 47 |
test_string.len = remaining_in_buffer; |
| 48 |
} |
| 49 |
aws_byte_buf_append(dest, &test_string); |
| 50 |
} |
| 51 |
aws_future_bool_set_result(future, true); |
| 52 |
} |
| 53 |
return future; |
| 54 |
} |
| 55 |
|
| 56 |
static struct aws_parallel_input_stream_vtable s_parallel_input_stream_from_file_failure_vtable = { |
| 57 |
.destroy = s_para_from_file_failure_destroy, |
| 58 |
.read = s_para_from_file_failure_read, |
| 59 |
}; |
| 60 |
|
| 61 |
struct aws_parallel_input_stream *aws_parallel_input_stream_new_from_file_failure_tester( |
| 62 |
struct aws_allocator *allocator, |
| 63 |
struct aws_byte_cursor file_name, |
| 64 |
struct aws_event_loop_group *reading_elg, |
| 65 |
bool direct_io_read) { |
| 66 |
(void)file_name; |
| 67 |
(void)reading_elg; |
| 68 |
(void)direct_io_read; |
| 69 |
|
| 70 |
struct aws_parallel_input_stream_from_file_failure_impl *impl = |
| 71 |
aws_mem_calloc(allocator, 1, sizeof(struct aws_parallel_input_stream_from_file_failure_impl)); |
| 72 |
aws_parallel_input_stream_init_base( |
| 73 |
&impl->base, allocator, &s_parallel_input_stream_from_file_failure_vtable, impl); |
| 74 |
|
| 75 |
aws_atomic_init_int(&impl->number_read, 0); |
| 76 |
return &impl->base; |
| 77 |
} |