Reorganize socket classes

This commit is contained in:
2019-06-16 11:42:26 +02:00
parent 9ba225cbde
commit e9509fb117
8 changed files with 32 additions and 33 deletions

View File

@@ -6,22 +6,22 @@
#include <cstdio>
#include <sstream>
void ConnectionOperator::SendResponse(Connection const & connection, Http::Response const & response) const
void ConnectionOperator::SendResponse(ClientSocket const & clientSocket, Http::Response const & response) const
{
auto bytesToSend = response.Serialize();
try
{
connection.WriteBytes(bytesToSend);
clientSocket.WriteBytes(bytesToSend);
}
catch(std::runtime_error & e)
{
logger.Error("Error writing data to connection");
logger.Error("Error writing data to clientSocket");
}
}
void ConnectionOperator::HandleNewConnection(Connection const & newConnection)
void ConnectionOperator::HandleNewConnection(ClientSocket const & newClient)
{
auto requestBytes = newConnection.ReadBytes();
auto requestBytes = newClient.ReadBytes();
Http::Request request;
Http::Response response;
try
@@ -37,7 +37,7 @@ void ConnectionOperator::HandleNewConnection(Connection const & newConnection)
logger.Error(ss.str());
response.code = HttpResponse::Code::BAD_REQUEST;
SendResponse(newConnection, response);
SendResponse(newClient, response);
return;
}
@@ -57,12 +57,12 @@ void ConnectionOperator::HandleNewConnection(Connection const & newConnection)
logger.Error(ss.str());
response.code = HttpResponse::Code::NOT_IMPLEMENTED;
SendResponse(newConnection, response);
SendResponse(newClient, response);
return;
}
auto bytesToSend = response.Serialize();
newConnection.WriteBytes(bytesToSend);
newClient.WriteBytes(bytesToSend);
}
ConnectionOperator::ConnectionOperator(Logger & _logger)