feature: Support listening on multiple ports simultaneously
This commit is contained in:
@@ -11,18 +11,52 @@
|
||||
#include "resource.h" // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#include "common/iniFile.h"
|
||||
#include "IOCPServer.h"
|
||||
#include "IOCPUDPServer.h"
|
||||
|
||||
// CMy2015RemoteApp:
|
||||
// <20>йش<D0B9><D8B4><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2015Remote.cpp
|
||||
//
|
||||
|
||||
// ServerPair:
|
||||
// һ<><D2BB>SOCKET<45><54><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>: ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>TCP<43><50>UDP.
|
||||
class ServerPair
|
||||
{
|
||||
private:
|
||||
Server* m_tcpServer;
|
||||
Server* m_udpServer;
|
||||
public:
|
||||
ServerPair() : m_tcpServer(new IOCPServer), m_udpServer(new IOCPUDPServer) {}
|
||||
virtual ~ServerPair() { SAFE_DELETE(m_tcpServer); SAFE_DELETE(m_udpServer); }
|
||||
|
||||
BOOL StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort) {
|
||||
UINT ret1 = m_tcpServer->StartServer(NotifyProc, OffProc, uPort);
|
||||
UINT ret2 = m_udpServer->StartServer(NotifyProc, OffProc, uPort);
|
||||
return (ret1 == 0 || ret2 == 0);
|
||||
}
|
||||
|
||||
void UpdateMaxConnection(int maxConn) {
|
||||
if (m_tcpServer) m_tcpServer->UpdateMaxConnection(maxConn);
|
||||
if (m_udpServer) m_udpServer->UpdateMaxConnection(maxConn);
|
||||
}
|
||||
|
||||
void Destroy() {
|
||||
if (m_tcpServer) m_tcpServer->Destroy();
|
||||
if (m_udpServer) m_udpServer->Destroy();
|
||||
}
|
||||
|
||||
void Disconnect(CONTEXT_OBJECT* ctx) {
|
||||
if (m_tcpServer) m_tcpServer->Disconnect(ctx);
|
||||
if (m_udpServer) m_udpServer->Disconnect(ctx);
|
||||
}
|
||||
};
|
||||
|
||||
class CMy2015RemoteApp : public CWinApp
|
||||
{
|
||||
private:
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1>
|
||||
config* m_iniFile = nullptr;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
||||
std::vector<Server*> m_iocpServer;
|
||||
std::vector<ServerPair*> m_iocpServer;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
HANDLE m_Mutex = nullptr;
|
||||
|
||||
@@ -38,16 +72,25 @@ public:
|
||||
return m_iniFile;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, USHORT uPort) {
|
||||
auto svr = new IOCPServer();
|
||||
UINT ret = svr->StartServer(NotifyProc, OffProc, uPort);
|
||||
if (ret != 0) {
|
||||
SAFE_DELETE(svr);
|
||||
return ret;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||||
// nPortʾ<74><CABE>: 6543;7543
|
||||
UINT StartServer(pfnNotifyProc NotifyProc, pfnOfflineProc OffProc, const std::string& uPort) {
|
||||
bool succeed = false;
|
||||
auto list = StringToVector(uPort, ';');
|
||||
for (int i=0; i<list.size(); ++i)
|
||||
{
|
||||
int port = std::atoi(list[i].c_str());
|
||||
auto svr = new ServerPair();
|
||||
BOOL ret = svr->StartServer(NotifyProc, OffProc, port);
|
||||
if (ret == FALSE) {
|
||||
SAFE_DELETE(svr);
|
||||
continue;
|
||||
}
|
||||
succeed = true;
|
||||
m_iocpServer.push_back(svr);
|
||||
}
|
||||
m_iocpServer.push_back(svr);
|
||||
return 0;
|
||||
|
||||
return succeed ? 0 : -1;
|
||||
}
|
||||
|
||||
// <20>ͷŷ<CDB7><C5B7><EFBFBD><EFBFBD><EFBFBD> SOCKET
|
||||
|
||||
Reference in New Issue
Block a user