Don't send GOAWAY when it is received from peer. Fixed want_read, want_write.

This commit is contained in:
Tatsuhiro Tsujikawa 2012-01-29 15:11:10 +09:00
parent ebd3dc9dcc
commit e212eea08a
2 changed files with 12 additions and 22 deletions

View File

@ -859,18 +859,8 @@ int spdylay_session_on_ping_received(spdylay_session *session,
int spdylay_session_on_goaway_received(spdylay_session *session, int spdylay_session_on_goaway_received(spdylay_session *session,
spdylay_frame *frame) spdylay_frame *frame)
{ {
int r;
session->last_good_stream_id = frame->goaway.last_good_stream_id; session->last_good_stream_id = frame->goaway.last_good_stream_id;
session->goaway_flags |= SPDYLAY_GOAWAY_RECV; session->goaway_flags |= SPDYLAY_GOAWAY_RECV;
if(!(session->goaway_flags & SPDYLAY_GOAWAY_SEND)) {
/* TODO The spec does not mandate to send back GOAWAY. I think the
remote endpoint does not expect this, but sending GOAWAY does
not harm. */
r = spdylay_session_add_goaway(session, session->last_recv_stream_id);
if(r != 0) {
return r;
}
}
spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_GOAWAY, frame); spdylay_session_call_on_ctrl_frame_received(session, SPDYLAY_GOAWAY, frame);
return 0; return 0;
} }
@ -1152,19 +1142,23 @@ int spdylay_session_recv(spdylay_session *session)
int spdylay_session_want_read(spdylay_session *session) int spdylay_session_want_read(spdylay_session *session)
{ {
/* If GOAWAY is not sent or received, we always want to read /* Unless GOAWAY is sent or received, we always want to read
incoming frames. After GOAWAY is sent or received, we are only incoming frames. After GOAWAY is sent or received, we are only
interested in existing streams. */ interested in active streams. */
return !(session->goaway_flags & SPDYLAY_GOAWAY_SEND) || return !session->goaway_flags || spdylay_map_size(&session->streams) > 0;
spdylay_map_size(&session->streams) == 0;
} }
int spdylay_session_want_write(spdylay_session *session) int spdylay_session_want_write(spdylay_session *session)
{ {
uint8_t goaway_sent = session->goaway_flags & SPDYLAY_GOAWAY_SEND; /*
return (!goaway_sent && * Unless GOAWAY is sent or received, we want to write frames if
(session->aob.item != NULL || !spdylay_pq_empty(&session->ob_pq))) || * there is pending ones. After GOAWAY is sent or received, we want
(goaway_sent && spdylay_map_size(&session->streams) == 0); * to write frames if there is pending ones AND there are active
* frames.
*/
return (session->aob.item != NULL || !spdylay_pq_empty(&session->ob_pq)) &&
(!session->goaway_flags ||
spdylay_map_size(&session->streams) > 0);
} }
int spdylay_session_add_ping(spdylay_session *session, uint32_t unique_id) int spdylay_session_add_ping(spdylay_session *session, uint32_t unique_id)

View File

@ -606,10 +606,6 @@ void test_spdylay_session_on_goaway_received()
CU_ASSERT(1 == user_data.valid); CU_ASSERT(1 == user_data.valid);
CU_ASSERT(session->goaway_flags == SPDYLAY_GOAWAY_RECV); CU_ASSERT(session->goaway_flags == SPDYLAY_GOAWAY_RECV);
top = spdylay_session_get_ob_pq_top(session);
CU_ASSERT(SPDYLAY_GOAWAY == top->frame_type);
CU_ASSERT(0 == top->frame->goaway.last_good_stream_id);
spdylay_frame_goaway_free(&frame.goaway); spdylay_frame_goaway_free(&frame.goaway);
spdylay_session_del(session); spdylay_session_del(session);
} }