1
0
mirror of https://github.com/moparisthebest/spdylay synced 2024-12-22 07:38:52 -05:00

Erase the stream from the map after calling the on_stream_close callback

This commit is contained in:
Jim Morrison 2012-02-07 14:17:38 -08:00
parent 4ebfa021ba
commit 4298dc8a51
4 changed files with 38 additions and 1 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

@ -107,6 +107,8 @@ int main(int argc, char* argv[])
test_spdylay_session_get_next_ob_item) ||
!CU_add_test(pSuite, "session_pop_next_ob_item",
test_spdylay_session_pop_next_ob_item) ||
!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

@ -883,3 +883,37 @@ void test_spdylay_session_pop_next_ob_item()
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;
const char *nv[] = { NULL };
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

@ -45,5 +45,6 @@ void test_spdylay_session_is_my_stream_id();
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_stream_close();
#endif // SPDYLAY_SESSION_TEST_H