From 8bdf357e1a58784c1b46e7ff8886295381862da0 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 6 Nov 2022 23:30:21 +0100 Subject: [PATCH] work in progress --- Connection.cpp | 21 +++++++++++++++++++++ Connection.h | 3 ++- Payload.cpp | 13 +++++++++++++ Payload.h | 10 +++++++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Connection.cpp b/Connection.cpp index a833f54..c0bb40b 100644 --- a/Connection.cpp +++ b/Connection.cpp @@ -3,6 +3,7 @@ #include #include #include +#include void Connection::p_HandleError(){ std::cout << "an error occured during execution" << std::endl; @@ -45,3 +46,23 @@ Connection::Connection(std::string server_ip, int port){ Connection::~Connection(){ close(fd); } + +bool Connection::send(std::vector payloads){ + for (Payload& p : payloads) { + ::send(fd, p.getData() , p.getSize(), 0); + } + return true; +} + +Payload Connection::recv(){ + Payload ret; + char temp[100]; + memset(temp, 0, 100); + ssize_t size; + while((size = ::recv(fd, temp, sizeof(temp), 0)) > 0){ + for(char& in: temp){ + ret.push_char(in); + } + } + return ret; +} diff --git a/Connection.h b/Connection.h index 6e7ab91..64c5cb6 100644 --- a/Connection.h +++ b/Connection.h @@ -3,6 +3,7 @@ #include #include +#include "Payload.h" class Payload; @@ -26,7 +27,7 @@ public: ~Connection(); bool send(std::vector payload); - bool recv(void* data, int size); + Payload recv(); /** * Return the error code from the last command if there is one diff --git a/Payload.cpp b/Payload.cpp index e69de29..91bf955 100644 --- a/Payload.cpp +++ b/Payload.cpp @@ -0,0 +1,13 @@ +#include "Payload.h" + +void Payload::push_char(char load){ + Data.push_back(load); +} + +char* Payload::getData(){ + return Data.data(); +} + +size_t Payload::getSize(){ + return Data.size(); +} diff --git a/Payload.h b/Payload.h index 2f9fa39..b19f22f 100644 --- a/Payload.h +++ b/Payload.h @@ -1,11 +1,19 @@ #ifndef PAYLOAD_H #define PAYLOAD_H +#include +#include + class Payload { private: - + std::vector Data; public: + size_t getSize(); + char* getData(); + + void push_char(char); + Payload(); virtual ~Payload(); };