mirror of https://github.com/SeanOMik/libki.git
net: Add error codes to Session::close
This commit is contained in:
parent
7932ee2831
commit
993191ec51
|
@ -17,6 +17,22 @@ namespace protocol
|
|||
{
|
||||
namespace net
|
||||
{
|
||||
enum class SessionCloseErrorCode
|
||||
{
|
||||
NONE,
|
||||
APPLICATION_ERROR,
|
||||
|
||||
INVALID_FRAMING_START_SIGNAL,
|
||||
INVALID_FRAMING_SIZE_EXCEEDS_MAXIMUM,
|
||||
|
||||
UNHANDLED_CONTROL_MESSAGE,
|
||||
UNHANDLED_APPLICATION_MESSAGE,
|
||||
INVALID_MESSAGE,
|
||||
|
||||
SESSION_OFFER_TIMED_OUT,
|
||||
SESSION_DIED
|
||||
};
|
||||
|
||||
enum class ReceiveState
|
||||
{
|
||||
// Waiting for the 0xF00D start signal.
|
||||
|
@ -106,7 +122,7 @@ namespace net
|
|||
|
||||
/* Low-level socket methods */
|
||||
virtual void send_packet_data(const char *data, const size_t size) = 0;
|
||||
virtual void close() = 0;
|
||||
virtual void close(SessionCloseErrorCode error) = 0;
|
||||
private:
|
||||
/* Low-level networking members */
|
||||
uint16_t m_maximum_packet_size;
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace net
|
|||
break;
|
||||
|
||||
default:
|
||||
close();
|
||||
close(SessionCloseErrorCode::UNHANDLED_CONTROL_MESSAGE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -87,9 +87,9 @@ namespace net
|
|||
}
|
||||
catch (parse_error &e)
|
||||
{
|
||||
// The SESSION_ACCEPT wasn't valid...
|
||||
// The SESSION_OFFER wasn't valid...
|
||||
// Close the session
|
||||
close();
|
||||
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ namespace net
|
|||
std::chrono::steady_clock::now() - m_connection_time
|
||||
).count() > KI_CONNECTION_TIMEOUT)
|
||||
{
|
||||
close();
|
||||
close(SessionCloseErrorCode::SESSION_OFFER_TIMED_OUT);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ namespace net
|
|||
{
|
||||
// The KEEP_ALIVE wasn't valid...
|
||||
// Close the session
|
||||
close();
|
||||
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ namespace net
|
|||
{
|
||||
// The KEEP_ALIVE_RSP wasn't valid...
|
||||
// Close the session
|
||||
close();
|
||||
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace net
|
|||
break;
|
||||
|
||||
default:
|
||||
close();
|
||||
close(SessionCloseErrorCode::UNHANDLED_CONTROL_MESSAGE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ namespace net
|
|||
{
|
||||
// The SESSION_ACCEPT wasn't valid...
|
||||
// Close the session
|
||||
close();
|
||||
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -104,14 +104,14 @@ namespace net
|
|||
std::chrono::steady_clock::now() - m_connection_time
|
||||
).count() > KI_CONNECTION_TIMEOUT)
|
||||
{
|
||||
close();
|
||||
close(SessionCloseErrorCode::SESSION_OFFER_TIMED_OUT);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure they're accepting this session
|
||||
if (accept.get_session_id() != m_id)
|
||||
{
|
||||
close();
|
||||
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ namespace net
|
|||
{
|
||||
// The KEEP_ALIVE wasn't valid...
|
||||
// Close the session
|
||||
close();
|
||||
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ namespace net
|
|||
{
|
||||
// The KEEP_ALIVE_RSP wasn't valid...
|
||||
// Close the session
|
||||
close();
|
||||
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ namespace net
|
|||
// correctly.
|
||||
if (m_start_signal != KI_START_SIGNAL)
|
||||
{
|
||||
close();
|
||||
close(SessionCloseErrorCode::INVALID_FRAMING_START_SIGNAL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ namespace net
|
|||
// stop processing data.
|
||||
if (m_incoming_packet_size > m_maximum_packet_size)
|
||||
{
|
||||
close();
|
||||
close(SessionCloseErrorCode::INVALID_FRAMING_SIZE_EXCEEDS_MAXIMUM);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue