diff options
author | Andrey Uzunov <andrey.uzunov@gmail.com> | 2013-07-18 21:44:37 +0000 |
---|---|---|
committer | Andrey Uzunov <andrey.uzunov@gmail.com> | 2013-07-18 21:44:37 +0000 |
commit | fe35bcf2eb982078ee043927bda2b6cc107871bd (patch) | |
tree | e61f06f7dd1d9d8a7c34d7b20a2547e5771237e4 | |
parent | 0bebdb1cc3d5aaf217c1227ebc2b58ec7698377b (diff) | |
download | libmicrohttpd-fe35bcf2eb982078ee043927bda2b6cc107871bd.tar.gz libmicrohttpd-fe35bcf2eb982078ee043927bda2b6cc107871bd.zip |
spdy: send RST_STREAM when user callback for response fails
-rw-r--r-- | src/microspdy/session.c | 31 | ||||
-rw-r--r-- | src/microspdy/session.h | 4 |
2 files changed, 27 insertions, 8 deletions
diff --git a/src/microspdy/session.c b/src/microspdy/session.c index 6374201d..4a6d8525 100644 --- a/src/microspdy/session.c +++ b/src/microspdy/session.c | |||
@@ -129,7 +129,7 @@ spdyf_handler_read_syn_stream (struct SPDY_Session *session) | |||
129 | if(0 == name_value_strm_size || 0 == compressed_data_size) | 129 | if(0 == name_value_strm_size || 0 == compressed_data_size) |
130 | { | 130 | { |
131 | //Protocol error: send RST_STREAM | 131 | //Protocol error: send RST_STREAM |
132 | if(SPDY_YES != SPDYF_prepare_rst_stream(session, session->current_stream_id, | 132 | if(SPDY_YES != SPDYF_prepare_rst_stream(session, session->streams_head, |
133 | SPDY_RST_STREAM_STATUS_PROTOCOL_ERROR)) | 133 | SPDY_RST_STREAM_STATUS_PROTOCOL_ERROR)) |
134 | { | 134 | { |
135 | //no memory, try later to send RST | 135 | //no memory, try later to send RST |
@@ -571,11 +571,22 @@ SPDYF_handler_write_data (struct SPDY_Session *session) | |||
571 | 571 | ||
572 | if(ret < 0 || ret > response_queue->response->rcb_block_size) | 572 | if(ret < 0 || ret > response_queue->response->rcb_block_size) |
573 | { | 573 | { |
574 | //TODO send RST_STREAM (app error) | 574 | free(session->write_buffer); |
575 | session->write_buffer = NULL; | ||
576 | |||
577 | //send RST_STREAM | ||
578 | if(SPDY_YES == (ret = SPDYF_prepare_rst_stream(session, | ||
579 | response_queue->stream, | ||
580 | SPDY_RST_STREAM_STATUS_INTERNAL_ERROR))) | ||
581 | { | ||
582 | return SPDY_NO; | ||
583 | } | ||
584 | |||
585 | //else no memory | ||
575 | //for now close session | 586 | //for now close session |
587 | //TODO what? | ||
576 | session->status = SPDY_SESSION_STATUS_CLOSING; | 588 | session->status = SPDY_SESSION_STATUS_CLOSING; |
577 | 589 | ||
578 | free(session->write_buffer); | ||
579 | return SPDY_NO; | 590 | return SPDY_NO; |
580 | } | 591 | } |
581 | if(0 == ret && more) | 592 | if(0 == ret && more) |
@@ -619,6 +630,7 @@ SPDYF_handler_write_data (struct SPDY_Session *session) | |||
619 | session->status = SPDY_SESSION_STATUS_CLOSING; | 630 | session->status = SPDY_SESSION_STATUS_CLOSING; |
620 | 631 | ||
621 | free(session->write_buffer); | 632 | free(session->write_buffer); |
633 | session->write_buffer = NULL; | ||
622 | return SPDY_NO; | 634 | return SPDY_NO; |
623 | } | 635 | } |
624 | 636 | ||
@@ -992,7 +1004,7 @@ SPDYF_session_write (struct SPDY_Session *session, bool only_one_frame) | |||
992 | if(session->write_buffer_beginning == session->write_buffer_size) | 1004 | if(session->write_buffer_beginning == session->write_buffer_size) |
993 | { | 1005 | { |
994 | //that response is handled, remove it from queue | 1006 | //that response is handled, remove it from queue |
995 | free(session->write_buffer); | 1007 | free(session->write_buffer); |
996 | session->write_buffer = NULL; | 1008 | session->write_buffer = NULL; |
997 | session->write_buffer_size = 0; | 1009 | session->write_buffer_size = 0; |
998 | queue_head = session->response_queue_head; | 1010 | queue_head = session->response_queue_head; |
@@ -1175,7 +1187,7 @@ SPDYF_session_idle (struct SPDY_Session *session) | |||
1175 | session->read_buffer_beginning = session->read_buffer_offset; | 1187 | session->read_buffer_beginning = session->read_buffer_offset; |
1176 | 1188 | ||
1177 | SPDYF_prepare_rst_stream(session, | 1189 | SPDYF_prepare_rst_stream(session, |
1178 | session->current_stream_id, //may be 0 here which is not good | 1190 | session->current_stream_id > 0 ? session->streams_head : NULL, //may be 0 here which is not good |
1179 | SPDY_RST_STREAM_STATUS_FRAME_TOO_LARGE); | 1191 | SPDY_RST_STREAM_STATUS_FRAME_TOO_LARGE); |
1180 | 1192 | ||
1181 | //actually the read buffer can be bigger than the | 1193 | //actually the read buffer can be bigger than the |
@@ -1541,13 +1553,19 @@ SPDYF_prepare_goaway (struct SPDY_Session *session, | |||
1541 | 1553 | ||
1542 | int | 1554 | int |
1543 | SPDYF_prepare_rst_stream (struct SPDY_Session *session, | 1555 | SPDYF_prepare_rst_stream (struct SPDY_Session *session, |
1544 | uint32_t stream_id, | 1556 | struct SPDYF_Stream * stream, |
1545 | enum SPDY_RST_STREAM_STATUS status) | 1557 | enum SPDY_RST_STREAM_STATUS status) |
1546 | { | 1558 | { |
1547 | struct SPDYF_Response_Queue *response_to_queue; | 1559 | struct SPDYF_Response_Queue *response_to_queue; |
1548 | struct SPDYF_Control_Frame *control_frame; | 1560 | struct SPDYF_Control_Frame *control_frame; |
1549 | uint32_t *data; | 1561 | uint32_t *data; |
1562 | uint32_t stream_id; | ||
1550 | 1563 | ||
1564 | if(NULL == stream) | ||
1565 | stream_id = 0; | ||
1566 | else | ||
1567 | stream_id = stream->stream_id; | ||
1568 | |||
1551 | if(NULL == (response_to_queue = malloc(sizeof(struct SPDYF_Response_Queue)))) | 1569 | if(NULL == (response_to_queue = malloc(sizeof(struct SPDYF_Response_Queue)))) |
1552 | { | 1570 | { |
1553 | return SPDY_NO; | 1571 | return SPDY_NO; |
@@ -1579,6 +1597,7 @@ SPDYF_prepare_rst_stream (struct SPDY_Session *session, | |||
1579 | response_to_queue->process_response_handler = &SPDYF_handler_write_rst_stream; | 1597 | response_to_queue->process_response_handler = &SPDYF_handler_write_rst_stream; |
1580 | response_to_queue->data = data; | 1598 | response_to_queue->data = data; |
1581 | response_to_queue->data_size = 8; | 1599 | response_to_queue->data_size = 8; |
1600 | response_to_queue->stream = stream; | ||
1582 | 1601 | ||
1583 | SPDYF_queue_response (response_to_queue, | 1602 | SPDYF_queue_response (response_to_queue, |
1584 | session, | 1603 | session, |
diff --git a/src/microspdy/session.h b/src/microspdy/session.h index cdfa8d15..6af1ad95 100644 --- a/src/microspdy/session.h +++ b/src/microspdy/session.h | |||
@@ -160,14 +160,14 @@ SPDYF_prepare_goaway (struct SPDY_Session *session, | |||
160 | * will be discarded soon. | 160 | * will be discarded soon. |
161 | * | 161 | * |
162 | * @param session SPDY session | 162 | * @param session SPDY session |
163 | * @param stream_id stream to terminate | 163 | * @param stream stream to terminate |
164 | * @param status code for the RST_STREAM frame | 164 | * @param status code for the RST_STREAM frame |
165 | * @return SPDY_NO on memory error or | 165 | * @return SPDY_NO on memory error or |
166 | * SPDY_YES on success | 166 | * SPDY_YES on success |
167 | */ | 167 | */ |
168 | int | 168 | int |
169 | SPDYF_prepare_rst_stream (struct SPDY_Session *session, | 169 | SPDYF_prepare_rst_stream (struct SPDY_Session *session, |
170 | uint32_t stream_id, | 170 | struct SPDYF_Stream * stream, |
171 | enum SPDY_RST_STREAM_STATUS status); | 171 | enum SPDY_RST_STREAM_STATUS status); |
172 | 172 | ||
173 | 173 | ||