Trying to implement the sender but its not working the way i want
This commit is contained in:
@ -3,9 +3,9 @@
|
||||
|
||||
#include "Defs.hpp"
|
||||
#include "NetworkMessage.hpp"
|
||||
#include "ThreadPool.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
@ -30,17 +30,20 @@ public:
|
||||
|
||||
NetworkBuffer ReceiveDataArray();
|
||||
const NetworkMessage &ReceiveData();
|
||||
void StartSender();
|
||||
VoidCode SendMessage(const NetworkMessage &message);
|
||||
|
||||
private:
|
||||
static VoidCode SendNetworkMessage(const NetworkMessage &message, TcpClient *client);
|
||||
void SendNetworkMessage(const NetworkMessage &message);
|
||||
void SendNetworkMessageNow(const NetworkMessage &message);
|
||||
VoidCode Initialize(const std::string &ip, uint16 port = default_port);
|
||||
|
||||
std::string ip;
|
||||
uint16 port = 0;
|
||||
bool initialized;
|
||||
bool initialized = false;
|
||||
bool run_sender = false;
|
||||
|
||||
ThreadPool thread_pool;
|
||||
std::vector<NetworkMessage> network_message_queue;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
SOCKET tcp_socket = INVALID_SOCKET;
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
#ifndef THREAD_POOL_HPP
|
||||
#define THREAD_POOL_HPP
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
ThreadPool(int threads);
|
||||
~ThreadPool();
|
||||
void Enqueue(std::function<void()> f);
|
||||
void Shutdown();
|
||||
const ThreadPool &operator=(ThreadPool &pool);
|
||||
|
||||
private:
|
||||
std::vector<std::thread> threadPool;
|
||||
std::queue<std::function<void()>> tasks;
|
||||
std::mutex tasksMutex;
|
||||
std::condition_variable condition;
|
||||
bool terminate;
|
||||
bool stopped;
|
||||
void Invoke();
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -11,7 +11,6 @@
|
||||
#include "Callbacks.hpp"
|
||||
#include "NetworkBuffer.hpp"
|
||||
#include "NetworkMessage.hpp"
|
||||
#include "ThreadPool.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
Reference in New Issue
Block a user