Trying to implement the sender but its not working the way i want

This commit is contained in:
xX-TheDoctor-Xx
2016-07-18 03:44:27 +01:00
parent a211400964
commit c27ce40bab
21 changed files with 29 additions and 112 deletions

View File

@ -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;

View File

@ -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

View File

@ -11,7 +11,6 @@
#include "Callbacks.hpp"
#include "NetworkBuffer.hpp"
#include "NetworkMessage.hpp"
#include "ThreadPool.hpp"
#include <string>
#include <thread>