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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef _LOCAL_CONNECTION_H
#define _LOCAL_CONNECTION_H
#include <boost/thread/mutex.hpp>
#include <deque>
#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(boost::shared_ptr<const RawPacket> data);
bool HasIncomingData() const;
boost::shared_ptr<const RawPacket> Peek(unsigned ahead) const;
void DeleteBufferPacketAt(unsigned index);
boost::shared_ptr<const RawPacket> GetData();
void Flush(const bool forced);
bool CheckTimeout(int seconds, bool initial) const;
void ReconnectTo(CConnection& conn) {}
bool CanReconnect() const;
bool NeedsReconnect();
void Unmute() {}
void Close(bool flush) {}
void SetLossFactor(int factor) {}
std::string Statistics() const;
std::string GetFullAddress() const;
// END overriding CConnection
private:
static std::deque< boost::shared_ptr<const RawPacket> > Data[2];
static boost::mutex Mutex[2];
unsigned OtherInstance() const;
/// we can have 2 instances, one in serverNet and one in net
static unsigned instances;
/// which instance we are
unsigned instance;
};
} // namespace netcode
#endif // _LOCAL_CONNECTION_H
|