From 5f35df4e6e0943e5f22baa5106dcddbf4585f47c Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 27 Oct 2011 10:06:21 -0500 Subject: [PATCH] streamlined bad close code behavior --- src/websocket_frame.cpp | 6 +----- src/websocket_session.cpp | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/websocket_frame.cpp b/src/websocket_frame.cpp index 114cdbd012..c630f05007 100644 --- a/src/websocket_frame.cpp +++ b/src/websocket_frame.cpp @@ -297,11 +297,7 @@ uint16_t frame::get_close_status() const { reinterpret_cast(&val[0]) )); - if (close::status::invalid(code)) { - return close::status::PROTOCOL_ERROR; - } else { - return code; - } + return code; } else { return close::status::PROTOCOL_ERROR; } diff --git a/src/websocket_session.cpp b/src/websocket_session.cpp index f43f8abdaa..a8119b4728 100644 --- a/src/websocket_session.cpp +++ b/src/websocket_session.cpp @@ -184,17 +184,17 @@ void session::send_close(uint16_t status,const std::string &message) { m_write_frame.set_opcode(frame::CONNECTION_CLOSE); // echo close value unless there is a good reason not to. - try { - if (status == CLOSE_STATUS_NO_STATUS) { - m_write_frame.set_status(CLOSE_STATUS_NORMAL,""); - } else if (status == CLOSE_STATUS_ABNORMAL_CLOSE) { - // Internal implimentation error. There is no good close code for this. - m_write_frame.set_status(CLOSE_STATUS_POLICY_VIOLATION,message); - } else { - m_write_frame.set_status(status,message); - } - } catch (const frame_error& e) { - m_write_frame.set_status(close::status::PROTOCOL_ERROR,e.what()); + if (status == CLOSE_STATUS_NO_STATUS) { + m_write_frame.set_status(CLOSE_STATUS_NORMAL,""); + } else if (status == CLOSE_STATUS_ABNORMAL_CLOSE) { + // Internal implimentation error. There is no good close code for this. + m_write_frame.set_status(CLOSE_STATUS_POLICY_VIOLATION,message); + } else if (close::status::invalid(status)) { + m_write_frame.set_status(close::status::PROTOCOL_ERROR,"Status code is invalid"); + } else if (close::status::reserved(status)) { + m_write_frame.set_status(close::status::PROTOCOL_ERROR,"Status code is reserved"); + } else { + m_write_frame.set_status(status,message); } write_frame();