|
@@ -263,7 +263,8 @@ bool CSATTCPServer::_InitializeIOCP()
|
|
|
}
|
|
|
|
|
|
// 根据本机中的处理器数量,建立对应的线程数
|
|
|
- m_nThreads = WORKER_THREADS_PER_PROCESSOR * _GetNoOfProcessors();
|
|
|
+ //m_nThreads = WORKER_THREADS_PER_PROCESSOR * _GetNoOfProcessors();
|
|
|
+ m_nThreads = _GetNoOfProcessors();
|
|
|
|
|
|
// 为工作者线程初始化句柄
|
|
|
m_phWorkerThreads = new HANDLE[m_nThreads];
|
|
@@ -500,27 +501,6 @@ bool CSATTCPServer::_DoAccpet( PER_SOCKET_CONTEXT* pSocketContext, PER_IO_CONTEX
|
|
|
|
|
|
_RecvProcess(pSocketContext, pIoContext);
|
|
|
this->_ShowMessage( _T("客户端 %s:%d 连入."), inet_ntoa(ClientAddr->sin_addr), ntohs(ClientAddr->sin_port) );
|
|
|
- //this->_ShowMessage( _T("客户额 %s:%d 信息:%s."),inet_ntoa(ClientAddr->sin_addr), ntohs(ClientAddr->sin_port),pIoContext->m_wsaBuf.buf );
|
|
|
- //if ( Global::g_bEnableLog )
|
|
|
- //{
|
|
|
- // // 解析Json字符串;
|
|
|
- // Global::TLog tlog;
|
|
|
- // cJSON *pJson = cJSON_Parse(Global::DeCode_URLUNICODE(pIoContext->m_wsaBuf.buf).c_str());
|
|
|
- // if ( pJson )
|
|
|
- // {
|
|
|
- // tlog.report_type = cJSON_GetObjectItem(pJson, _T("ReportType")) ? cJSON_GetObjectItem(pJson, _T("ReportType"))->valuestring : "";
|
|
|
- // tlog.report_data = cJSON_GetObjectItem(pJson, _T("prinMsg")) ? cJSON_GetObjectItem(pJson, _T("prinMsg"))->valuestring : "";
|
|
|
- // if ( _tcscmp(tlog.report_type.c_str(), _T("printLog")) == 0 )
|
|
|
- // {
|
|
|
- // Global::WritePythonLog(tlog.report_data.c_str());
|
|
|
- // Global::g_time = time(NULL);
|
|
|
- // Global::g_lastTime = COleDateTime::GetCurrentTime();
|
|
|
- // }
|
|
|
-
|
|
|
- // cJSON_Delete(pJson);
|
|
|
- // pJson = NULL;
|
|
|
- // }
|
|
|
- //}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
// 2. 这里需要注意,这里传入的这个是ListenSocket上的Context,这个Context我们还需要用于监听下一个连接
|
|
@@ -537,7 +517,6 @@ bool CSATTCPServer::_DoAccpet( PER_SOCKET_CONTEXT* pSocketContext, PER_IO_CONTEX
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
// 3. 继续,建立其下的IoContext,用于在这个Socket上投递第一个Recv数据请求
|
|
|
PER_IO_CONTEXT* pNewIoContext = pNewSocketContext->GetNewIoContext();
|
|
@@ -597,26 +576,6 @@ bool CSATTCPServer::_DoRecv( PER_SOCKET_CONTEXT* pSocketContext, PER_IO_CONTEXT*
|
|
|
//this->_ShowMessage( _T("收到 %s:%d 信息:%s"),inet_ntoa(ClientAddr->sin_addr), ntohs(ClientAddr->sin_port), pIoContext->m_wsaBuf.buf );
|
|
|
|
|
|
_RecvProcess(pSocketContext, pIoContext);
|
|
|
- //if ( Global::g_bEnableLog )
|
|
|
- //{
|
|
|
- // // 解析Json字符串;
|
|
|
- // Global::TLog tlog;
|
|
|
- // cJSON *pJson = cJSON_Parse(Global::DeCode_URLUNICODE(pIoContext->m_wsaBuf.buf).c_str());
|
|
|
- // if ( pJson )
|
|
|
- // {
|
|
|
- // tlog.report_type = cJSON_GetObjectItem(pJson, _T("ReportType")) ? cJSON_GetObjectItem(pJson, _T("ReportType"))->valuestring : "";
|
|
|
- // tlog.report_data = cJSON_GetObjectItem(pJson, _T("prinMsg")) ? cJSON_GetObjectItem(pJson, _T("prinMsg"))->valuestring : "";
|
|
|
- // if ( _tcscmp(tlog.report_type.c_str(), _T("printLog")) == 0 )
|
|
|
- // {
|
|
|
- // Global::WritePythonLog(tlog.report_data.c_str());
|
|
|
- // Global::g_time = time(NULL);
|
|
|
- // Global::g_lastTime = COleDateTime::GetCurrentTime();
|
|
|
- // }
|
|
|
- // cJSON_Delete(pJson);
|
|
|
- // pJson = NULL;
|
|
|
- // }
|
|
|
- //
|
|
|
- //}
|
|
|
|
|
|
// 然后开始投递下一个WSARecv请求
|
|
|
return _PostRecv( pIoContext );
|
|
@@ -641,15 +600,12 @@ bool CSATTCPServer::_AssociateWithIOCP( PER_SOCKET_CONTEXT *pContext )
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//====================================================================================
|
|
|
//
|
|
|
// ContextList 相关操作
|
|
|
//
|
|
|
//====================================================================================
|
|
|
|
|
|
-
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
// 将客户端的相关信息存储到数组中
|
|
|
void CSATTCPServer::_AddToContextList( PER_SOCKET_CONTEXT *pHandleData )
|
|
@@ -704,8 +660,6 @@ void CSATTCPServer::_ClearContextList()
|
|
|
//
|
|
|
//====================================================================================
|
|
|
|
|
|
-
|
|
|
-
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// 获得本机的IP地址
|
|
|
CString CSATTCPServer::GetLocalIP()
|
|
@@ -754,17 +708,7 @@ void CSATTCPServer::_ShowMessage(const CString szFormat,...) const
|
|
|
strMessage.FormatV(szFormat,arglist);
|
|
|
va_end(arglist);
|
|
|
|
|
|
-#if 0
|
|
|
- // 在主界面中显示
|
|
|
- CMainDlg* pMain = (CMainDlg*)m_pMain;
|
|
|
- if( m_pMain!=NULL )
|
|
|
- {
|
|
|
- pMain->AddInformation(strMessage);
|
|
|
- TRACE( strMessage+_T("\n") );
|
|
|
- }
|
|
|
-#else
|
|
|
// Global::WriteTextLog(strMessage);
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
#define PAK_LEN sizeof(SATProtocol::DataHeader)
|
|
@@ -914,6 +858,7 @@ void CSATTCPServer::_TaskProcess(PER_IO_CONTEXT* pIoContext, SATProtocol::Packag
|
|
|
#ifdef _DEBUG
|
|
|
OutputDebugString("\n########成功获取数据########\n\n");
|
|
|
#endif
|
|
|
+
|
|
|
SATProtocol::DataHeader *pHeader = &pak->header;
|
|
|
if ( !pHeader )
|
|
|
return;
|
|
@@ -940,9 +885,14 @@ void CSATTCPServer::_TaskProcess(PER_IO_CONTEXT* pIoContext, SATProtocol::Packag
|
|
|
_stprintf_s(szMessage, _T("登录……"));
|
|
|
memcpy(pSendPak->buf + sizeof(bool), szMessage, MAX_PATH);
|
|
|
#else
|
|
|
+ const SATParameters::STLoginResp *pstLoginResp = CSATExecutor::GetInstance()->GetLoginResp();
|
|
|
SATProtocol::LoginResp *pLoginResp = (SATProtocol::LoginResp*)(pbuff+sizeof(SATProtocol::DataHeader));
|
|
|
pLoginResp->bStatus = bRet;
|
|
|
- _stprintf_s(pLoginResp->szMessage, _T("登录描述……"));
|
|
|
+ memset(pLoginResp->szMessage, 0, MAX_PATH);
|
|
|
+ //_stprintf_s(pLoginResp->szMessage, _T("%s"), pstLoginResp->strMessage.c_str());
|
|
|
+ //_tcscpy_s(pLoginResp->szMessage, _T("登录描述……"));
|
|
|
+ // 如果使用上方两种方式赋值,会导致'\0'后面的字节不为0;
|
|
|
+ memcpy(pLoginResp->szMessage, pstLoginResp->strMessage.c_str(), pstLoginResp->strMessage.size());
|
|
|
#endif
|
|
|
|
|
|
// 发送,无须判断是否发送成功;
|