@@ -14,14 +14,21 @@ AWS_PUSH_SANE_WARNING_LEVEL
1414
1515struct aws_byte_buf ;
1616struct aws_future_bool ;
17+ struct aws_future_void ;
1718struct aws_input_stream ;
19+ struct aws_s3_meta_request ;
20+ struct aws_s3_request ;
1821
1922struct aws_event_loop_group ;
2023
24+ /**
25+ * This should be private, but keep it public for providing your own implementation.
26+ */
2127struct aws_parallel_input_stream {
2228 const struct aws_parallel_input_stream_vtable * vtable ;
2329 struct aws_allocator * alloc ;
2430 struct aws_ref_count ref_count ;
31+ struct aws_future_void * shutdown_future ;
2532
2633 void * impl ;
2734};
@@ -33,11 +40,27 @@ struct aws_parallel_input_stream_vtable {
3340 void (* destroy )(struct aws_parallel_input_stream * stream );
3441
3542 /**
36- * Read into the buffer in parallel.
37- * The implementation needs to support this to be invoked concurrently from multiple threads
43+ * Read from the offset until fill the dest, or EOF reached.
44+ * It's thread safe to be called from multiple threads without waiting for other read to complete
45+ *
46+ * @param stream The stream to read from
47+ * @param offset The offset in the stream from beginning to start reading
48+ * @param max_length The maximum number of bytes to read
49+ * @param dest The output buffer read to
50+ * @return a future, which will contain an error code if something went wrong,
51+ * or a result bool indicating whether EOF has been reached.
3852 */
3953 struct aws_future_bool * (
40- * read )(struct aws_parallel_input_stream * stream , uint64_t offset , struct aws_byte_buf * dest );
54+ * read )(struct aws_parallel_input_stream * stream , uint64_t offset , size_t max_length , struct aws_byte_buf * dest );
55+
56+ /**
57+ * Get the length of the stream.
58+ *
59+ * @param stream The stream to get length from
60+ * @param out_length The output length
61+ * @return AWS_OP_SUCCESS if success, otherwise AWS_OP_ERR
62+ */
63+ int (* get_length )(struct aws_parallel_input_stream * stream , int64_t * out_length );
4164};
4265
4366AWS_EXTERN_C_BEGIN
@@ -74,6 +97,7 @@ struct aws_parallel_input_stream *aws_parallel_input_stream_release(struct aws_p
7497 *
7598 * @param stream The stream to read from
7699 * @param offset The offset in the stream from beginning to start reading
100+ * @param max_length The maximum number of bytes to read
77101 * @param dest The output buffer read to
78102 * @return a future, which will contain an error code if something went wrong,
79103 * or a result bool indicating whether EOF has been reached.
@@ -82,22 +106,51 @@ AWS_S3_API
82106struct aws_future_bool * aws_parallel_input_stream_read (
83107 struct aws_parallel_input_stream * stream ,
84108 uint64_t offset ,
109+ size_t max_length ,
85110 struct aws_byte_buf * dest );
86111
87112/**
88- * Create a new file based parallel input stream.
113+ * Get the total length of the parallel input stream.
89114 *
90- * This implementation will open a file handler when the read happens, and seek to the offset to start reading. Close
91- * the file handler as read finishes.
115+ * @param stream
116+ * @param out_length
117+ * @return AWS_S3_API
118+ */
119+ AWS_S3_API
120+ int aws_parallel_input_stream_get_length (struct aws_parallel_input_stream * stream , int64_t * out_length );
121+
122+ /**
123+ * Creates a new parallel input stream that reads from a file.
124+ * This stream uses an event loop group to perform file I/O operations asynchronously.
125+ *
126+ * Notes for direct_io_read:
127+ * - checking `aws_file_path_read_from_offset_direct_io` for detail
128+ * - For `AWS_ERROR_UNSUPPORTED_OPERATION`, fallback to reading with cache with warnings, instead of fail.
129+ * - If alignment required, it's callers' responsibility to align with the page size.
92130 *
93- * @param allocator memory allocator
94- * @param file_name The file path to read from
95- * @return aws_parallel_input_stream
131+ * @param allocator The allocator to use for memory allocation
132+ * @param file_name The name of the file to read from
133+ * @param reading_elg The event loop group to use for file I/O operations
134+ * @param direct_io_read Whether to use direct I/O for reading the file.
135+ *
136+ * @return A new parallel input stream that reads from the specified file
96137 */
97138AWS_S3_API
98139struct aws_parallel_input_stream * aws_parallel_input_stream_new_from_file (
99140 struct aws_allocator * allocator ,
100- struct aws_byte_cursor file_name );
141+ struct aws_byte_cursor file_name ,
142+ struct aws_event_loop_group * reading_elg ,
143+ bool direct_io_read );
144+
145+ /**
146+ * Get the shutdown future from the parallel input stream.
147+ * The future will be completed when every refcount on the stream has been released.
148+ * And all the resource has been released.
149+ * Don't hold any refcount of the stream while waiting on the future, otherwise, deadlock can happen.
150+ * You need to release the future after using it.
151+ */
152+ AWS_S3_API
153+ struct aws_future_void * aws_parallel_input_stream_get_shutdown_future (struct aws_parallel_input_stream * stream );
101154
102155AWS_EXTERN_C_END
103156AWS_POP_SANE_WARNING_LEVEL
0 commit comments