@@ -345,18 +345,18 @@ static int s_aws_s3_mmap_part_streaming_input_stream_get_status(
345345
346346static int s_aws_s3_mmap_part_streaming_input_stream_get_length (struct aws_input_stream * stream , int64_t * out_length ) {
347347 AWS_ASSERT (stream != NULL );
348- struct aws_s3_mmap_part_streaming_input_stream_impl * mmap_input_stream =
348+ struct aws_s3_mmap_part_streaming_input_stream_impl * impl =
349349 AWS_CONTAINER_OF (stream , struct aws_s3_mmap_part_streaming_input_stream_impl , base );
350- * out_length = (int64_t )mmap_input_stream -> total_length ;
350+ * out_length = (int64_t )impl -> total_length ;
351351 return AWS_OP_SUCCESS ;
352352}
353353
354354static void s_aws_s3_mmap_part_streaming_input_stream_destroy (
355- struct aws_s3_mmap_part_streaming_input_stream_impl * mmap_input_stream ) {
356- aws_parallel_input_stream_release (mmap_input_stream -> stream );
357- aws_byte_buf_clean_up (& mmap_input_stream -> chunk_buf_1 );
358- aws_byte_buf_clean_up (& mmap_input_stream -> chunk_buf_2 );
359- aws_mem_release (mmap_input_stream -> allocator , mmap_input_stream );
355+ struct aws_s3_mmap_part_streaming_input_stream_impl * impl ) {
356+ aws_parallel_input_stream_release (impl -> stream );
357+ aws_byte_buf_clean_up (& impl -> chunk_buf_1 );
358+ aws_byte_buf_clean_up (& impl -> chunk_buf_2 );
359+ aws_mem_release (impl -> allocator , impl );
360360}
361361
362362static struct aws_input_stream_vtable s_aws_s3_mmap_part_streaming_input_stream_vtable = {
@@ -367,9 +367,18 @@ static struct aws_input_stream_vtable s_aws_s3_mmap_part_streaming_input_stream_
367367};
368368
369369void aws_streaming_input_stream_reset (struct aws_input_stream * stream ) {
370- struct aws_s3_mmap_part_streaming_input_stream_impl * mmap_input_stream =
370+ struct aws_s3_mmap_part_streaming_input_stream_impl * impl =
371371 AWS_CONTAINER_OF (stream , struct aws_s3_mmap_part_streaming_input_stream_impl , base );
372- mmap_input_stream -> total_length_read = 0 ;
372+ impl -> total_length_read = 0 ;
373+ impl -> eos_loaded = false;
374+ impl -> eos_reached = false;
375+ impl -> in_chunk_offset = SIZE_MAX ;
376+ aws_byte_buf_reset (& impl -> chunk_buf_1 , false);
377+ aws_byte_buf_reset (& impl -> chunk_buf_2 , false);
378+ size_t new_load_length = aws_min_size (impl -> chunk_load_size , impl -> total_length );
379+ /* Start to load into the loading buffer. */
380+ impl -> loading_future =
381+ aws_parallel_input_stream_read (impl -> stream , impl -> offset , new_load_length , impl -> loading_chunk_buf );
373382}
374383
375384struct aws_input_stream * aws_input_stream_new_from_parallel_stream (
@@ -378,32 +387,26 @@ struct aws_input_stream *aws_input_stream_new_from_parallel_stream(
378387 uint64_t offset ,
379388 size_t request_body_size ) {
380389
381- struct aws_s3_mmap_part_streaming_input_stream_impl * mmap_input_stream =
390+ struct aws_s3_mmap_part_streaming_input_stream_impl * impl =
382391 aws_mem_calloc (allocator , 1 , sizeof (struct aws_s3_mmap_part_streaming_input_stream_impl ));
383392 aws_ref_count_init (
384- & mmap_input_stream -> base .ref_count ,
385- mmap_input_stream ,
393+ & impl -> base .ref_count ,
394+ impl ,
386395 (aws_simple_completion_callback * )s_aws_s3_mmap_part_streaming_input_stream_destroy );
387- mmap_input_stream -> allocator = allocator ;
388- mmap_input_stream -> base .vtable = & s_aws_s3_mmap_part_streaming_input_stream_vtable ;
389-
390- mmap_input_stream -> total_length = request_body_size ;
391- mmap_input_stream -> offset = offset ;
396+ impl -> allocator = allocator ;
397+ impl -> base .vtable = & s_aws_s3_mmap_part_streaming_input_stream_vtable ;
392398
393- mmap_input_stream -> in_chunk_offset = SIZE_MAX ;
394- mmap_input_stream -> chunk_load_size = 8 * 1024 * 1024 ;
399+ impl -> total_length = request_body_size ;
400+ impl -> offset = offset ;
401+ impl -> chunk_load_size = 8 * 1024 * 1024 ;
395402
396- mmap_input_stream -> stream = aws_parallel_input_stream_acquire (stream );
397- aws_byte_buf_init (& mmap_input_stream -> chunk_buf_1 , allocator , mmap_input_stream -> chunk_load_size );
398- aws_byte_buf_init (& mmap_input_stream -> chunk_buf_2 , allocator , mmap_input_stream -> chunk_load_size );
403+ impl -> stream = aws_parallel_input_stream_acquire (stream );
404+ aws_byte_buf_init (& impl -> chunk_buf_1 , allocator , impl -> chunk_load_size );
405+ aws_byte_buf_init (& impl -> chunk_buf_2 , allocator , impl -> chunk_load_size );
406+ impl -> loading_chunk_buf = & impl -> chunk_buf_1 ;
407+ impl -> reading_chunk_buf = & impl -> chunk_buf_2 ;
399408
400- mmap_input_stream -> loading_chunk_buf = & mmap_input_stream -> chunk_buf_1 ;
401- mmap_input_stream -> reading_chunk_buf = & mmap_input_stream -> chunk_buf_2 ;
402- size_t new_load_length = aws_min_size (mmap_input_stream -> chunk_load_size , mmap_input_stream -> total_length );
403-
404- /* Start to load into the loading buffer. */
405- mmap_input_stream -> loading_future =
406- aws_parallel_input_stream_read (stream , offset , new_load_length , mmap_input_stream -> loading_chunk_buf );
407-
408- return & mmap_input_stream -> base ;
409+ /* Reset the input stream to start */
410+ aws_streaming_input_stream_reset (& impl -> base );
411+ return & impl -> base ;
409412}
0 commit comments