mirror of
https://github.com/nghttp2/nghttp2.git
synced 2025-12-08 11:08:52 +08:00
nghttp2_data_source_read_callback: Replace eof with uint32_t *data_flags
Replace int *eof with uint32_t *data_flags so that we can easily extend functionality if we have to (but we don't do if possible).
This commit is contained in:
@@ -621,6 +621,23 @@ typedef union {
|
||||
void *ptr;
|
||||
} nghttp2_data_source;
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* The flags used to set in |data_flags| output parameter in
|
||||
* :type:`nghttp2_data_source_read_callback`.
|
||||
*/
|
||||
typedef enum {
|
||||
/**
|
||||
* No flag set.
|
||||
*/
|
||||
NGHTTP2_DATA_FLAG_NONE = 0,
|
||||
/**
|
||||
* Indicates EOF was sensed.
|
||||
*/
|
||||
NGHTTP2_DATA_FLAG_EOF = 0x01
|
||||
} nghttp2_data_flag;
|
||||
|
||||
/**
|
||||
* @functypedef
|
||||
*
|
||||
@@ -629,21 +646,22 @@ typedef union {
|
||||
* implementation of this function must read at most |length| bytes of
|
||||
* data from |source| (or possibly other places) and store them in
|
||||
* |buf| and return number of data stored in |buf|. If EOF is reached,
|
||||
* set |*eof| to 1. If the application wants to postpone DATA frames,
|
||||
* (e.g., asynchronous I/O, or reading data blocks for long time), it
|
||||
* is achieved by returning :enum:`NGHTTP2_ERR_DEFERRED` without
|
||||
* reading any data in this invocation. The library removes DATA
|
||||
* frame from the outgoing queue temporarily. To move back deferred
|
||||
* DATA frame to outgoing queue, call `nghttp2_session_resume_data()`.
|
||||
* In case of error, there are 2 choices. Returning
|
||||
* :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will close the stream
|
||||
* by issuing RST_STREAM with :enum:`NGHTTP2_INTERNAL_ERROR`.
|
||||
* Returning :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the
|
||||
* entire session failure.
|
||||
* set :enum:`NGHTTP2_DATA_FLAG_EOF` flag in |*data_falgs|. If the
|
||||
* application wants to postpone DATA frames, (e.g., asynchronous I/O,
|
||||
* or reading data blocks for long time), it is achieved by returning
|
||||
* :enum:`NGHTTP2_ERR_DEFERRED` without reading any data in this
|
||||
* invocation. The library removes DATA frame from the outgoing queue
|
||||
* temporarily. To move back deferred DATA frame to outgoing queue,
|
||||
* call `nghttp2_session_resume_data()`. In case of error, there are
|
||||
* 2 choices. Returning :enum:`NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`
|
||||
* will close the stream by issuing RST_STREAM with
|
||||
* :enum:`NGHTTP2_INTERNAL_ERROR`. Returning
|
||||
* :enum:`NGHTTP2_ERR_CALLBACK_FAILURE` will signal the entire session
|
||||
* failure.
|
||||
*/
|
||||
typedef ssize_t (*nghttp2_data_source_read_callback)
|
||||
(nghttp2_session *session, int32_t stream_id,
|
||||
uint8_t *buf, size_t length, int *eof,
|
||||
uint8_t *buf, size_t length, uint32_t *data_flags,
|
||||
nghttp2_data_source *source, void *user_data);
|
||||
|
||||
/**
|
||||
|
||||
@@ -5388,7 +5388,7 @@ int nghttp2_session_pack_data(nghttp2_session *session,
|
||||
nghttp2_private_data *frame)
|
||||
{
|
||||
ssize_t rv;
|
||||
int eof_flags;
|
||||
uint32_t data_flags;
|
||||
uint8_t flags;
|
||||
ssize_t payloadlen;
|
||||
ssize_t padded_payloadlen;
|
||||
@@ -5404,10 +5404,10 @@ int nghttp2_session_pack_data(nghttp2_session *session,
|
||||
/* Current max DATA length is less then buffer chunk size */
|
||||
assert(nghttp2_buf_avail(buf) >= (ssize_t)datamax);
|
||||
|
||||
eof_flags = 0;
|
||||
data_flags = NGHTTP2_DATA_FLAG_NONE;
|
||||
payloadlen = frame->data_prd.read_callback
|
||||
(session, frame->hd.stream_id, buf->pos, datamax,
|
||||
&eof_flags, &frame->data_prd.source, session->user_data);
|
||||
&data_flags, &frame->data_prd.source, session->user_data);
|
||||
|
||||
if(payloadlen == NGHTTP2_ERR_DEFERRED ||
|
||||
payloadlen == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) {
|
||||
@@ -5430,7 +5430,7 @@ int nghttp2_session_pack_data(nghttp2_session *session,
|
||||
frame->hd.flags &= (NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_SEGMENT);
|
||||
flags = NGHTTP2_FLAG_NONE;
|
||||
|
||||
if(eof_flags) {
|
||||
if(data_flags & NGHTTP2_DATA_FLAG_EOF) {
|
||||
frame->eof = 1;
|
||||
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
||||
flags |= NGHTTP2_FLAG_END_STREAM;
|
||||
|
||||
Reference in New Issue
Block a user