Connection and payload quite done
This commit is contained in:
@@ -47,22 +47,37 @@ Connection::~Connection(){
|
||||
close(fd);
|
||||
}
|
||||
|
||||
bool Connection::send(std::vector<Payload> payloads){
|
||||
bool Connection::send(std::vector<Payload> payloads, bool size){
|
||||
if(size){
|
||||
unsigned char _size = payloads.size();
|
||||
::send(fd, &_size , sizeof(_size), 0);
|
||||
}
|
||||
for (Payload& p : payloads) {
|
||||
::send(fd, p.getData() , p.getSize(), 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Connection::send(Payload payload, bool size){
|
||||
return send(std::vector<Payload>{payload}, size);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ssize_t size = 0, bytes;
|
||||
std::vector<unsigned char> received(100);
|
||||
while((bytes = ::recv(fd, received.data() + size, 100, 0)) > 0){
|
||||
size += bytes;
|
||||
received.resize(size+100);
|
||||
}
|
||||
if(bytes == 0){
|
||||
received.shrink_to_fit();
|
||||
ret.setData(received);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//Error Handling
|
||||
error = ErrorTypes::recv;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user