Added spdylay_on_stream_close_callback

This commit is contained in:
Tatsuhiro Tsujikawa 2012-01-29 23:00:33 +09:00
parent bf1be4850e
commit 6e12291ae1
3 changed files with 32 additions and 10 deletions

View File

@ -78,6 +78,7 @@ typedef enum {
} spdylay_flag; } spdylay_flag;
typedef enum { typedef enum {
SPDYLAY_OK = 0,
SPDYLAY_PROTOCOL_ERROR = 1, SPDYLAY_PROTOCOL_ERROR = 1,
SPDYLAY_INVALID_STREAM = 2, SPDYLAY_INVALID_STREAM = 2,
SPDYLAY_REFUSED_STREAM = 3, SPDYLAY_REFUSED_STREAM = 3,
@ -256,6 +257,14 @@ typedef void (*spdylay_before_ctrl_send_callback)
(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, (spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame,
void *user_data); void *user_data);
/*
* Callback function invoked when stream |stream_id| is closed. The
* reason of closure is indicated by |status_code|.
*/
typedef void (*spdylay_on_stream_close_callback)
(spdylay_session *session, int32_t stream_id, spdylay_status_code status_code,
void *user_data);
typedef struct { typedef struct {
spdylay_send_callback send_callback; spdylay_send_callback send_callback;
spdylay_recv_callback recv_callback; spdylay_recv_callback recv_callback;
@ -267,6 +276,7 @@ typedef struct {
spdylay_before_ctrl_send_callback before_ctrl_send_callback; spdylay_before_ctrl_send_callback before_ctrl_send_callback;
spdylay_on_ctrl_send_callback on_ctrl_send_callback; spdylay_on_ctrl_send_callback on_ctrl_send_callback;
spdylay_on_data_send_callback on_data_send_callback; spdylay_on_data_send_callback on_data_send_callback;
spdylay_on_stream_close_callback on_stream_close_callback;
} spdylay_session_callbacks; } spdylay_session_callbacks;
/* /*

View File

@ -286,11 +286,18 @@ spdylay_stream* spdylay_session_open_stream(spdylay_session *session,
return stream; return stream;
} }
int spdylay_session_close_stream(spdylay_session *session, int32_t stream_id) int spdylay_session_close_stream(spdylay_session *session, int32_t stream_id,
spdylay_status_code status_code)
{ {
spdylay_stream *stream = spdylay_session_get_stream(session, stream_id); spdylay_stream *stream = spdylay_session_get_stream(session, stream_id);
if(stream) { if(stream) {
spdylay_map_erase(&session->streams, stream_id); spdylay_map_erase(&session->streams, stream_id);
if(stream->state != SPDYLAY_STREAM_INITIAL &&
session->callbacks.on_stream_close_callback) {
session->callbacks.on_stream_close_callback(session, stream_id,
status_code,
session->user_data);
}
spdylay_stream_free(stream); spdylay_stream_free(stream);
free(stream); free(stream);
return 0; return 0;
@ -303,7 +310,8 @@ int spdylay_session_close_stream_if_shut_rdwr(spdylay_session *session,
spdylay_stream *stream) spdylay_stream *stream)
{ {
if((stream->shut_flags & SPDYLAY_SHUT_RDWR) == SPDYLAY_SHUT_RDWR) { if((stream->shut_flags & SPDYLAY_SHUT_RDWR) == SPDYLAY_SHUT_RDWR) {
return spdylay_session_close_stream(session, stream->stream_id); return spdylay_session_close_stream(session, stream->stream_id,
SPDYLAY_OK);
} else { } else {
return 0; return 0;
} }
@ -381,7 +389,7 @@ ssize_t spdylay_session_prep_frame(spdylay_session *session,
r = spdylay_submit_data(session, stream_id, data_prd); r = spdylay_submit_data(session, stream_id, data_prd);
if(r != 0) { if(r != 0) {
free(framebuf); free(framebuf);
spdylay_session_close_stream(session, stream_id); spdylay_session_close_stream(session, stream_id, SPDYLAY_OK);
return r; return r;
} }
} }
@ -506,7 +514,8 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
break; break;
} }
case SPDYLAY_RST_STREAM: case SPDYLAY_RST_STREAM:
spdylay_session_close_stream(session, frame->rst_stream.stream_id); spdylay_session_close_stream(session, frame->rst_stream.stream_id,
frame->rst_stream.status_code);
break; break;
case SPDYLAY_NOOP: case SPDYLAY_NOOP:
/* We don't have any public API to add NOOP, so here is /* We don't have any public API to add NOOP, so here is
@ -835,7 +844,8 @@ int spdylay_session_on_syn_reply_received(spdylay_session *session,
int spdylay_session_on_rst_stream_received(spdylay_session *session, int spdylay_session_on_rst_stream_received(spdylay_session *session,
spdylay_frame *frame) spdylay_frame *frame)
{ {
spdylay_session_close_stream(session, frame->rst_stream.stream_id); spdylay_session_close_stream(session, frame->rst_stream.stream_id,
frame->rst_stream.status_code);
return 0; return 0;
} }

View File

@ -159,12 +159,14 @@ spdylay_stream* spdylay_session_open_stream(spdylay_session *session,
spdylay_stream_state initial_state); spdylay_stream_state initial_state);
/* /*
* Closes stream whose stream ID is |stream_id|. This function returns * Closes stream whose stream ID is |stream_id|. The reason of closure
* 0 if it succeeds, or negative error code. The possible error code * is indicated by |status_code|. This function returns 0 if it
* is SPDYLAY_ERR_INVALID_ARGUMENT, which is used when stream * succeeds, or negative error code. The possible error code is
* |stream_id| does not exist. So the caller may ignore this error. * SPDYLAY_ERR_INVALID_ARGUMENT, which is used when stream |stream_id|
* does not exist. So the caller may ignore this error.
*/ */
int spdylay_session_close_stream(spdylay_session *session, int32_t stream_id); int spdylay_session_close_stream(spdylay_session *session, int32_t stream_id,
spdylay_status_code status_code);
/* /*
* If further receptions and transmissions over this stream are * If further receptions and transmissions over this stream are