Danbias/Code/Network/NetworkDependencies/ThreadedClient.h

60 lines
1.3 KiB
C
Raw Normal View History

#ifndef NETWORK_DEPENDENCIES_THREADED_CLIENT_H
#define NETWORK_DEPENDENCIES_THREADED_CLIENT_H
//////////////////////////////////
// Created by Sam Svensson 2013 //
//////////////////////////////////
#include "../../Misc/Thread/IThreadObject.h"
2013-12-08 23:56:17 +01:00
#include "PostBox.h"
#include "Connection.h"
#include "../../Misc/Thread/OysterThread.h"
#include "../../Misc/Utilities.h"
#include <mutex>
namespace Oyster
{
namespace Network
{
class CustomNetProtocol;
2013-12-08 23:56:17 +01:00
class OysterByte;
class ThreadedClient : public Thread::IThreadObject
{
public:
ThreadedClient();
ThreadedClient(unsigned int socket);
ThreadedClient(IPostBox<CustomNetProtocol*> *postBox, unsigned int socket);
virtual ~ThreadedClient();
void Send(CustomNetProtocol* protocol);
bool IsConnected();
int Connect(unsigned short port, const char serverName[]);
void Disconnect();
void setRecvPostBox(IPostBox<CustomNetProtocol*> *postBox);
protected:
virtual int Send();
virtual int Recv();
//These functions should not be called by any other than the thread.
virtual void ThreadEntry();
virtual void ThreadExit();
virtual bool DoWork();
protected:
Connection* connection;
IPostBox<CustomNetProtocol*> *sendPostBox;
IPostBox<CustomNetProtocol*> *recvPostBox;
Oyster::Thread::OysterThread thread;
std::mutex stdMutex;
};
}
}
#endif