Skip to content

Commit 212bffc

Browse files
committed
VersionManager: Strip "client" sockets
"Client" sockets as in the VersionManager acts as a client to connect to something else. Stripping these as they're unused and reduce the overall code to migrate.
1 parent 1abd2a8 commit 212bffc

6 files changed

Lines changed: 11 additions & 270 deletions

File tree

Server/VersionManager/Define.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
constexpr int MAX_USER = 3000;
1515

1616
constexpr int _LISTEN_PORT = 15100;
17-
constexpr int CLIENT_SOCKSIZE = 10;
1817
constexpr int DB_PROCESS_TIMEOUT = 100;
1918

2019
////////////////////////////////////////////////////////////
@@ -33,10 +32,6 @@ constexpr int DB_PROCESS_TIMEOUT = 100;
3332
#define STATE_DISCONNECTED 0X02
3433
#define STATE_GAMESTART 0x03
3534

36-
// Socket type
37-
#define TYPE_ACCEPT 0x01
38-
#define TYPE_CONNECT 0x02
39-
4035
// Overlapped flag
4136
#define OVL_RECEIVE 0X01
4237
#define OVL_SEND 0X02

Server/VersionManager/IOCPSocket2.cpp

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ CIOCPSocket2::CIOCPSocket2()
2222
m_Socket = INVALID_SOCKET;
2323

2424
m_pIOCPort = nullptr;
25-
m_Type = TYPE_ACCEPT;
2625
}
2726

2827
CIOCPSocket2::~CIOCPSocket2()
@@ -54,49 +53,6 @@ bool CIOCPSocket2::Create(UINT nSocketPort, int nSocketType, long lEvent, const
5453
return true;
5554
}
5655

57-
bool CIOCPSocket2::Connect(CIOCPort* pIocp, const char* lpszHostAddress, UINT nHostPort)
58-
{
59-
sockaddr_in addr;
60-
61-
memset(&addr, 0, sizeof(addr));
62-
addr.sin_family = AF_INET;
63-
addr.sin_addr.s_addr = inet_addr(lpszHostAddress);
64-
addr.sin_port = htons(nHostPort);
65-
66-
int result = connect(m_Socket, (sockaddr*) &addr, sizeof(addr));
67-
if (result == SOCKET_ERROR)
68-
{
69-
int err = WSAGetLastError();
70-
// TRACE("CONNECT FAIL : %d\n", err);
71-
closesocket(m_Socket);
72-
return false;
73-
}
74-
75-
ASSERT(pIocp);
76-
77-
InitSocket(pIocp);
78-
79-
m_Sid = m_pIOCPort->GetClientSid();
80-
if (m_Sid < 0)
81-
return false;
82-
83-
m_pIOCPort->m_ClientSockArray[m_Sid] = this;
84-
85-
if (!m_pIOCPort->Associate(this, m_pIOCPort->m_hClientIOCPort))
86-
{
87-
spdlog::error("IOCPSocket2::Connect: failed to associate");
88-
return false;
89-
}
90-
91-
m_ConnectAddress = lpszHostAddress;
92-
m_State = STATE_CONNECTED;
93-
m_Type = TYPE_CONNECT;
94-
95-
Receive();
96-
97-
return true;
98-
}
99-
10056
int CIOCPSocket2::Send(char* pBuf, long length, int dwFlag)
10157
{
10258
int ret_value = 0;
@@ -172,11 +128,7 @@ int CIOCPSocket2::Send(char* pBuf, long length, int dwFlag)
172128
pOvl = &m_RecvOverlapped;
173129
pOvl->Offset = OVL_CLOSE;
174130

175-
if (m_Type == TYPE_ACCEPT)
176-
hComport = m_pIOCPort->m_hServerIOCPort;
177-
else
178-
hComport = m_pIOCPort->m_hClientIOCPort;
179-
131+
hComport = m_pIOCPort->m_hServerIOCPort;
180132
PostQueuedCompletionStatus(hComport, 0, m_Sid, pOvl);
181133

182134
return -1;
@@ -237,11 +189,7 @@ int CIOCPSocket2::Receive()
237189
pOvl = &m_RecvOverlapped;
238190
pOvl->Offset = OVL_CLOSE;
239191

240-
if (m_Type == TYPE_ACCEPT)
241-
hComport = m_pIOCPort->m_hServerIOCPort;
242-
else
243-
hComport = m_pIOCPort->m_hClientIOCPort;
244-
192+
hComport = m_pIOCPort->m_hServerIOCPort;
245193
PostQueuedCompletionStatus(hComport, 0, m_Sid, pOvl);
246194

247195
return -1;
@@ -351,27 +299,6 @@ bool CIOCPSocket2::PullOutCore(char*& data, int& length)
351299
return foundCore;
352300
}
353301

