From 21e85281fac3b71a4f4b68a007e4bfbbb6357b5d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 9 May 2012 23:27:44 +0900 Subject: [PATCH] Added debug output using on_invalid_ctrl_recv_callback to spdycat. --- examples/spdycat.cc | 1 + examples/spdylay_ssl.cc | 46 ++++++++++++++++++++++++++++++++++++++++- examples/spdylay_ssl.h | 4 ++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/examples/spdycat.cc b/examples/spdycat.cc index f0512fdb..fc1ef289 100644 --- a/examples/spdycat.cc +++ b/examples/spdycat.cc @@ -348,6 +348,7 @@ int run(char **uris, int n) callbacks.on_ctrl_recv_callback = on_ctrl_recv_callback3; callbacks.on_data_recv_callback = on_data_recv_callback; callbacks.on_ctrl_send_callback = on_ctrl_send_callback3; + callbacks.on_invalid_ctrl_recv_callback = on_invalid_ctrl_recv_callback; callbacks.on_ctrl_recv_parse_error_callback = on_ctrl_recv_parse_error_callback; callbacks.on_unknown_ctrl_recv_callback = on_unknown_ctrl_recv_callback; diff --git a/examples/spdylay_ssl.cc b/examples/spdylay_ssl.cc index f6327cd5..aaffcbbb 100644 --- a/examples/spdylay_ssl.cc +++ b/examples/spdylay_ssl.cc @@ -407,6 +407,50 @@ void on_ctrl_recv_callback fflush(stdout); } +namespace { +const char* strstatus(uint32_t status_code) +{ + switch(status_code) { + case SPDYLAY_OK: + return "OK"; + case SPDYLAY_PROTOCOL_ERROR: + return "PROTOCOL_ERROR"; + case SPDYLAY_INVALID_STREAM: + return "INVALID_STREAM"; + case SPDYLAY_REFUSED_STREAM: + return "REFUSED_STREAM"; + case SPDYLAY_UNSUPPORTED_VERSION: + return "UNSUPPORTED_VERSION"; + case SPDYLAY_CANCEL: + return "CANCEL"; + case SPDYLAY_INTERNAL_ERROR: + return "INTERNAL_ERROR"; + case SPDYLAY_FLOW_CONTROL_ERROR: + return "FLOW_CONTROL_ERROR"; + case SPDYLAY_STREAM_IN_USE: + return "STREAM_IN_USE"; + case SPDYLAY_STREAM_ALREADY_CLOSED: + return "STREAM_ALREADY_CLOSED"; + case SPDYLAY_INVALID_CREDENTIALS: + return "INVALID_CREDENTIALS"; + case FRAME_TOO_LARGE: + return "FRAME_TOO_LARGE"; + default: + return "Unknown status code"; + } +} +} // namespace + +void on_invalid_ctrl_recv_callback +(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, + uint32_t status_code, void *user_data) +{ + print_timer(); + printf(" [INVALID; status=%s] recv ", strstatus(status_code)); + print_frame(type, frame); + fflush(stdout); +} + namespace { void dump_header(const uint8_t *head, size_t headlen) { @@ -429,7 +473,7 @@ void on_ctrl_recv_parse_error_callback(spdylay_session *session, int error_code, void *user_data) { print_timer(); - printf(" recv %s frame: Parse error\n", ctrl_names[type-1]); + printf(" [PARSE_ERROR] recv %s frame\n", ctrl_names[type-1]); print_frame_attr_indent(); printf("Error: %s\n", spdylay_strerror(error_code)); dump_header(head, headlen); diff --git a/examples/spdylay_ssl.h b/examples/spdylay_ssl.h index e37ff0d4..b7fc288a 100644 --- a/examples/spdylay_ssl.h +++ b/examples/spdylay_ssl.h @@ -85,6 +85,10 @@ void on_ctrl_recv_callback (spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, void *user_data); +void on_invalid_ctrl_recv_callback +(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, + uint32_t status_code, void *user_data); + void on_ctrl_recv_parse_error_callback(spdylay_session *session, spdylay_frame_type type, const uint8_t *head,