From c1aefb3ba548f518adfca0418a2cc3b7fca77359 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 15 Feb 2012 23:02:51 +0900 Subject: [PATCH] Added flags argument to spdylay_submit_data() and spdylay_frame_data_init(). The intention is make spdylay_submit_data() more generic, allowing trailing DATA and/or HEADERS frames. --- lib/includes/spdylay/spdylay.h | 19 +++++++++++-------- lib/spdylay_frame.c | 3 ++- lib/spdylay_frame.h | 2 +- lib/spdylay_session.c | 5 +++-- lib/spdylay_submit.c | 7 ++++++- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/includes/spdylay/spdylay.h b/lib/includes/spdylay/spdylay.h index 01f2026d..756bcb4d 100644 --- a/lib/includes/spdylay/spdylay.h +++ b/lib/includes/spdylay/spdylay.h @@ -425,14 +425,6 @@ int spdylay_submit_request(spdylay_session *session, uint8_t pri, spdylay_data_provider *data_prd, void *stream_user_data); -/* - * Submits DATA frame to stream |stream_id|. - * - * This function returns 0 if it succeeds, or negative error code. - */ -int spdylay_submit_data(spdylay_session *session, int32_t stream_id, - spdylay_data_provider *data_prd); - /* * Submits SYN_REPLY frame against stream |stream_id|. |nv| must * include following name/value pairs: @@ -451,6 +443,17 @@ int spdylay_submit_response(spdylay_session *session, int32_t stream_id, const char **nv, spdylay_data_provider *data_prd); +/* + * 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. + * + * This function returns 0 if it succeeds, or negative error code. + */ +int spdylay_submit_data(spdylay_session *session, int32_t stream_id, + uint8_t flags, spdylay_data_provider *data_prd); + /* * Submits RST_STREAM frame to cancel/reset stream |stream_id| with * status code |status_code|. This function returns 0 if it succeeds, diff --git a/lib/spdylay_frame.c b/lib/spdylay_frame.c index ca21601a..f5972f0e 100644 --- a/lib/spdylay_frame.c +++ b/lib/spdylay_frame.c @@ -425,10 +425,11 @@ void spdylay_frame_settings_free(spdylay_settings *frame) } void spdylay_frame_data_init(spdylay_data *frame, int32_t stream_id, - spdylay_data_provider *data_prd) + uint8_t flags, spdylay_data_provider *data_prd) { memset(frame, 0, sizeof(spdylay_data)); frame->stream_id = stream_id; + frame->flags = flags; frame->data_prd = *data_prd; } diff --git a/lib/spdylay_frame.h b/lib/spdylay_frame.h index 3991ebce..a880a601 100644 --- a/lib/spdylay_frame.h +++ b/lib/spdylay_frame.h @@ -266,7 +266,7 @@ void spdylay_frame_settings_init(spdylay_settings *frame, uint8_t flags, void spdylay_frame_settings_free(spdylay_settings *frame); void spdylay_frame_data_init(spdylay_data *frame, int32_t stream_id, - spdylay_data_provider *data_prd); + uint8_t flags, spdylay_data_provider *data_prd); void spdylay_frame_data_free(spdylay_data *frame); diff --git a/lib/spdylay_session.c b/lib/spdylay_session.c index 52593381..753c9b63 100644 --- a/lib/spdylay_session.c +++ b/lib/spdylay_session.c @@ -691,7 +691,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, - aux_data->data_prd); + SPDYLAY_FLAG_FIN, aux_data->data_prd); if(r != 0) { /* TODO If r is not FATAL, we should send RST_STREAM. */ return r; @@ -714,7 +714,8 @@ static int spdylay_session_after_frame_sent(spdylay_session *session) spdylay_data_provider *data_prd = (spdylay_data_provider*)item->aux_data; int r; - r = spdylay_submit_data(session, frame->syn_reply.stream_id, data_prd); + r = spdylay_submit_data(session, frame->syn_reply.stream_id, + SPDYLAY_FLAG_FIN, data_prd); if(r != 0) { /* TODO If r is not FATAL, we should send RST_STREAM. */ return r; diff --git a/lib/spdylay_submit.c b/lib/spdylay_submit.c index 1daaba20..d1579a28 100644 --- a/lib/spdylay_submit.c +++ b/lib/spdylay_submit.c @@ -88,15 +88,20 @@ int spdylay_submit_response(spdylay_session *session, } int spdylay_submit_data(spdylay_session *session, int32_t stream_id, + uint8_t flags, spdylay_data_provider *data_prd) { int r; spdylay_frame *frame; + uint8_t nflags = 0; frame = malloc(sizeof(spdylay_frame)); if(frame == NULL) { return SPDYLAY_ERR_NOMEM; } - spdylay_frame_data_init(&frame->data, stream_id, data_prd); + if(flags & SPDYLAY_FLAG_FIN) { + nflags |= SPDYLAY_FLAG_FIN; + } + spdylay_frame_data_init(&frame->data, stream_id, nflags, data_prd); r = spdylay_session_add_frame(session, SPDYLAY_DATA, frame, NULL); if(r != 0) { spdylay_frame_data_free(&frame->data);