354-
bool CIOCPSocket2::AsyncSelect(long lEvent)
355-
{
356-
int retEventResult, err;
357-
358-
retEventResult = WSAEventSelect(m_Socket, m_hSockEvent, lEvent);
359-
err = WSAGetLastError();
360-
return (retEventResult == 0);
361-
}
362-
363-
bool CIOCPSocket2::SetSockOpt(int nOptionName, const void* lpOptionValue, int nOptionLen, int nLevel)
364-
{
365-
int retValue = setsockopt(m_Socket, nLevel, nOptionName, (char*) lpOptionValue, nOptionLen);
366-
return (retValue == 0);
367-
}
368-
369-
bool CIOCPSocket2::ShutDown(int nHow)
370-
{
371-
int retValue = shutdown(m_Socket, nHow);
372-
return (retValue == 0);
373-
}
374-
375302
void CIOCPSocket2::Close()
376303
{
377304
if (m_pIOCPort == nullptr)
@@ -382,10 +309,7 @@ void CIOCPSocket2::Close()
382309
pOvl = &m_RecvOverlapped;
383310
pOvl->Offset = OVL_CLOSE;
384311

385-
if (m_Type == TYPE_ACCEPT)
386-
hComport = m_pIOCPort->m_hServerIOCPort;
387-
else
388-
hComport = m_pIOCPort->m_hClientIOCPort;
312+
hComport = m_pIOCPort->m_hServerIOCPort;
389313

390314
int retValue = PostQueuedCompletionStatus(hComport, 0, m_Sid, pOvl);
391315
if (retValue == 0)

Server/VersionManager/IOCPSocket2.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,16 @@
1212
#include "IOCPort.h"
1313
#include "Define.h"
1414

15-
#define receives 0
16-
#define sends 1
17-
#define both 2
18-
1915
class CCircularBuffer;
20-
2116
class CIOCPSocket2
2217
{
2318
public:
2419
void InitSocket(CIOCPort* pIOCPort);
2520
void Close();
26-
bool AsyncSelect(long lEvent = FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE);
27-
bool SetSockOpt(int nOptionName, const void* lpOptionValue, int nOptionLen, int nLevel = SOL_SOCKET);
28-
bool ShutDown(int nHow = sends);
2921
bool PullOutCore(char*& data, int& length);
3022
void ReceivedData(int length);
3123
int Receive();
3224
int Send(char* pBuf, long length, int dwFlag = 0);
33-
bool Connect(CIOCPort* pIocp, const char* lpszHostAddress, UINT nHostPort);
3425
bool Create(UINT nSocketPort = 0,
3526
int nSocketType = SOCK_STREAM,
3627
long lEvent = FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE,
@@ -53,10 +44,6 @@ class CIOCPSocket2
5344
return m_State;
5445
}
5546

56-
uint8_t GetSockType() const {
57-
return m_Type;
58-
}
59-
6047
virtual void CloseProcess();
6148
virtual void Parsing(int length, char* pData);
6249
virtual void Initialize();
@@ -82,7 +69,6 @@ class CIOCPSocket2
8269
OVERLAPPED m_RecvOverlapped;
8370
OVERLAPPED m_SendOverlapped;
8471

85-
uint8_t m_Type;
8672
uint8_t m_State;
8773
int m_Sid;
8874
std::string m_ConnectAddress;

0 commit comments

Comments
 (0)