Commit cf7da385 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Define flags separately for control and data frames.

parent 946e6f41
......@@ -74,10 +74,15 @@ typedef enum {
} spdylay_frame_type;
typedef enum {
SPDYLAY_FLAG_NONE = 0,
SPDYLAY_FLAG_FIN = 1,
SPDYLAY_FLAG_UNIDIRECTIONAL = 2
} spdylay_flag;
SPDYLAY_CTRL_FLAG_NONE = 0,
SPDYLAY_CTRL_FLAG_FIN = 0x1,
SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL = 0x2
} spdylay_ctrl_flag;
typedef enum {
SPDYLAY_DATA_FLAG_NONE = 0,
SPDYLAY_DATA_FLAG_FIN = 0x1
} spdylay_data_flag;
typedef enum {
SPDYLAY_FLAG_SETTINGS_NONE = 0,
......@@ -271,10 +276,9 @@ typedef void (*spdylay_on_invalid_ctrl_recv_callback)
* Callback function invoked when data chunk of DATA frame is
* received. |stream_id| is the stream ID of this DATA frame belongs
* to. |flags| is the flags of DATA frame which this data chunk is
* contained. flags & SPDYLAY_FLAG_FIN does not necessarily mean this
* chunk of data is the last one in the stream. You should use
* spdylay_on_data_recv_callback to know all data frame is received
* whose flags contains SPDYLAY_FLAG_FIN.
* contained. flags & SPDYLAY_DATA_FLAG_FIN does not necessarily mean
* this chunk of data is the last one in the stream. You should use
* spdylay_on_data_recv_callback to know all data frames are received.
*/
typedef void (*spdylay_on_data_chunk_recv_callback)
(spdylay_session *session, uint8_t flags, int32_t stream_id,
......@@ -515,10 +519,11 @@ int spdylay_submit_response(spdylay_session *session,
* Submits SYN_STREAM frame. The |flags| is bitwise OR of the
* following values:
*
* SPDYLAY_FLAG_FIN
* SPDYLAY_FLAG_UNIDIRECTIONAL
* SPDYLAY_CTRL_FLAG_FIN
* SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL
*
* If |flags| includes SPDYLAY_FLAG_FIN, this frame has FIN flag set.
* If |flags| includes SPDYLAY_CTRL_FLAG_FIN, this frame has FIN flag
* set.
*
* The |assoc_stream_id| is used for server-push. If |session| is
* initialized for client use, |assoc_stream_id| is ignored. The |pri|
......@@ -547,9 +552,10 @@ int spdylay_submit_syn_stream(spdylay_session *session, uint8_t flags,
* Submits HEADERS frame. The |flags| is bitwise OR of the following
* values:
*
* SPDYLAY_FLAG_FIN
* SPDYLAY_CTRL_FLAG_FIN
*
* If |flags| includes SPDYLAY_FLAG_FIN, this frame has FIN flag set.
* If |flags| includes SPDYLAY_CTRL_FLAG_FIN, this frame has FIN flag
* set.
*
* The stream this frame belongs to is given in |stream_id|. The |nv|
* is the name/value pairs in this frame.
......@@ -567,7 +573,7 @@ int spdylay_submit_headers(spdylay_session *session, uint8_t flags,
* Submits 1 or more DATA frames to the stream |stream_id|. The data
* to be sent are provided by |data_prd|. Depending on the length of
* data, 1 or more DATA frames will be sent. If |flags| contains
* SPDYLAY_FLAG_FIN, the last DATA frame has FLAG_FIN set.
* SPDYLAY_DATA_FLAG_FIN, the last DATA frame has FLAG_FIN set.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
......
......@@ -408,7 +408,7 @@ void spdylay_frame_ping_init(spdylay_ping *frame, uint32_t unique_id)
memset(frame, 0, sizeof(spdylay_ping));
frame->hd.version = SPDYLAY_PROTO_VERSION;
frame->hd.type = SPDYLAY_PING;
frame->hd.flags = SPDYLAY_FLAG_NONE;
frame->hd.flags = SPDYLAY_CTRL_FLAG_NONE;
frame->hd.length = 4;
frame->unique_id = unique_id;
}
......
......@@ -715,7 +715,7 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
session->callbacks.on_data_send_callback
(session,
frame->data.eof ? frame->data.flags :
(frame->data.flags & (~SPDYLAY_FLAG_FIN)),
(frame->data.flags & (~SPDYLAY_DATA_FLAG_FIN)),
frame->data.stream_id,
session->aob.framebuflen-SPDYLAY_HEAD_LEN, session->user_data);
}
......@@ -732,10 +732,10 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
if(stream) {
spdylay_syn_stream_aux_data *aux_data;
stream->state = SPDYLAY_STREAM_OPENING;
if(frame->syn_stream.hd.flags & SPDYLAY_FLAG_FIN) {
if(frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_WR);
}
if(frame->syn_stream.hd.flags & SPDYLAY_FLAG_UNIDIRECTIONAL) {
if(frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) {
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD);
}
spdylay_session_close_stream_if_shut_rdwr(session, stream);
......@@ -745,7 +745,7 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
int r;
/* spdylay_submit_data() makes a copy of aux_data->data_prd */
r = spdylay_submit_data(session, frame->syn_stream.stream_id,
SPDYLAY_FLAG_FIN, aux_data->data_prd);
SPDYLAY_DATA_FLAG_FIN, aux_data->data_prd);
if(r != 0) {
/* FATAL error */
assert(r < SPDYLAY_ERR_FATAL);
......@@ -761,7 +761,7 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
spdylay_session_get_stream(session, frame->syn_reply.stream_id);
if(stream) {
stream->state = SPDYLAY_STREAM_OPENED;
if(frame->syn_reply.hd.flags & SPDYLAY_FLAG_FIN) {
if(frame->syn_reply.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_WR);
}
spdylay_session_close_stream_if_shut_rdwr(session, stream);
......@@ -771,7 +771,7 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
(spdylay_data_provider*)item->aux_data;
int r;
r = spdylay_submit_data(session, frame->syn_reply.stream_id,
SPDYLAY_FLAG_FIN, data_prd);
SPDYLAY_DATA_FLAG_FIN, data_prd);
if(r != 0) {
/* FATAL error */
assert(r < SPDYLAY_ERR_FATAL);
......@@ -811,7 +811,7 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
spdylay_stream *stream =
spdylay_session_get_stream(session, frame->headers.stream_id);
if(stream) {
if(frame->headers.hd.flags & SPDYLAY_FLAG_FIN) {
if(frame->headers.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_WR);
}
spdylay_session_close_stream_if_shut_rdwr(session, stream);
......@@ -819,7 +819,7 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
break;
}
case SPDYLAY_DATA:
if(frame->data.eof && (frame->data.flags & SPDYLAY_FLAG_FIN)) {
if(frame->data.eof && (frame->data.flags & SPDYLAY_DATA_FLAG_FIN)) {
spdylay_stream *stream =
spdylay_session_get_stream(session, frame->data.stream_id);
if(stream) {
......@@ -1078,7 +1078,7 @@ static int spdylay_session_validate_syn_stream(spdylay_session *session,
a RST_STREAM with error code INVALID_STREAM. */
return SPDYLAY_INVALID_STREAM;
}
if((frame->hd.flags & SPDYLAY_FLAG_UNIDIRECTIONAL) == 0 ||
if((frame->hd.flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) == 0 ||
frame->assoc_stream_id % 2 == 0 ||
spdylay_session_get_stream(session, frame->assoc_stream_id) == NULL) {
/* It seems spdy/2 spec does not say which status code should be
......@@ -1133,7 +1133,8 @@ int spdylay_session_on_syn_stream_received(spdylay_session *session,
&frame->syn_stream);
if(status_code == 0) {
uint8_t flags = frame->syn_stream.hd.flags;
if((flags & SPDYLAY_FLAG_FIN) && (flags & SPDYLAY_FLAG_UNIDIRECTIONAL)) {
if((flags & SPDYLAY_CTRL_FLAG_FIN) &&
(flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL)) {
/* If the stream is UNIDIRECTIONAL and FIN bit set, we can close
stream upon receiving SYN_STREAM. So, the stream needs not to
be opened. */
......@@ -1145,24 +1146,24 @@ int spdylay_session_on_syn_stream_received(spdylay_session *session,
SPDYLAY_STREAM_OPENING,
NULL);
if(stream) {
if(flags & SPDYLAY_FLAG_FIN) {
if(flags & SPDYLAY_CTRL_FLAG_FIN) {
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD);
}
if(flags & SPDYLAY_FLAG_UNIDIRECTIONAL) {
if(flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) {
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_WR);
}
/* We don't call spdylay_session_close_stream_if_shut_rdwr()
here because either SPDYLAY_FLAG_FIN or
SPDYLAY_FLAG_UNIDIRECTIONAL is not set here. */
here because either SPDYLAY_CTRL_FLAG_FIN or
SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL is not set here. */
}
}
session->last_recv_stream_id = frame->syn_stream.stream_id;
spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_SYN_STREAM,
frame);
if(flags & SPDYLAY_FLAG_FIN) {
if(flags & SPDYLAY_CTRL_FLAG_FIN) {
spdylay_session_call_on_request_recv(session,
frame->syn_stream.stream_id);
if(flags & SPDYLAY_FLAG_UNIDIRECTIONAL) {
if(flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) {
/* Note that we call on_stream_close_callback without opening
stream. */
if(session->callbacks.on_stream_close_callback) {
......@@ -1199,7 +1200,7 @@ int spdylay_session_on_syn_reply_received(spdylay_session *session,
stream->state = SPDYLAY_STREAM_OPENED;
spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_SYN_REPLY,
frame);
if(frame->syn_reply.hd.flags & SPDYLAY_FLAG_FIN) {
if(frame->syn_reply.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
/* This is the last frame of this stream, so disallow
further receptions. */
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD);
......@@ -1303,7 +1304,7 @@ int spdylay_session_on_headers_received(spdylay_session *session,
valid = 1;
spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_HEADERS,
frame);
if(frame->headers.hd.flags & SPDYLAY_FLAG_FIN) {
if(frame->headers.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD);
spdylay_session_close_stream_if_shut_rdwr(session, stream);
}
......@@ -1322,7 +1323,7 @@ int spdylay_session_on_headers_received(spdylay_session *session,
if(stream->state != SPDYLAY_STREAM_CLOSING) {
spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_HEADERS,
frame);
if(frame->headers.hd.flags & SPDYLAY_FLAG_FIN) {
if(frame->headers.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
spdylay_session_call_on_request_recv(session,
frame->headers.stream_id);
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD);
......@@ -1516,12 +1517,12 @@ int spdylay_session_on_data_received(spdylay_session *session,
session->callbacks.on_data_recv_callback
(session, flags, stream_id, length, session->user_data);
}
if(flags & SPDYLAY_FLAG_FIN) {
if(flags & SPDYLAY_DATA_FLAG_FIN) {
spdylay_session_call_on_request_recv(session, stream_id);
}
}
if(valid) {
if(flags & SPDYLAY_FLAG_FIN) {
if(flags & SPDYLAY_DATA_FLAG_FIN) {
spdylay_stream_shutdown(stream, SPDYLAY_SHUT_RD);
spdylay_session_close_stream_if_shut_rdwr(session, stream);
}
......@@ -1754,8 +1755,8 @@ ssize_t spdylay_session_pack_data(spdylay_session *session,
flags = 0;
if(eof) {
frame->eof = 1;
if(frame->flags & SPDYLAY_FLAG_FIN) {
flags |= SPDYLAY_FLAG_FIN;
if(frame->flags & SPDYLAY_DATA_FLAG_FIN) {
flags |= SPDYLAY_DATA_FLAG_FIN;
}
}
(*buf_ptr)[4] = flags;
......
......@@ -224,14 +224,15 @@ int spdylay_session_add_goaway(spdylay_session *session,
/*
* Creates new stream in |session| with stream ID |stream_id|,
* priority |pri| and flags |flags|. SPDYLAY_FLAG_UNIDIRECTIONAL flag
* is set in |flags|, this stream is unidirectional. SPDYLAY_FLAG_FIN
* flag is set in |flags|, the sender of SYN_STREAM will not send any
* further data in this stream. Since this function is called when
* SYN_STREAM is sent or received, these flags are taken from
* SYN_STREAM. The state of stream is set to |initial_state|.
* |stream_user_data| is a pointer to the arbitrary user supplied data
* to be associated to this stream.
* priority |pri| and flags |flags|. SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL
* flag is set in |flags|, this stream is
* unidirectional. SPDYLAY_CTRL_FLAG_FIN flag is set in |flags|, the
* sender of SYN_STREAM will not send any further data in this
* stream. Since this function is called when SYN_STREAM is sent or
* received, these flags are taken from SYN_STREAM. The state of
* stream is set to |initial_state|. |stream_user_data| is a pointer
* to the arbitrary user supplied data to be associated to this
* stream.
*
* This function returns a pointer to created new stream object, or
* NULL.
......
......@@ -79,11 +79,11 @@ static int spdylay_submit_syn_stream_shared
spdylay_frame_nv_downcase(nv_copy);
spdylay_frame_nv_sort(nv_copy);
flags_copy = 0;
if(flags & SPDYLAY_FLAG_FIN) {
flags_copy |= SPDYLAY_FLAG_FIN;
if(flags & SPDYLAY_CTRL_FLAG_FIN) {
flags_copy |= SPDYLAY_CTRL_FLAG_FIN;
}
if(flags & SPDYLAY_FLAG_UNIDIRECTIONAL) {
flags_copy |= SPDYLAY_FLAG_UNIDIRECTIONAL;
if(flags & SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL) {
flags_copy |= SPDYLAY_CTRL_FLAG_UNIDIRECTIONAL;
}
spdylay_frame_syn_stream_init(&frame->syn_stream, flags_copy,
0, assoc_stream_id, pri, nv_copy);
......@@ -125,8 +125,8 @@ int spdylay_submit_headers(spdylay_session *session, uint8_t flags,
spdylay_frame_nv_downcase(nv_copy);
spdylay_frame_nv_sort(nv_copy);
flags_copy = 0;
if(flags & SPDYLAY_FLAG_FIN) {
flags_copy |= SPDYLAY_FLAG_FIN;
if(flags & SPDYLAY_CTRL_FLAG_FIN) {
flags_copy |= SPDYLAY_CTRL_FLAG_FIN;
}
spdylay_frame_headers_init(&frame->headers, flags_copy, stream_id, nv_copy);
r = spdylay_session_add_frame(session, SPDYLAY_HEADERS, frame, NULL);
......@@ -162,7 +162,7 @@ int spdylay_submit_request(spdylay_session *session, uint8_t pri,
int flags;
flags = 0;
if(data_prd == NULL || data_prd->read_callback == NULL) {
flags |= SPDYLAY_FLAG_FIN;
flags |= SPDYLAY_CTRL_FLAG_FIN;
}
return spdylay_submit_syn_stream_shared(session, flags, 0, pri, nv, data_prd,
stream_user_data);
......@@ -198,7 +198,7 @@ int spdylay_submit_response(spdylay_session *session,
spdylay_frame_nv_downcase(nv_copy);
spdylay_frame_nv_sort(nv_copy);
if(data_prd_copy == NULL) {
flags |= SPDYLAY_FLAG_FIN;
flags |= SPDYLAY_CTRL_FLAG_FIN;
}
spdylay_frame_syn_reply_init(&frame->syn_reply, flags, stream_id,
nv_copy);
......@@ -223,8 +223,8 @@ int spdylay_submit_data(spdylay_session *session, int32_t stream_id,
if(frame == NULL) {
return SPDYLAY_ERR_NOMEM;
}
if(flags & SPDYLAY_FLAG_FIN) {
nflags |= SPDYLAY_FLAG_FIN;
if(flags & SPDYLAY_DATA_FLAG_FIN) {
nflags |= SPDYLAY_DATA_FLAG_FIN;
}
spdylay_frame_data_init(&frame->data, stream_id, nflags, data_prd);
r = spdylay_session_add_frame(session, SPDYLAY_DATA, frame, NULL);
......
......@@ -218,7 +218,7 @@ void test_spdylay_frame_pack_goaway()
CU_ASSERT(1000000007 == oframe.goaway.last_good_stream_id);
CU_ASSERT(SPDYLAY_PROTO_VERSION == oframe.headers.hd.version);
CU_ASSERT(SPDYLAY_GOAWAY == oframe.headers.hd.type);
CU_ASSERT(SPDYLAY_FLAG_NONE == oframe.headers.hd.flags);
CU_ASSERT(SPDYLAY_CTRL_FLAG_NONE == oframe.headers.hd.flags);
CU_ASSERT(framelen-SPDYLAY_FRAME_HEAD_LENGTH == oframe.ping.hd.length);
free(buf);
spdylay_frame_goaway_free(&oframe.goaway);
......@@ -236,7 +236,7 @@ void test_spdylay_frame_pack_headers()
spdylay_buffer_init(&inflatebuf, 4096);
spdylay_zlib_deflate_hd_init(&deflater);
spdylay_zlib_inflate_hd_init(&inflater);
spdylay_frame_headers_init(&frame.headers, SPDYLAY_FLAG_FIN, 3,
spdylay_frame_headers_init(&frame.headers, SPDYLAY_CTRL_FLAG_FIN, 3,
spdylay_frame_nv_copy(headers));
framelen = spdylay_frame_pack_headers(&buf, &buflen,
&nvbuf, &nvbuflen,
......@@ -252,7 +252,7 @@ void test_spdylay_frame_pack_headers()
CU_ASSERT(3 == oframe.headers.stream_id);
CU_ASSERT(SPDYLAY_PROTO_VERSION == oframe.headers.hd.version);
CU_ASSERT(SPDYLAY_HEADERS == oframe.headers.hd.type);
CU_ASSERT(SPDYLAY_FLAG_FIN == oframe.headers.hd.flags);
CU_ASSERT(SPDYLAY_CTRL_FLAG_FIN == oframe.headers.hd.flags);
CU_ASSERT(framelen-SPDYLAY_FRAME_HEAD_LENGTH == oframe.ping.hd.length);
CU_ASSERT(strcmp("method", oframe.headers.nv[0]) == 0);
CU_ASSERT(strcmp("GET", oframe.headers.nv[1]) == 0);
......
This diff is collapsed.
......@@ -32,8 +32,8 @@ void test_spdylay_stream_add_pushed_stream()
{
spdylay_stream stream;
int i, n;
spdylay_stream_init(&stream, 1, SPDYLAY_FLAG_NONE, 3, SPDYLAY_STREAM_OPENING,
NULL);
spdylay_stream_init(&stream, 1, SPDYLAY_CTRL_FLAG_NONE, 3,
SPDYLAY_STREAM_OPENING, NULL);
n = 26;
for(i = 2; i < n; i += 2) {
CU_ASSERT(0 == spdylay_stream_add_pushed_stream(&stream, i));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment