@@ -6,15 +6,15 @@ bool IOCP_Server::initServer()
6
6
7
7
int nRet = WSAStartup (MAKEWORD (2 , 2 ), &wsaData);
8
8
if (0 != nRet) {
9
- spdlog::error (" WSAStartup() 함수 실패 : {}" , WSAGetLastError ());
9
+ spdlog::error (" WSAStartup() Function failure : {}" , WSAGetLastError ());
10
10
return false ;
11
11
}
12
12
13
13
// 연결지향형 TCP , Overlapped I/O 소켓을 생성
14
14
listenSocket = WSASocket (AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL , NULL , WSA_FLAG_OVERLAPPED);
15
15
16
16
if (INVALID_SOCKET == listenSocket) {
17
- spdlog::error (" socket() 함수 실패 : {}" , WSAGetLastError ());
17
+ spdlog::error (" socket() Function failure : {}" , WSAGetLastError ());
18
18
return false ;
19
19
}
20
20
@@ -36,15 +36,15 @@ bool IOCP_Server::BindandListen(const u_short port)
36
36
// int nRet = ::bind(listenSocket, (SOCKADDR*)&stServerAddr, sizeof(SOCKADDR_IN));
37
37
int nRet = ::bind (listenSocket, reinterpret_cast <sockaddr *>(&stServerAddr), sizeof (SOCKADDR_IN));
38
38
if (0 != nRet) {
39
- spdlog::error (" bind() 함수 실패 : {}" , WSAGetLastError ());
39
+ spdlog::error (" bind() Function failure : {}" , WSAGetLastError ());
40
40
return false ;
41
41
}
42
42
43
43
// 접속 요청을 받아들이기 위해 cIOCompletionPort소켓을 등록하고
44
44
// 접속 대기큐를 5개로 설정 한다.
45
45
nRet = ::listen (listenSocket, 5 );
46
46
if (0 != nRet) {
47
- spdlog::error (" listen() 함수 실패 : {}" , WSAGetLastError ());
47
+ spdlog::error (" listen() Function failure : {}" , WSAGetLastError ());
48
48
return false ;
49
49
}
50
50
@@ -62,7 +62,7 @@ bool IOCP_Server::StartServer()
62
62
// CompletionPort객체 생성 요청을 한다.
63
63
g_hiocp = CreateIoCompletionPort (INVALID_HANDLE_VALUE, NULL , NULL , MAX_WORKERTHREAD);
64
64
if (NULL == g_hiocp) {
65
- spdlog::error (" CreateIoCompletionPort() 함수 실패 : {}" , GetLastError ());
65
+ spdlog::error (" CreateIoCompletionPort() Function failure : {}" , GetLastError ());
66
66
return false ;
67
67
}
68
68
@@ -168,14 +168,12 @@ void IOCP_Server::WokerThread()
168
168
// client가 접속을 끊었을때..
169
169
if (FALSE == bSuccess || (0 == dwIoSize && TRUE == bSuccess))
170
170
{
171
- spdlog::info (" Socket 접속 끊김 / [unique_id:{}]" , (int )pPlayerSession->get_unique_id ());
172
- spdlog::info (" Total Packet Count : {}" , packet_cnt);
171
+ spdlog::info (" Socket Disconnected / [unique_id:{}]" , (int )pPlayerSession->get_unique_id ());
173
172
ClosePlayer (pPlayerSession->get_unique_id ());
174
173
CloseSocket (pPlayerSession);
175
174
continue ;
176
175
}
177
176
178
-
179
177
stOverlappedEx* pOverlappedEx = (stOverlappedEx*)lpOverlapped;
180
178
// Overlapped I/O Recv작업 결과 뒤 처리
181
179
switch (pOverlappedEx->m_eOperation ) {
@@ -193,7 +191,8 @@ void IOCP_Server::WokerThread()
193
191
default :
194
192
{
195
193
// 예외 상황
196
- spdlog::critical (" [Exception WokerThread({})] No value defined..!" , (int )pOverlappedEx->m_eOperation );
194
+ spdlog::critical (" [Exception WokerThread({})] No value defined..! / [unique_id:{}]" ,
195
+ (int )pOverlappedEx->m_eOperation , pPlayerSession->get_unique_id ());
197
196
}
198
197
break ;
199
198
@@ -261,7 +260,7 @@ bool IOCP_Server::SendPacket(class PLAYER_Session * pPlayerSession, char * pMsg,
261
260
// socket_error이면 client socket이 끊어진걸로 처리한다.
262
261
if (nRet == SOCKET_ERROR && (WSAGetLastError () != ERROR_IO_PENDING))
263
262
{
264
- spdlog::error (" WSASend() 함수 실패 : {}" , WSAGetLastError ());
263
+ spdlog::error (" WSASend() Function failure : {} / [unique_id:{}] " , WSAGetLastError (), pPlayerSession-> get_unique_id ());
265
264
ClosePlayer (pPlayerSession->get_unique_id ());
266
265
CloseSocket (pPlayerSession);
267
266
return false ;
@@ -274,7 +273,7 @@ void IOCP_Server::OnRecv(struct stOverlappedEx* pOver, int ioSize)
274
273
// 플레이어 세션 에서 플레이어 데이터 가져오기
275
274
auto pTempPlayerSession = player_session.find (pOver->m_unique_id ); // getPlayerSession(pOver->m_unique_id);
276
275
if (pTempPlayerSession == player_session.end ()) {
277
- spdlog::error (" No Exit Session [unique_id:{}]" , pOver->m_unique_id );
276
+ spdlog::error (" No Exit Session / [unique_id:{}]" , pOver->m_unique_id );
278
277
return ;
279
278
}
280
279
auto pPlayerSession = pTempPlayerSession->second ;
@@ -285,7 +284,7 @@ void IOCP_Server::OnRecv(struct stOverlappedEx* pOver, int ioSize)
285
284
// 쓰기를 위한 위치를 옮겨준다.
286
285
if (!pPlayerSession->get_buffer ().moveWritePos (ioSize))
287
286
{
288
- spdlog::error (" ReadBuffer Over Flow [unique_id:{}]" , pPlayerSession->get_unique_id ());
287
+ spdlog::error (" ReadBuffer Over Flow / [unique_id:{}]" , pPlayerSession->get_unique_id ());
289
288
}
290
289
291
290
PACKET_HEADER header;
@@ -309,7 +308,7 @@ void IOCP_Server::OnRecv(struct stOverlappedEx* pOver, int ioSize)
309
308
// Packet_Header 를 가져온다.
310
309
auto PacketSize = pPlayerSession->get_buffer ().getHeaderSize ((char *)&header, sizeof (header));
311
310
if (PacketSize == -1 ) {
312
- spdlog::error (" getHeaderSize [unique_id:{}]" , pPlayerSession->get_unique_id ());
311
+ spdlog::error (" getHeaderSize / [unique_id:{}]" , pPlayerSession->get_unique_id ());
313
312
}
314
313
315
314
if (pPlayerSession->get_buffer ().getReadAbleSize () < header.packet_len || header.packet_len <= PACKET_HEADER_BYTE) {
@@ -318,7 +317,7 @@ void IOCP_Server::OnRecv(struct stOverlappedEx* pOver, int ioSize)
318
317
header.packet_len , PACKET_HEADER_BYTE, pPlayerSession->get_buffer ().getReadAbleSize (), header.packet_len , pPlayerSession->get_unique_id ());
319
318
// Packet 사이즈가 Header 크기보다 작을 경우 Error count를 올린다.
320
319
if (header.packet_len <= PACKET_HEADER_BYTE) {
321
- pPlayerSession->set_error_cnt ();
320
+ pPlayerSession->update_error_cnt ();
322
321
}
323
322
break ;
324
323
}
@@ -401,7 +400,7 @@ void IOCP_Server::AccepterThread()
401
400
// I/O Completion Port객체와 소켓을 연결시킨다.
402
401
bool bRet = BindIOCompletionPort (pPlayerSession);
403
402
if (false == bRet) {
404
- spdlog::error (" BindIOCompletionPort() 함수 실패 : {}" , GetLastError ());
403
+ spdlog::error (" BindIOCompletionPort() Function failure : {}" , GetLastError ());
405
404
CloseSocket (pPlayerSession);
406
405
continue ;
407
406
}
@@ -423,12 +422,12 @@ void IOCP_Server::AccepterThread()
423
422
424
423
char clientIP[32 ] = { 0 , };
425
424
inet_ntop (AF_INET, &(client_addr.sin_addr ), clientIP, 32 - 1 );
426
- spdlog::info (" [접속 ] Client IP : {} / SOCKET : {} / [unique_id:{}]" , clientIP, (int )pPlayerSession->get_sock (), pPlayerSession->get_unique_id ());
425
+ spdlog::info (" [Connect ] Client IP : {} / SOCKET : {} / [unique_id:{}]" , clientIP, (int )pPlayerSession->get_sock (), pPlayerSession->get_unique_id ());
427
426
428
427
// Recv Overlapped I/O작업을 요청해 놓는다.
429
428
bRet = BindRecv (pPlayerSession, 0 );
430
429
if (false == bRet) {
431
- spdlog::error (" BindRecv() 함수 실패 [unique_id:{}]" , pPlayerSession->get_unique_id ());
430
+ spdlog::error (" BindRecv() Function failure / [unique_id:{}]" , pPlayerSession->get_unique_id ());
432
431
ClosePlayer (pPlayerSession->get_unique_id ());
433
432
CloseSocket (pPlayerSession);
434
433
continue ;
@@ -443,7 +442,7 @@ bool IOCP_Server::BindIOCompletionPort(class PLAYER_Session * pPlayerSession)
443
442
auto hIOCP = CreateIoCompletionPort ((HANDLE)pPlayerSession->get_sock (), g_hiocp, (ULONG_PTR)(pPlayerSession), 0 );
444
443
445
444
if (NULL == hIOCP || g_hiocp != hIOCP) {
446
- spdlog::error (" CreateIoCompletionPort() 함수 실패 : {} / [unique_id:{}]" , GetLastError (), pPlayerSession->get_unique_id ());
445
+ spdlog::error (" CreateIoCompletionPort() Function failure : {} / [unique_id:{}]" , GetLastError (), pPlayerSession->get_unique_id ());
447
446
return false ;
448
447
}
449
448
@@ -460,7 +459,7 @@ bool IOCP_Server::BindRecv(class PLAYER_Session * pPlayerSession, int remainSize
460
459
pPlayerSession->get_buffer ().checkWrite (remainSize);
461
460
}
462
461
463
- // Overlapped I/O을 위해 각 정보를 셋팅해 준다.
462
+ // Overlapped I/O을 위해 각 정보를 셋팅해 준다.
464
463
wBuf.len = MAX_SOCKBUF;
465
464
wBuf.buf = pPlayerSession->get_buffer ().getWriteBuffer ();
466
465
pPlayerSession->get_Recv_over ().m_eOperation = IOOperation::RECV;
@@ -475,9 +474,9 @@ bool IOCP_Server::BindRecv(class PLAYER_Session * pPlayerSession, int remainSize
475
474
(LPWSAOVERLAPPED) & (pPlayerSession->get_Recv_over ()),
476
475
NULL );
477
476
478
- // socket_error이면 client socket이 끊어진걸로 처리한다.
477
+ // socket_error이면 client socket이 끊어진걸로 처리한다.
479
478
if (nRet == SOCKET_ERROR && (WSAGetLastError () != ERROR_IO_PENDING)) {
480
- spdlog::error (" WSARecv() 함수 실패 : {} / [unique_id:{}]" , WSAGetLastError (), pPlayerSession->get_unique_id ());
479
+ spdlog::error (" WSARecv() Function failure : {} / [unique_id:{}]" , WSAGetLastError (), pPlayerSession->get_unique_id ());
481
480
ClosePlayer (pPlayerSession->get_unique_id ());
482
481
CloseSocket (pPlayerSession);
483
482
return false ;
0 commit comments