Merge branch 'master' of https://github.com/sorced-jim/spdylay into sorced-jim-master

Conflicts:
	tests/main.c
	tests/spdylay_session_test.c
	tests/spdylay_session_test.h
This commit is contained in:
Tatsuhiro Tsujikawa 2012-02-08 21:37:44 +09:00
commit 679159878f
4 changed files with 37 additions and 2 deletions

View File

@ -358,13 +358,13 @@ int spdylay_session_close_stream(spdylay_session *session, int32_t stream_id,
{
spdylay_stream *stream = spdylay_session_get_stream(session, stream_id);
if(stream) {
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_map_erase(&session->streams, stream_id);
spdylay_stream_free(stream);
free(stream);
return 0;

View File

@ -109,6 +109,8 @@ int main(int argc, char* argv[])
test_spdylay_session_pop_next_ob_item) ||
!CU_add_test(pSuite, "session_on_request_recv_callback",
test_spdylay_session_on_request_recv_callback) ||
!CU_add_test(pSuite, "session_on_stream_close",
test_spdylay_session_on_stream_close) ||
!CU_add_test(pSuite, "frame_unpack_nv", test_spdylay_frame_unpack_nv) ||
!CU_add_test(pSuite, "frame_count_nv_space",
test_spdylay_frame_count_nv_space) ||

View File

@ -943,6 +943,38 @@ void test_spdylay_session_on_request_recv_callback()
CU_ASSERT(0 == user_data.stream_id);
spdylay_frame_headers_free(&frame.headers);
spdylay_session_del(session);
}
void stream_close_callback(spdylay_session *session, int32_t stream_id,
spdylay_status_code status_code, void *user_data)
{
my_user_data* my_data = (my_user_data*)user_data;
void *stream_data = spdylay_session_get_stream_user_data(session, stream_id);
my_data->invalid = 1;
my_data->valid = stream_data != NULL ? 1 : 0;
}
void test_spdylay_session_on_stream_close()
{
spdylay_session *session;
spdylay_session_callbacks callbacks;
my_user_data user_data;
spdylay_stream *stream;
int32_t stream_id = 1;
uint8_t pri = 3;
memset(&callbacks, 0, sizeof(spdylay_session_callbacks));
callbacks.on_stream_close_callback = stream_close_callback;
user_data.valid = 0;
user_data.invalid = 0;
CU_ASSERT(spdylay_session_client_new(&session, &callbacks, &user_data) == 0);
stream = spdylay_session_open_stream(session, stream_id, SPDYLAY_FLAG_NONE,
pri, SPDYLAY_STREAM_OPENED, &user_data);
CU_ASSERT(stream != NULL);
CU_ASSERT(spdylay_session_close_stream(session, stream_id, SPDYLAY_OK) == 0);
CU_ASSERT(user_data.invalid == 1); /* Called the callback. */
CU_ASSERT(user_data.valid == 1);
spdylay_session_del(session);
}

View File

@ -46,5 +46,6 @@ void test_spdylay_session_send_rst_stream();
void test_spdylay_session_get_next_ob_item();
void test_spdylay_session_pop_next_ob_item();
void test_spdylay_session_on_request_recv_callback();
void test_spdylay_session_on_stream_close();
#endif // SPDYLAY_SESSION_TEST_H