renamed hook to pierog

This commit is contained in:
ags
2021-12-13 20:22:00 +00:00
parent 0a0da5b5a9
commit 545298f26d
9 changed files with 779 additions and 498 deletions

View File

@@ -1,6 +1,7 @@
#include "DataDistributor.h"
#include <utility>
#include <ostream>
DataDistributor::DataDistributor(std::string logPath,
std::string host,
@@ -18,22 +19,24 @@ void DataDistributor::start() {
}
std::thread thread_object([this]() {
bool anythingToSend = true;
long KEEP_ALIVE = 1000;
auto now = std::chrono::system_clock::now();
bool nothingToSend = false;
while(shouldRun) {
auto now = std::chrono::system_clock::now();
if(lock.try_lock()) {
if(sendQueue.empty()) {
auto delay = std::chrono::duration_cast<std::chrono::milliseconds>(now - lastSent);
if(delay.count() > KEEP_ALIVE) {
sendQueue.push_front(new std::string(" "));
} else {
anythingToSend = false;
nothingToSend = true;
}
} else {
auto payload = sendQueue.front();
int sent = socketOutput->write(payload);
lastSent = std::chrono::system_clock::now();
if(sent > 0) {
everSentViaSocket = true;
@@ -45,7 +48,6 @@ void DataDistributor::start() {
sendQueue.push_front(&shortened);
delete payload;
}
lastSent = std::chrono::system_clock::now();
} else {
// failed to send
}
@@ -54,9 +56,7 @@ void DataDistributor::start() {
lock.unlock();
}
if(anythingToSend) {
Sleep(10);
} else {
if(nothingToSend) {
Sleep(100);
}
}

View File

@@ -18,10 +18,6 @@ int SocketOutput::write(std::string *payload) {
}
int bytesSent = send(tcpSocket, payload->c_str(), payload->length(), 0);
if(bytesSent == payload->length()) {
return 0;
}
if(bytesSent > 0) {
return bytesSent;
} else {

View File

@@ -0,0 +1,38 @@
#ifndef PARENT_SOCKETOUTPUT_H
#define PARENT_SOCKETOUTPUT_H
#include "winsock.h"
#include <string>
#include <atomic>
enum enumConnectionState {
DISCONNECTED,
CONNECTED,
NEVER_CONNECTED
};
class SocketOutput {
public:
SocketOutput(std::string host,
int port);
virtual ~SocketOutput();
int write(std::string* payload);
bool isConnected();
private:
SOCKET tcpSocket = INVALID_SOCKET;
SOCKADDR_IN* address = nullptr;
const std::string tcpHost = "localhost";
const int tcpPort = 0;
volatile enumConnectionState connectionState = NEVER_CONNECTED;
bool _connect();
// void reconnect();
void disconnect();
};
#endif //PARENT_SOCKETOUTPUT_H