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
|
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
|
enum class ReceiveState
|
||||||
{
|
{
|
||||||
// Waiting for the 0xF00D start signal.
|
// Waiting for the 0xF00D start signal.
|
||||||
|
@ -106,7 +122,7 @@ namespace net
|
||||||
|
|
||||||
/* Low-level socket methods */
|
/* Low-level socket methods */
|
||||||
virtual void send_packet_data(const char *data, const size_t size) = 0;
|
virtual void send_packet_data(const char *data, const size_t size) = 0;
|
||||||
virtual void close() = 0;
|
virtual void close(SessionCloseErrorCode error) = 0;
|
||||||
private:
|
private:
|
||||||
/* Low-level networking members */
|
/* Low-level networking members */
|
||||||
uint16_t m_maximum_packet_size;
|
uint16_t m_maximum_packet_size;
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace net
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
close();
|
close(SessionCloseErrorCode::UNHANDLED_CONTROL_MESSAGE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,9 @@ namespace net
|
||||||
}
|
}
|
||||||
catch (parse_error &e)
|
catch (parse_error &e)
|
||||||
{
|
{
|
||||||
// The SESSION_ACCEPT wasn't valid...
|
// The SESSION_OFFER wasn't valid...
|
||||||
// Close the session
|
// Close the session
|
||||||
close();
|
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ namespace net
|
||||||
std::chrono::steady_clock::now() - m_connection_time
|
std::chrono::steady_clock::now() - m_connection_time
|
||||||
).count() > KI_CONNECTION_TIMEOUT)
|
).count() > KI_CONNECTION_TIMEOUT)
|
||||||
{
|
{
|
||||||
close();
|
close(SessionCloseErrorCode::SESSION_OFFER_TIMED_OUT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ namespace net
|
||||||
{
|
{
|
||||||
// The KEEP_ALIVE wasn't valid...
|
// The KEEP_ALIVE wasn't valid...
|
||||||
// Close the session
|
// Close the session
|
||||||
close();
|
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ namespace net
|
||||||
{
|
{
|
||||||
// The KEEP_ALIVE_RSP wasn't valid...
|
// The KEEP_ALIVE_RSP wasn't valid...
|
||||||
// Close the session
|
// Close the session
|
||||||
close();
|
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace net
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
close();
|
close(SessionCloseErrorCode::UNHANDLED_CONTROL_MESSAGE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ namespace net
|
||||||
{
|
{
|
||||||
// The SESSION_ACCEPT wasn't valid...
|
// The SESSION_ACCEPT wasn't valid...
|
||||||
// Close the session
|
// Close the session
|
||||||
close();
|
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,14 +104,14 @@ namespace net
|
||||||
std::chrono::steady_clock::now() - m_connection_time
|
std::chrono::steady_clock::now() - m_connection_time
|
||||||
).count() > KI_CONNECTION_TIMEOUT)
|
).count() > KI_CONNECTION_TIMEOUT)
|
||||||
{
|
{
|
||||||
close();
|
close(SessionCloseErrorCode::SESSION_OFFER_TIMED_OUT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure they're accepting this session
|
// Make sure they're accepting this session
|
||||||
if (accept.get_session_id() != m_id)
|
if (accept.get_session_id() != m_id)
|
||||||
{
|
{
|
||||||
close();
|
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ namespace net
|
||||||
{
|
{
|
||||||
// The KEEP_ALIVE wasn't valid...
|
// The KEEP_ALIVE wasn't valid...
|
||||||
// Close the session
|
// Close the session
|
||||||
close();
|
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ namespace net
|
||||||
{
|
{
|
||||||
// The KEEP_ALIVE_RSP wasn't valid...
|
// The KEEP_ALIVE_RSP wasn't valid...
|
||||||
// Close the session
|
// Close the session
|
||||||
close();
|
close(SessionCloseErrorCode::INVALID_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ namespace net
|
||||||
// correctly.
|
// correctly.
|
||||||
if (m_start_signal != KI_START_SIGNAL)
|
if (m_start_signal != KI_START_SIGNAL)
|
||||||
{
|
{
|
||||||
close();
|
close(SessionCloseErrorCode::INVALID_FRAMING_START_SIGNAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ namespace net
|
||||||
// stop processing data.
|
// stop processing data.
|
||||||
if (m_incoming_packet_size > m_maximum_packet_size)
|
if (m_incoming_packet_size > m_maximum_packet_size)
|
||||||
{
|
{
|
||||||
close();
|
close(SessionCloseErrorCode::INVALID_FRAMING_SIZE_EXCEEDS_MAXIMUM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue