Function hyper::ffi::hyper_body_data

source ·
#[no_mangle]
pub extern "C" fn hyper_body_data(
    body: *mut hyper_body
) -> *mut hyper_task
Available on crate feature ffi and hyper_unstable_ffi only.
Expand description

Creates a task that will poll a response body for the next buffer of data.

The task may have different types depending on the outcome:

  • HYPER_TASK_BUF: Success, and more data was received.
  • HYPER_TASK_ERROR: An error retrieving the data.
  • HYPER_TASK_EMPTY: The body has finished streaming data.

When the application receives the task from hyper_executor_poll, if the task type is HYPER_TASK_BUF, it should cast the task to hyper_buf * and consume all the bytes in the buffer. Then the application should call hyper_body_data again for the same hyper_body *, to create a task for the next buffer of data. Repeat until the polled task type is HYPER_TASK_ERROR or HYPER_TASK_EMPTY.

To avoid a memory leak, the task must eventually be consumed by hyper_task_free, or taken ownership of by hyper_executor_push without subsequently being given back by hyper_executor_poll.

This does not consume the hyper_body *, so it may be used again. However, the hyper_body * MUST NOT be used or freed until the related task is returned from hyper_executor_poll.

For a more convenient method, see also hyper_body_foreach.