diff options
Diffstat (limited to 'src/ClientConnection.cpp')
-rw-r--r-- | src/ClientConnection.cpp | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/ClientConnection.cpp b/src/ClientConnection.cpp deleted file mode 100644 index c434212..0000000 --- a/src/ClientConnection.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "ClientConnection.h" - -#include <cstring> -#include <iostream> -#include <sstream> -#include <unistd.h> - -ClientConnection::ClientConnection(int socket) - : m_socket_fd(socket) -{ -} - -HttpRequest ClientConnection::read_request() const -{ - // TODO: Clean up this code to ensure it works with multiple lines - // and not risk a buffer overflow. - constexpr int BUFFER_SIZE = 4096; - char buffer[BUFFER_SIZE + 1]; - int n = 0; - - memset(buffer, 0, BUFFER_SIZE); - while ((n = read(m_socket_fd, buffer, BUFFER_SIZE - 1)) > 0) { - if (buffer[n - 1] == '\n') - break; - - memset(buffer, 0, BUFFER_SIZE); - } - - return HttpRequest(buffer); -} - -bool ClientConnection::send(const HttpResponse& response) const -{ - if (!m_is_open) - return false; - - std::string result = response.to_string(); - write(m_socket_fd, result.c_str(), result.length()); - - return true; -} - -void ClientConnection::close_connection() -{ - m_is_open = false; - close(m_socket_fd); -} |