work in progress

This commit is contained in:
Debucquoy Anthony 2022-11-06 23:30:21 +01:00
parent f13900156e
commit 8bdf357e1a
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
4 changed files with 45 additions and 2 deletions

View File

@ -3,6 +3,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
#include <string.h>
void Connection::p_HandleError(){ void Connection::p_HandleError(){
std::cout << "an error occured during execution" << std::endl; std::cout << "an error occured during execution" << std::endl;
@ -45,3 +46,23 @@ Connection::Connection(std::string server_ip, int port){
Connection::~Connection(){ Connection::~Connection(){
close(fd); close(fd);
} }
bool Connection::send(std::vector<Payload> 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;
}

View File

@ -3,6 +3,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "Payload.h"
class Payload; class Payload;
@ -26,7 +27,7 @@ public:
~Connection(); ~Connection();
bool send(std::vector<Payload> payload); bool send(std::vector<Payload> payload);
bool recv(void* data, int size); Payload recv();
/** /**
* Return the error code from the last command if there is one * Return the error code from the last command if there is one

View File

@ -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();
}

View File

@ -1,11 +1,19 @@
#ifndef PAYLOAD_H #ifndef PAYLOAD_H
#define PAYLOAD_H #define PAYLOAD_H
#include <stdlib.h>
#include <vector>
class Payload class Payload
{ {
private: private:
std::vector<char> Data;
public: public:
size_t getSize();
char* getData();
void push_char(char);
Payload(); Payload();
virtual ~Payload(); virtual ~Payload();
}; };