work in progress
This commit is contained in:
parent
f13900156e
commit
8bdf357e1a
@ -3,6 +3,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
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<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;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Payload.h"
|
||||
|
||||
class Payload;
|
||||
|
||||
@ -26,7 +27,7 @@ public:
|
||||
~Connection();
|
||||
|
||||
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
|
||||
|
13
Payload.cpp
13
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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user