Reorganize socket classes
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user