Refactored socket send method and message recieved method (#25)

* Enhanced sockets

* Removed unnecessary copy operations

* Enhanced sock session send method to recieve rref

* Enhanced on_read with rvalue reference

* Added string_view

* Added comments
This commit is contained in:
Ravidu Lashan
2019-10-14 18:26:34 +05:30
committed by GitHub
parent 56c3e3ee93
commit 9ec9c9575d
9 changed files with 102 additions and 41 deletions

View File

@@ -24,7 +24,7 @@ void user_session_handler::on_connect(sock::socket_session *session)
{
std::cout << "User client connected " << session->address_ << ":" << session->port_ << std::endl;
// As a soon as a user conntects, we issue them a challenge message. We remember the
// As soon as a user conntects, we issue them a challenge message. We remember the
// challenge we issued and later verifies the user's response with it.
std::string msg;
@@ -37,8 +37,7 @@ void user_session_handler::on_connect(sock::socket_session *session)
// Create an entry in pending_challenges for later tracking upon challenge response.
usr::pending_challenges[session->uniqueid_] = challengeb64;
// TODO: This needs to be reviewed to optimise passing the message.
session->send(std::make_shared<std::string>(msg));
session->send(std::move(msg));
// Set the challenge-issued flag to help later checks in on_message.
session->flags_.set(util::SESSION_FLAG::USER_CHALLENGE_ISSUED);
@@ -47,7 +46,7 @@ void user_session_handler::on_connect(sock::socket_session *session)
/**
* This gets hit every time we receive some data from a client connected to the HP public port.
*/
void user_session_handler::on_message(sock::socket_session *session, const std::string &message)
void user_session_handler::on_message(sock::socket_session *session, std::string &&message)
{
// First check whether this session is pending challenge.
// Meaning we have previously issued a challenge to the client,