work in progress
This commit is contained in:
		@ -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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										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();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								Payload.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								Payload.h
									
									
									
									
									
								
							@ -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();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user