forked from LosaDev/ls-2019-source
LosaDev source snapshot 2019
This commit is contained in:
commit
c198676e97
20588 files changed
+8812878
No files matched your search
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/pool/singleton_pool.hpp>
|
||||
|
||||
template<class T>
|
||||
class BoostPooler
|
||||
{
|
||||
public:
|
||||
static void* operator new(size_t size)
|
||||
{
|
||||
return boost::singleton_pool<T,sizeof(T),boost::default_user_allocator_new_delete,boost::details::pool::null_mutex>::malloc();
|
||||
}
|
||||
static void operator delete(void* p)
|
||||
{
|
||||
boost::singleton_pool<T,sizeof(T),boost::default_user_allocator_new_delete,boost::details::pool::null_mutex>::free(p);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class BoostPoolerL
|
||||
{
|
||||
public:
|
||||
static void* operator new(size_t size)
|
||||
{
|
||||
return boost::singleton_pool<T,sizeof(T),boost::default_user_allocator_new_delete>::malloc();
|
||||
}
|
||||
static void operator delete(void* p)
|
||||
{
|
||||
boost::singleton_pool<T,sizeof(T),boost::default_user_allocator_new_delete>::free(p);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once // AP_SERVER
|
||||
|
||||
#ifndef _AP_BASIC_TYPES_
|
||||
#define _AP_BASIC_TYPES_
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long uint32;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned __int64 uint64;
|
||||
typedef char int8;
|
||||
typedef short int16;
|
||||
typedef long int32;
|
||||
typedef __int64 int64;
|
||||
|
||||
typedef uint64 uniq;
|
||||
typedef uint32 unit;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
// 압축,암호설정 타입
|
||||
enum EncryptTypes
|
||||
{
|
||||
ENCRYPT_OFF = 0,
|
||||
ENCRYPT_ON
|
||||
};
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
class IIocpContext
|
||||
{
|
||||
public:
|
||||
IIocpContext()
|
||||
{}
|
||||
~IIocpContext()
|
||||
{}
|
||||
|
||||
public:
|
||||
virtual BOOL IsActive() = 0;
|
||||
virtual void SetActive( BOOL active ) = 0;
|
||||
|
||||
virtual void Disconnect() = 0;
|
||||
virtual uint32 GetEntity() = 0;
|
||||
virtual uint32 GetIP() = 0;
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
class IIocpContext;
|
||||
|
||||
|
||||
class INetwork
|
||||
{
|
||||
public:
|
||||
INetwork(void);
|
||||
~INetwork(void);
|
||||
|
||||
public:
|
||||
BOOL Flush(IIocpContext *context);
|
||||
|
||||
BOOL Send( IIocpContext *iocpContext,
|
||||
const uint16 command,
|
||||
const uint8* buffer = NULL,
|
||||
const uint16 length = 0,
|
||||
const BOOL encoding = TRUE);
|
||||
|
||||
void Send( const uint32 ID,
|
||||
const uint16 command,
|
||||
const uint8* buffer = NULL,
|
||||
const uint16 length = 0);
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "../include/IIocpContext.h"
|
||||
|
||||
|
||||
class IProcessor
|
||||
{
|
||||
public:
|
||||
IProcessor(void) : m_count(NULL) {}
|
||||
virtual ~IProcessor(void) {}
|
||||
|
||||
void SetCountPointer( volatile LONG& count ) { m_count = &count; }
|
||||
|
||||
public:
|
||||
virtual void Process( IIocpContext* context, const uint32 command, const uint8* buffer, const uint32 length ) = 0;
|
||||
virtual void Process( const uint32 serverId, const uint32 command, const uint8* buffer, const uint32 length ) = 0;
|
||||
|
||||
protected:
|
||||
volatile LONG* m_count;
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
class IProcessor;
|
||||
|
||||
|
||||
class ISystem
|
||||
{
|
||||
public:
|
||||
ISystem(void);
|
||||
~ISystem(void);
|
||||
|
||||
void Init();
|
||||
void Destroy();
|
||||
|
||||
public:
|
||||
BOOL Startup(
|
||||
const uint32 maxSession,
|
||||
const uint32 maxPacket,
|
||||
const uint32 maxQueue,
|
||||
const uint32 encoding=0) const;
|
||||
void Cleanup() const;
|
||||
|
||||
BOOL Start(const int32 workerCount = 4, const int32 commandCount = 1, const int32 connectorCount = 0) const;
|
||||
void Stop() const;
|
||||
|
||||
void SetProcessor(IProcessor* processor) const;
|
||||
void SetEvent(const uint32 connectId, const uint32 disconnectId) const;
|
||||
|
||||
BOOL Listen(const uint16 port, const uint32 backlog) const;
|
||||
BOOL Connect(const uint32 serverId, const TCHAR* IP, const uint16 port) const;
|
||||
|
||||
BOOL Call(const uint32 command, const uint8* buffer, const uint32 length) const;
|
||||
};
|
||||
@@ -0,0 +1,143 @@
|
||||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
#include "cCriticalSection.h"
|
||||
|
||||
|
||||
template <class Type>
|
||||
class MemPooler
|
||||
{
|
||||
public:
|
||||
MemPooler(int nNumofBlock=0, int nMaximumBlock=0, BOOL bThreadSafe=TRUE) :
|
||||
m_nAllocCount(32),
|
||||
m_nNumofBlock(0),
|
||||
m_nMaximumBlock(nMaximumBlock),
|
||||
m_bThreadSafe(bThreadSafe)
|
||||
{
|
||||
m_nBlockSize = sizeof(Type);
|
||||
|
||||
Create(nNumofBlock);
|
||||
}
|
||||
~MemPooler()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
public:
|
||||
void CreatePool(const int nNumofBlock, const int nMaximumBlock=0, BOOL bThreadSafe=TRUE)
|
||||
{
|
||||
m_nNumofBlock = 0;
|
||||
m_nMaximumBlock = nMaximumBlock;
|
||||
m_bThreadSafe = bThreadSafe;
|
||||
|
||||
Create(nNumofBlock);
|
||||
}
|
||||
void DestroyPool()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
public:
|
||||
Type* Pop()
|
||||
{
|
||||
if((m_MemPool.empty()) && (m_nNumofBlock < m_nMaximumBlock))
|
||||
{
|
||||
int allocCount = m_nMaximumBlock - m_nNumofBlock;
|
||||
(allocCount > m_nAllocCount) ? Create(m_nAllocCount) : Create(allocCount);
|
||||
}
|
||||
|
||||
return Get();
|
||||
}
|
||||
|
||||
Type* Remove()
|
||||
{
|
||||
if(m_MemPool.empty())
|
||||
return (NULL);
|
||||
|
||||
return Get();
|
||||
}
|
||||
|
||||
void Push(Type* pBlock)
|
||||
{
|
||||
Lock();
|
||||
m_MemPool.push_back(pBlock);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void Push_Front(Type* pBlock)
|
||||
{
|
||||
Lock();
|
||||
m_MemPool.push_front(pBlock);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
int GetCount() { return m_MemPool.size(); }
|
||||
int GetTotalCount() { return m_nNumofBlock; }
|
||||
|
||||
protected:
|
||||
void Create(const int nNumofBlock)
|
||||
{
|
||||
if(nNumofBlock <= 0) return;
|
||||
|
||||
BYTE *memBlock = new BYTE[m_nBlockSize * nNumofBlock];
|
||||
if(memBlock)
|
||||
{
|
||||
Type *pBlock;
|
||||
int nSegment = 0;
|
||||
for(int i = 0 ; i < nNumofBlock ; i++)
|
||||
{
|
||||
pBlock = reinterpret_cast<Type*>(reinterpret_cast<DWORD>(memBlock) + nSegment);
|
||||
new (pBlock) Type;
|
||||
Push(pBlock);
|
||||
|
||||
nSegment += m_nBlockSize;
|
||||
}
|
||||
m_nNumofBlock += nNumofBlock;
|
||||
}
|
||||
}
|
||||
|
||||
void Destroy()
|
||||
{
|
||||
Type* pBlock = NULL;
|
||||
while((pBlock = Remove()) != NULL)
|
||||
{
|
||||
delete pBlock;
|
||||
}
|
||||
}
|
||||
|
||||
Type* Get()
|
||||
{
|
||||
Type* pBlock = NULL;
|
||||
Lock();
|
||||
if(!m_MemPool.empty())
|
||||
{
|
||||
pBlock = m_MemPool.front();
|
||||
if(pBlock)
|
||||
m_MemPool.pop_front();
|
||||
}
|
||||
Unlock();
|
||||
return (pBlock);
|
||||
}
|
||||
|
||||
void Lock()
|
||||
{
|
||||
if(m_bThreadSafe) m_cs.Lock();
|
||||
}
|
||||
|
||||
void Unlock()
|
||||
{
|
||||
if(m_bThreadSafe) m_cs.Unlock();
|
||||
}
|
||||
|
||||
protected:
|
||||
int m_nAllocCount;
|
||||
int m_nNumofBlock;
|
||||
int m_nMaximumBlock;
|
||||
int m_nBlockSize;
|
||||
BOOL m_bThreadSafe;
|
||||
std::deque<Type*> m_MemPool;
|
||||
|
||||
// For thread-safe.
|
||||
cCriticalSection m_cs;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// cCriticalSection.h: interface for the cCriticalSection class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CCRITICALSECTION_H__DB4999B0_D591_4B20_8D30_B6C442AC1C4B__INCLUDED_)
|
||||
#define AFX_CCRITICALSECTION_H__DB4999B0_D591_4B20_8D30_B6C442AC1C4B__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
|
||||
|
||||
class cCriticalSection
|
||||
{
|
||||
public:
|
||||
cCriticalSection()
|
||||
{
|
||||
InitializeCriticalSection( &m_CriticalSection );
|
||||
}
|
||||
|
||||
~cCriticalSection() { DeleteCriticalSection( &m_CriticalSection ); }
|
||||
|
||||
public:
|
||||
void Lock() { EnterCriticalSection( &m_CriticalSection ); }
|
||||
void Unlock() { LeaveCriticalSection( &m_CriticalSection ); }
|
||||
|
||||
private:
|
||||
CRITICAL_SECTION m_CriticalSection;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // !defined(AFX_CCRITICALSECTION_H__DB4999B0_D591_4B20_8D30_B6C442AC1C4B__INCLUDED_)
|
||||
@@ -0,0 +1,45 @@
|
||||
// cSingleton.h: interface for the cSingleton class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CSINGLETON_H__84137C84_0822_4457_A94B_3A0F1EB45167__INCLUDED_)
|
||||
#define AFX_CSINGLETON_H__84137C84_0822_4457_A94B_3A0F1EB45167__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <class objectT>
|
||||
class cSingleton
|
||||
{
|
||||
private:
|
||||
cSingleton() {}
|
||||
~cSingleton() {}
|
||||
|
||||
public:
|
||||
static objectT* GetInstance()
|
||||
{
|
||||
if( !_this )
|
||||
{
|
||||
_this = new objectT;
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
|
||||
private:
|
||||
static objectT* _this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class objectT>
|
||||
objectT* cSingleton<objectT>::_this;
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // !defined(AFX_CSINGLETON_H__84137C84_0822_4457_A94B_3A0F1EB45167__INCLUDED_)
|
||||
Reference in new issue
Block a user