PICloud with streampacker

This commit is contained in:
2021-04-07 14:38:32 +03:00
parent fcf9f0f80e
commit 1fd9851068
13 changed files with 90 additions and 67 deletions

View File

@@ -21,6 +21,7 @@
#include "picrypt.h"
#include "pichunkstream.h"
#include "piethernet.h"
#include "pistreampacker.h"
const char hash_def_key[] = "_picrypt_";
@@ -31,9 +32,9 @@ PICloud::TCP::Header::Header() {
}
PICloud::TCP::TCP() {
}
PICloud::TCP::TCP(PIStreamPacker * s) : streampacker(s) {
}
void PICloud::TCP::setRole(PICloud::TCP::Role r) {
header.role = r;
@@ -45,53 +46,55 @@ void PICloud::TCP::setServerName(const PIString & server_name) {
}
void PICloud::TCP::sendStart(PIEthernet * eth) {
void PICloud::TCP::sendStart() {
piCout << "sendStart";
header.type = PICloud::TCP::Connect;
PIByteArray ba;
ba << header << sname;
eth->send(ba);
streampacker->send(ba);
}
void PICloud::TCP::sendConnected(PIEthernet * eth, uint client_id) {
void PICloud::TCP::sendConnected(uint client_id) {
header.type = PICloud::TCP::Connect;
PIByteArray ba;
ba << header << client_id;
eth->send(ba);
streampacker->send(ba);
}
void PICloud::TCP::sendDisconnected(PIEthernet * eth, uint client_id) {
void PICloud::TCP::sendDisconnected(uint client_id) {
header.type = PICloud::TCP::Disconnect;
PIByteArray ba;
ba << header << client_id;
eth->send(ba);
streampacker->send(ba);
}
void PICloud::TCP::sendData(PIEthernet * eth, const PIByteArray & data) {
void PICloud::TCP::sendData(const PIByteArray & data) {
header.type = PICloud::TCP::Data;
PIByteArray ba;
ba << header;
ba.append(data);
// piCout << "sendData" << ba.toHex();
eth->send(ba);
streampacker->send(ba);
}
int PICloud::TCP::sendData(PIEthernet * eth, const PIByteArray & data, uint client_id) {
int PICloud::TCP::sendData(const PIByteArray & data, uint client_id) {
header.type = PICloud::TCP::Data;
PIByteArray ba;
ba << header << client_id;
ba.append(data);
if (eth->send(ba)) return data.size_s();
else return -1;
streampacker->send(ba);
return data.size_s();
}
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> PICloud::TCP::parseHeader(PIByteArray & ba) {
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> ret;
ret.first = Invalid;
ret.first = InvalidType;
ret.second = InvalidRole;
if (ba.size() < sizeof(Header)) return ret;
PICloud::TCP::Header hdr;
ba >> hdr;