Type Definition libnghttp2_sys::nghttp2_send_data_callback
source · [−]pub type nghttp2_send_data_callback = Option<unsafe extern "C" fn(session: *mut nghttp2_session, frame: *mut nghttp2_frame, framehd: *const u8, length: usize, source: *mut nghttp2_data_source, user_data: *mut c_void) -> c_int>;
Expand description
@functypedef
Callback function invoked when :enum:NGHTTP2_DATA_FLAG_NO_COPY
is
used in :type:nghttp2_data_source_read_callback
to send complete
DATA frame.
The |frame| is a DATA frame to send. The |framehd| is the
serialized frame header (9 bytes). The |length| is the length of
application data to send (this does not include padding). The
|source| is the same pointer passed to
:type:nghttp2_data_source_read_callback
.
The application first must send frame header |framehd| of length 9
bytes. If frame->data.padlen > 0
, send 1 byte of value
frame->data.padlen - 1
. Then send exactly |length| bytes of
application data. Finally, if frame->data.padlen > 1
, send
frame->data.padlen - 1
bytes of zero as padding.
The application has to send complete DATA frame in this callback. If all data were written successfully, return 0.
If it cannot send any data at all, just return
:enum:NGHTTP2_ERR_WOULDBLOCK
; the library will call this callback
with the same parameters later (It is recommended to send complete
DATA frame at once in this function to deal with error; if partial
frame data has already sent, it is impossible to send another data
in that state, and all we can do is tear down connection). When
data is fully processed, but application wants to make
nghttp2_session_mem_send()
or nghttp2_session_send()
return
immediately without processing next frames, return
:enum:NGHTTP2_ERR_PAUSE
. If application decided to reset this
stream, return :enum:NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE
, then
the library will send RST_STREAM with INTERNAL_ERROR as error code.
The application can also return
:enum:NGHTTP2_ERR_CALLBACK_FAILURE
, which will result in
connection closure. Returning any other value is treated as
:enum:NGHTTP2_ERR_CALLBACK_FAILURE
is returned.