1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef _LOCAL_CONNECTION_H
#define _LOCAL_CONNECTION_H
#include <deque>
#include "System/Threading/SpringThreading.h"
#include "Connection.h"
namespace netcode {
/**
* @brief Class for local connection between server / client
* Directly connects the respective input-buffers, to increase performance.
* The server and the client have to run in one instance (same process)
* of spring for this to work.
* Otherwise, a normal UDP connection had to be used.
* IMPORTANT: You must not have more than two instances of this.
*/
class CLocalConnection : public CConnection
{
public:
/**
* @brief Constructor
* @throw network_error When there already 2 instances
*/
CLocalConnection();
virtual ~CLocalConnection();
// START overriding CConnection
void SendData(std::shared_ptr<const RawPacket> packet);
bool HasIncomingData() const;
std::shared_ptr<const RawPacket> Peek(unsigned ahead) const;
std::shared_ptr<const RawPacket> GetData();
void DeleteBufferPacketAt(unsigned index);
void Flush(const bool forced) {}
bool CheckTimeout(int seconds, bool initial) const { return false; }
void ReconnectTo(CConnection& conn) {}
bool CanReconnect() const { return false; }
bool NeedsReconnect() { return false; }
void Unmute() {}
void Close(bool flush);
void SetLossFactor(int factor) {}
unsigned int GetPacketQueueSize() const;
std::string Statistics() const;
std::string GetFullAddress() const;
// END overriding CConnection
private:
static std::deque< std::shared_ptr<const RawPacket> > pqueues[2];
static spring::mutex mutexes[2];
unsigned int OtherInstance() const { return ((instance + 1) % 2); }
/// we can have two instances, one in GameServer and one in NetProtocol
/// (first instance represents server->client and second client->server)
static unsigned int instances;
/// which instance we are
unsigned int instance;
};
} // namespace netcode
#endif // _LOCAL_CONNECTION_H
|