mirror of
https://github.com/DaKerboul/perun.git
synced 2026-08-09 19:05:39 +02:00
renamed hook to pierog
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
38
03_Perun_Lua_Wrapper/pierog/src/SocketOutput.h
Normal file
38
03_Perun_Lua_Wrapper/pierog/src/SocketOutput.h
Normal 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
|
||||
Reference in New Issue
Block a user