streamlined bad close code behavior

This commit is contained in:
Peter Thorson
2011-10-27 10:06:21 -05:00
parent ccb34c98b4
commit 5f35df4e6e
2 changed files with 12 additions and 16 deletions

View File

@@ -297,11 +297,7 @@ uint16_t frame::get_close_status() const {
reinterpret_cast<uint16_t*>(&val[0])
));
if (close::status::invalid(code)) {
return close::status::PROTOCOL_ERROR;
} else {
return code;
}
return code;
} else {
return close::status::PROTOCOL_ERROR;
}

View File

@@ -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();