mirror of
https://bitbucket.org/theswgsource/src-1.2.git
synced 2026-10-08 23:12:52 -04:00
remove SOE deprecated code and files - leaving in the #if 0 blocks with TODO and other possible uses for later
This commit is contained in:
-394
@@ -1,394 +0,0 @@
|
||||
//This code is not used by anything intentionally
|
||||
//The Connection class was getting mistakenly linked in
|
||||
//instead of the SWG Connection class that is used for
|
||||
//all of our connections. Removing the whole thing
|
||||
//to prevent the issue from coming up again.
|
||||
#if 0
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (disable: 4786)
|
||||
#endif
|
||||
|
||||
#include "Base/timer.h"
|
||||
#include "UdpListener.h"
|
||||
#include "Base/profile.h"
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
|
||||
namespace UdpLibrary
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Listener::QueueNode::QueueNode() :
|
||||
connection(0),
|
||||
request(0)
|
||||
{
|
||||
}
|
||||
|
||||
Listener::QueueNode::QueueNode(Connection * con, RequestBase * req) :
|
||||
connection(con),
|
||||
request(req)
|
||||
{
|
||||
}
|
||||
|
||||
Listener::Listener() :
|
||||
mParams(),
|
||||
mUdpManager(0),
|
||||
mConnections(),
|
||||
mConnectionCount(0),
|
||||
mClosedConnections(),
|
||||
mQueuedRequests(),
|
||||
mActiveRequests(),
|
||||
mActiveCount(0),
|
||||
mActiveMax(0)
|
||||
{
|
||||
//printf("ctor 0x%x Listener\n",this);
|
||||
}
|
||||
|
||||
Listener::~Listener()
|
||||
{
|
||||
std::set<Connection *>::iterator iterator;
|
||||
for (iterator = mConnections.begin(); iterator != mConnections.end(); iterator++)
|
||||
{
|
||||
Connection * connection = *iterator;
|
||||
delete connection;
|
||||
}
|
||||
mConnections.clear();
|
||||
|
||||
if (mUdpManager != 0)
|
||||
{
|
||||
mUdpManager->Release();
|
||||
mUdpManager = 0;
|
||||
}
|
||||
|
||||
//printf("dtor 0x%x Listener\n",this);
|
||||
}
|
||||
|
||||
void Listener::RequestSleep(RequestBase * request)
|
||||
{
|
||||
mSleepingRequests.insert(request);
|
||||
}
|
||||
|
||||
void Listener::RequestWake(RequestBase * request)
|
||||
{
|
||||
if (mSleepingRequests.erase(request))
|
||||
{
|
||||
QueueNode node(request->mConnection, request);
|
||||
mActiveRequests.push_front(node);
|
||||
}
|
||||
}
|
||||
|
||||
void Listener::OnConnectRequest(UdpConnection * connection)
|
||||
{
|
||||
if (IsActive())
|
||||
{
|
||||
Connection * connectionObject = new Connection(*this, connection);
|
||||
|
||||
mConnections.insert(connectionObject);
|
||||
mConnectionCount++;
|
||||
|
||||
OnConnectionOpened(connectionObject);
|
||||
}
|
||||
}
|
||||
|
||||
void Listener::QueueRequest(Connection * connection, RequestBase * request)
|
||||
{
|
||||
connection->NotifyQueuedRequest(request);
|
||||
mQueuedRequests.push_back(QueueNode(connection,request));
|
||||
}
|
||||
|
||||
bool Listener::IsIdle() const
|
||||
{
|
||||
return (!IsActive() && !mUdpManager && mQueuedRequests.empty() && !mActiveCount);
|
||||
}
|
||||
|
||||
unsigned Listener::Process()
|
||||
{
|
||||
Profile profile("Listener::Process");
|
||||
////////////////////////////////////////
|
||||
// handle inactive state (with UdpManager)
|
||||
if (!IsActive() && mUdpManager)
|
||||
{
|
||||
// check all connections to see if they are idle
|
||||
std::set<Connection *>::iterator iterator;
|
||||
for (iterator = mConnections.begin(); iterator != mConnections.end(); iterator++)
|
||||
{
|
||||
Connection * connection = *iterator;
|
||||
if (connection->IsConnected())
|
||||
connection->Disconnect();
|
||||
}
|
||||
// close the UdpManager if all the connections are closed
|
||||
if (!mConnectionCount)
|
||||
{
|
||||
mUdpManager->Release();
|
||||
mUdpManager = 0;
|
||||
OnShutdown();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
// handle active state (without UdpManager)
|
||||
else if (IsActive() && !mUdpManager)
|
||||
{
|
||||
mParams = GetConnectionParams();
|
||||
mParams.handler = this;
|
||||
mActiveMax = GetActiveRequestMax();
|
||||
mUdpManager = new UdpManager(&mParams);
|
||||
OnStartup();
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// process the UdpManager
|
||||
if (mUdpManager)
|
||||
{
|
||||
Profile subProfile("UdpManager::GiveTime()");
|
||||
mUdpManager->GiveTime();
|
||||
}
|
||||
|
||||
// check all closed connections to see if they are idle
|
||||
std::list<Connection *>::iterator closedIterator = mClosedConnections.begin();
|
||||
while (closedIterator != mClosedConnections.end())
|
||||
{
|
||||
Profile profile("Listener::Process (cleanup connection)");
|
||||
std::list<Connection *>::iterator current = closedIterator++;
|
||||
Connection * connection = *current;
|
||||
if (!connection->GetActiveRequests() &&
|
||||
!connection->GetQueuedRequests())
|
||||
{
|
||||
mClosedConnections.erase(current);
|
||||
mConnections.erase(connection);
|
||||
mConnectionCount--;
|
||||
OnConnectionDestroyed(connection);
|
||||
delete connection;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// process request queue
|
||||
while (!mQueuedRequests.empty() && (!mActiveMax || mActiveCount < mActiveMax))
|
||||
{
|
||||
Profile profile("Listener::Process (activate queued request)");
|
||||
QueueNode & node = mQueuedRequests.front();
|
||||
if (!IsActive())
|
||||
{
|
||||
// If not active, discard queued request
|
||||
node.connection->NotifyDiscardRequest(node.request);
|
||||
DestroyRequest(node.request);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move request to active list
|
||||
node.connection->NotifyBeginRequest(node.request);
|
||||
mActiveRequests.push_back(node);
|
||||
mActiveCount++;
|
||||
}
|
||||
mQueuedRequests.pop_front();
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Process active requests
|
||||
unsigned requestsProcessed = 0;
|
||||
std::list<QueueNode>::iterator iterator = mActiveRequests.begin();
|
||||
while (iterator != mActiveRequests.end())
|
||||
{
|
||||
Profile profile("Listener::Process (process request)");
|
||||
std::list<QueueNode>::iterator current = iterator++;
|
||||
RequestBase * request = current->request;
|
||||
Connection * connection = current->connection;
|
||||
|
||||
if (request->Process())
|
||||
{
|
||||
connection->NotifyEndRequest(request);
|
||||
DestroyRequest(request);
|
||||
mActiveRequests.erase(current);
|
||||
mActiveCount--;
|
||||
}
|
||||
else if (mSleepingRequests.find(request) != mSleepingRequests.end())
|
||||
{
|
||||
mActiveRequests.erase(current);
|
||||
}
|
||||
requestsProcessed++;
|
||||
}
|
||||
return requestsProcessed;
|
||||
}
|
||||
|
||||
void Listener::GetStats(UdpManagerStatistics & statsStruct)
|
||||
{
|
||||
if (mUdpManager)
|
||||
mUdpManager->GetStats(&statsStruct);
|
||||
}
|
||||
|
||||
void Listener::ResetStats()
|
||||
{
|
||||
if (mUdpManager)
|
||||
mUdpManager->ResetStats();
|
||||
}
|
||||
|
||||
void Listener::OnStartup()
|
||||
{
|
||||
}
|
||||
|
||||
void Listener::OnShutdown()
|
||||
{
|
||||
}
|
||||
|
||||
void Listener::OnConnectionOpened(Connection * connection)
|
||||
{
|
||||
}
|
||||
|
||||
void Listener::OnConnectionClosed(Connection * connection, const char * reason)
|
||||
{
|
||||
}
|
||||
|
||||
void Listener::OnConnectionDestroyed(Connection * connection)
|
||||
{
|
||||
}
|
||||
|
||||
void Listener::OnCrcReject(Connection *connection, const unsigned char * buffer, unsigned size)
|
||||
{
|
||||
}
|
||||
|
||||
void Listener::OnPacketCorrupt(Connection *con, const unsigned char *data, int dataLen, UdpCorruptionReason reason)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Connection::Connection(Listener & listener, UdpConnection * connection) :
|
||||
mListener(listener),
|
||||
mConnection(connection),
|
||||
mHost(),
|
||||
mHostIp(0),
|
||||
mDisconnectReason(0),
|
||||
mQueuedRequests(0),
|
||||
mActiveRequests(0)
|
||||
{
|
||||
mConnection->AddRef();
|
||||
mConnection->SetHandler(this);
|
||||
|
||||
char buffer[256];
|
||||
char addr[32];
|
||||
mHostIp = mConnection->GetDestinationIp().GetAddress();
|
||||
mConnection->GetDestinationIp().GetAddress(addr);
|
||||
snprintf(buffer, sizeof(buffer), "%s:%u", addr, mConnection->GetDestinationPort());
|
||||
mHost = buffer;
|
||||
|
||||
//printf("ctor 0x%x connection\n",this);
|
||||
}
|
||||
|
||||
Connection::~Connection()
|
||||
{
|
||||
Disconnect();
|
||||
|
||||
//printf("dtor 0x%x connection\n",this);
|
||||
}
|
||||
|
||||
unsigned Connection::Send(const unsigned char * data, unsigned dataLen)
|
||||
{
|
||||
if (mConnection)
|
||||
{
|
||||
mConnection->Send(cUdpChannelReliable1, data, dataLen);
|
||||
return dataLen;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Connection::Disconnect()
|
||||
{
|
||||
if (mConnection)
|
||||
OnTerminated(mConnection);
|
||||
}
|
||||
|
||||
bool Connection::IsConnected() const
|
||||
{
|
||||
return mConnection != 0;
|
||||
}
|
||||
|
||||
const std::string & Connection::GetHost() const
|
||||
{
|
||||
return mHost;
|
||||
}
|
||||
|
||||
const unsigned Connection::GetHostIP() const
|
||||
{
|
||||
return mHostIp;
|
||||
}
|
||||
|
||||
unsigned Connection::GetQueuedRequests() const
|
||||
{
|
||||
return mQueuedRequests;
|
||||
}
|
||||
|
||||
unsigned Connection::GetActiveRequests() const
|
||||
{
|
||||
return mActiveRequests;
|
||||
}
|
||||
|
||||
void Connection::OnTerminated(UdpConnection *con)
|
||||
{
|
||||
mConnection->SetHandler(0);
|
||||
mConnection->Disconnect();
|
||||
UdpConnection::DisconnectReason disconnectReason = mConnection->GetDisconnectReason();
|
||||
mConnection->Release();
|
||||
mConnection = 0;
|
||||
mListener.mClosedConnections.push_back(this);
|
||||
mListener.OnConnectionClosed(this, UdpConnection::DisconnectReasonText(disconnectReason));
|
||||
}
|
||||
|
||||
void Connection::OnRoutePacket(UdpConnection *, const unsigned char * data, int dataLen)
|
||||
{
|
||||
mListener.OnReceive(this, data, dataLen);
|
||||
}
|
||||
|
||||
void Connection::OnCrcReject(UdpConnection *, const unsigned char * data, int dataLen)
|
||||
{
|
||||
mListener.OnCrcReject(this, data, dataLen);
|
||||
}
|
||||
|
||||
void Connection::OnPacketCorrupt(UdpConnection *, const uchar *data, int dataLen, UdpCorruptionReason reason)
|
||||
{
|
||||
mListener.OnPacketCorrupt(this, data, dataLen, reason);
|
||||
}
|
||||
|
||||
void Connection::NotifyQueuedRequest(RequestBase * request)
|
||||
{
|
||||
mQueuedRequests++;
|
||||
}
|
||||
|
||||
void Connection::NotifyDiscardRequest(RequestBase * request)
|
||||
{
|
||||
mQueuedRequests--;
|
||||
}
|
||||
|
||||
void Connection::NotifyBeginRequest(RequestBase * request)
|
||||
{
|
||||
mQueuedRequests--;
|
||||
mActiveRequests++;
|
||||
}
|
||||
|
||||
void Connection::NotifyEndRequest(RequestBase * request)
|
||||
{
|
||||
mActiveRequests--;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
RequestBase::RequestBase(Connection * connection) :
|
||||
mConnection(connection),
|
||||
mProcessState(0)
|
||||
{
|
||||
}
|
||||
|
||||
RequestBase::~RequestBase()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
-145
@@ -1,145 +0,0 @@
|
||||
//This code is not used by anything intentionally
|
||||
//The Connection class was getting mistakenly linked in
|
||||
//instead of the SWG Connection class that is used for
|
||||
//all of our connections. Removing the whole thing
|
||||
//to prevent the issue from coming up again.
|
||||
#if 0
|
||||
|
||||
#ifndef COMMON_SERVER__LISTENER_H
|
||||
#define COMMON_SERVER__LISTENER_H
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include "UdpLibrary.hpp"
|
||||
|
||||
namespace UdpLibrary
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class RequestBase;
|
||||
class Connection;
|
||||
class Listener : public UdpManagerHandler
|
||||
{
|
||||
friend class Connection;
|
||||
struct QueueNode
|
||||
{
|
||||
QueueNode();
|
||||
QueueNode(Connection * connection, RequestBase * request);
|
||||
bool operator<(const QueueNode & rhs) { return request < rhs.request; }
|
||||
|
||||
Connection * connection;
|
||||
RequestBase * request;
|
||||
};
|
||||
|
||||
public:
|
||||
Listener();
|
||||
virtual ~Listener();
|
||||
|
||||
void QueueRequest(Connection * connection, RequestBase * request);
|
||||
bool IsIdle() const;
|
||||
unsigned Process();
|
||||
void GetStats(UdpManagerStatistics & statsStruct);
|
||||
void ResetStats();
|
||||
|
||||
void RequestSleep(RequestBase * request);
|
||||
void RequestWake(RequestBase * request);
|
||||
|
||||
virtual bool IsActive() const = 0;
|
||||
virtual unsigned GetActiveRequestMax() = 0;
|
||||
virtual UdpManager::Params GetConnectionParams() = 0;
|
||||
|
||||
virtual void OnStartup();
|
||||
virtual void OnShutdown();
|
||||
virtual void OnConnectionOpened(Connection * connection);
|
||||
virtual void OnConnectionClosed(Connection * connection, const char * reason);
|
||||
virtual void OnConnectionDestroyed(Connection * connection);
|
||||
virtual void OnReceive(Connection * connection, const unsigned char * data, unsigned dataLen) = 0;
|
||||
virtual void OnCrcReject(Connection *connection, const unsigned char * data, unsigned dataLen);
|
||||
virtual void OnPacketCorrupt(Connection *con, const unsigned char *data, int dataLen, UdpCorruptionReason reason);
|
||||
virtual void DestroyRequest(RequestBase * request) = 0;
|
||||
|
||||
virtual void OnConnectRequest(UdpConnection *con);
|
||||
|
||||
protected:
|
||||
UdpManager::Params mParams;
|
||||
UdpManager * mUdpManager;
|
||||
|
||||
std::set<Connection *> mConnections;
|
||||
unsigned mConnectionCount;
|
||||
std::list<Connection *> mClosedConnections;
|
||||
|
||||
std::list<QueueNode> mQueuedRequests;
|
||||
std::list<QueueNode> mActiveRequests;
|
||||
std::set<RequestBase *> mSleepingRequests;
|
||||
unsigned mActiveCount;
|
||||
unsigned mActiveMax;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class Connection : public UdpConnectionHandler
|
||||
{
|
||||
friend class Listener;
|
||||
public:
|
||||
Connection(Listener & listener, UdpConnection * connection);
|
||||
virtual ~Connection();
|
||||
|
||||
unsigned Send(const uchar * data, unsigned dataLen);
|
||||
void Disconnect();
|
||||
bool IsConnected() const;
|
||||
|
||||
const std::string & GetHost() const;
|
||||
const unsigned GetHostIP() const;
|
||||
unsigned GetQueuedRequests() const;
|
||||
unsigned GetActiveRequests() const;
|
||||
|
||||
virtual void OnTerminated(UdpConnection *con);
|
||||
virtual void OnRoutePacket(UdpConnection *con, const uchar *data, int dataLen);
|
||||
virtual void OnCrcReject(UdpConnection *con, const uchar *data, int dataLen);
|
||||
virtual void OnPacketCorrupt(UdpConnection *con, const uchar *data, int dataLen, UdpCorruptionReason reason);
|
||||
|
||||
protected:
|
||||
void NotifyQueuedRequest(RequestBase * request);
|
||||
void NotifyDiscardRequest(RequestBase * request);
|
||||
void NotifyBeginRequest(RequestBase * request);
|
||||
void NotifyEndRequest(RequestBase * request);
|
||||
|
||||
protected:
|
||||
Listener & mListener;
|
||||
UdpConnection * mConnection;
|
||||
std::string mHost;
|
||||
unsigned mHostIp;
|
||||
const char * mDisconnectReason;
|
||||
unsigned mQueuedRequests;
|
||||
unsigned mActiveRequests;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class RequestBase
|
||||
{
|
||||
friend class Listener;
|
||||
public:
|
||||
RequestBase(Connection * connection);
|
||||
virtual ~RequestBase();
|
||||
|
||||
virtual bool Process() = 0;
|
||||
|
||||
protected:
|
||||
Connection * mConnection;
|
||||
unsigned mProcessState;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user