|
@@ -184,6 +184,7 @@ ULONGLONG time_clear_call_time;
|
|
|
ULONGLONG time_send_call;
|
|
|
ULONGLONG time_send_help;
|
|
|
ULONGLONG time_ws_connect;
|
|
|
+volatile LONG g_QueueItemCount = 0;
|
|
|
bool g_exit=false;
|
|
|
long giSqlCount=0;
|
|
|
long giSqlThreadCount=0;
|
|
@@ -194,40 +195,36 @@ HANDLE hSemaHandle=NULL;
|
|
|
|
|
|
DWORD WINAPI _exec_sql(LPVOID lparam)
|
|
|
{
|
|
|
+ ::InterlockedIncrement(&g_QueueItemCount);
|
|
|
char *sql = (char*)lparam ;
|
|
|
CMysqlConn* pConn = NULL;
|
|
|
CDBConnGuard pDbGuard(pConn);
|
|
|
if(pConn == NULL){
|
|
|
- delete[] sql;
|
|
|
- sql = NULL;
|
|
|
+ if(sql){
|
|
|
+ delete[] sql;
|
|
|
+ sql = NULL;
|
|
|
+ }
|
|
|
+ ::InterlockedDecrement(&g_QueueItemCount);
|
|
|
return 1;
|
|
|
}
|
|
|
- //MYSQL_RES* pRes;
|
|
|
int err = 0;
|
|
|
- //pRes = pConn->Execute(sql, err);
|
|
|
- //mysql_free_result(pRes);
|
|
|
-
|
|
|
pConn->MultiExecute(sql,err);
|
|
|
|
|
|
if(err > 0){
|
|
|
TRACE(_T("sql error \n"));
|
|
|
}
|
|
|
-
|
|
|
- /*ofstream out("SQL_S.log",ios::out | ios::app);
|
|
|
- if (out.is_open())
|
|
|
- {
|
|
|
- out<<sql;
|
|
|
- out<<err;
|
|
|
- out.close();
|
|
|
- }*/
|
|
|
- delete[] sql;
|
|
|
- sql = NULL;
|
|
|
+ if(sql){
|
|
|
+ delete[] sql;
|
|
|
+ sql = NULL;
|
|
|
+ }
|
|
|
Sleep(1);
|
|
|
+ ::InterlockedDecrement(&g_QueueItemCount);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
DWORD WINAPI _write_error_log(LPVOID lparam)
|
|
|
{
|
|
|
+ ::InterlockedIncrement(&g_QueueItemCount);
|
|
|
LogInfo* err = (LogInfo*)lparam;
|
|
|
CYAServerDlg* dlg = reinterpret_cast<CYAServerDlg*>(err->handle);
|
|
|
dlg->writeErrorLogEx(err->path, err->strLog, err->useTime);
|
|
@@ -243,12 +240,13 @@ DWORD WINAPI _write_error_log(LPVOID lparam)
|
|
|
err = NULL;
|
|
|
}
|
|
|
Sleep(1);
|
|
|
-
|
|
|
+ ::InterlockedDecrement(&g_QueueItemCount);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
DWORD WINAPI _parse_package_data(LPVOID lparam)
|
|
|
{
|
|
|
+ ::InterlockedIncrement(&g_QueueItemCount);
|
|
|
ParseData* data = (ParseData*)lparam;
|
|
|
CYAServerDlg* dlg = reinterpret_cast<CYAServerDlg*>(data->handle);
|
|
|
dlg->parse_package_data(data->buf, data->len, data->dwConnID);
|
|
@@ -256,11 +254,13 @@ DWORD WINAPI _parse_package_data(LPVOID lparam)
|
|
|
|
|
|
free(data);
|
|
|
Sleep(1);
|
|
|
+ ::InterlockedDecrement(&g_QueueItemCount);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
DWORD WINAPI _parse_data_server(LPVOID lparam)
|
|
|
{
|
|
|
+ ::InterlockedIncrement(&g_QueueItemCount);
|
|
|
//TRACE(_T("in thread \n"));
|
|
|
ParseData* data = (ParseData*)lparam;
|
|
|
CYAServerDlg* dlg = reinterpret_cast<CYAServerDlg*>(data->handle);
|
|
@@ -271,6 +271,7 @@ DWORD WINAPI _parse_data_server(LPVOID lparam)
|
|
|
//TRACE(_T("use data over %d = \n"),data->handle->m_nMallocTimes);
|
|
|
free(data);
|
|
|
Sleep(1);
|
|
|
+ ::InterlockedDecrement(&g_QueueItemCount);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -643,10 +644,7 @@ void CYAServerDlg::stop_and_exit()
|
|
|
if(is_websocket_login){
|
|
|
ws_logout();
|
|
|
}
|
|
|
-
|
|
|
- ::SetMainWnd(NULL);
|
|
|
- ::SetInfoList(NULL);
|
|
|
-
|
|
|
+
|
|
|
g_exit = true;
|
|
|
if(m_thread_monitor){
|
|
|
WaitForSingleObject(m_thread_monitor->m_hThread, 0);
|
|
@@ -657,11 +655,21 @@ void CYAServerDlg::stop_and_exit()
|
|
|
}
|
|
|
m_thread_timer = NULL;
|
|
|
|
|
|
- clear_all_list();
|
|
|
-
|
|
|
if(m_qsmSQL){
|
|
|
m_qsmSQL->Execute();
|
|
|
}
|
|
|
+
|
|
|
+ CString strlog;
|
|
|
+ while(g_QueueItemCount >0){
|
|
|
+ strlog.Format(_T("%s: %d"), _T(LOG_LEFT_THREAD), g_QueueItemCount);
|
|
|
+ show_log(strlog);
|
|
|
+ WaitForMS(3000);
|
|
|
+ }
|
|
|
+
|
|
|
+ ::SetMainWnd(NULL);
|
|
|
+ ::SetInfoList(NULL);
|
|
|
+
|
|
|
+ clear_all_list();
|
|
|
GetConnPool().CloseAllConn();
|
|
|
|
|
|
DeleteCriticalSection(&m_csWriteLog);
|
|
@@ -2402,6 +2410,9 @@ void CYAServerDlg::parse_data_adhoc( BYTE* DataBuffer, int& nCurPos, int reader_
|
|
|
|
|
|
void CYAServerDlg::add_socket_to_list(DWORD dwConnID, DWORD reader_id )
|
|
|
{
|
|
|
+ if(m_enState != ST_STARTED){
|
|
|
+ return;
|
|
|
+ }
|
|
|
TCHAR szAddress[40];
|
|
|
int iAddressLen = sizeof(szAddress) / sizeof(TCHAR);
|
|
|
USHORT usPort;
|
|
@@ -6748,18 +6759,18 @@ void CYAServerDlg::release_map_memory()
|
|
|
|
|
|
void CYAServerDlg::release_card_memory()
|
|
|
{
|
|
|
- if(mp_card_list_all.size()>0){
|
|
|
- CardMap::iterator it = mp_card_list_all.begin();
|
|
|
- for(;it!=mp_card_list_all.end();){
|
|
|
- Card* tmp = (Card*)(it->second);
|
|
|
- mp_card_list_all.erase(it);
|
|
|
- if(tmp){
|
|
|
- delete tmp;
|
|
|
- tmp = NULL;
|
|
|
- }
|
|
|
- it = mp_card_list_all.begin();
|
|
|
- }
|
|
|
- }
|
|
|
+ //if(mp_card_list_all.size()>0){
|
|
|
+ // CardMap::iterator it = mp_card_list_all.begin();
|
|
|
+ // for(;it!=mp_card_list_all.end();){
|
|
|
+ // Card* tmp = (Card*)(it->second);
|
|
|
+ // mp_card_list_all.erase(it);
|
|
|
+ // if(tmp){
|
|
|
+ // delete tmp;
|
|
|
+ // tmp = NULL;
|
|
|
+ // }
|
|
|
+ // it = mp_card_list_all.begin();
|
|
|
+ // }
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
void CYAServerDlg::release_reader_memory()
|
|
@@ -6952,15 +6963,17 @@ void CYAServerDlg::parse_data_server( const BYTE * pData, int nLen, DWORD dwConn
|
|
|
it->second->wReadLen += nLen - read_length;
|
|
|
}else{
|
|
|
_SOCKET_BUFFER* _sockbuf = (_SOCKET_BUFFER*)malloc(sizeof(_SOCKET_BUFFER));
|
|
|
- _sockbuf->wReadLen = 0;
|
|
|
- _sockbuf->dwConnID = dwConnId;
|
|
|
- _sockbuf->wLen = pkg_len;
|
|
|
- memset(_sockbuf->pData, 0, LENGTH_MSG_1M);
|
|
|
- //TRACE("5\n");
|
|
|
- //TRACE(_T("13_2 new socket_buffer\n"));
|
|
|
- memcpy(_sockbuf->pData, &Buf[read_length], nLen - read_length);
|
|
|
- _sockbuf->wReadLen += nLen - read_length;
|
|
|
- mp_socket_buffer_list.insert(make_pair(dwConnId, _sockbuf));
|
|
|
+ if(_sockbuf){
|
|
|
+ _sockbuf->wReadLen = 0;
|
|
|
+ _sockbuf->dwConnID = dwConnId;
|
|
|
+ _sockbuf->wLen = pkg_len;
|
|
|
+ memset(_sockbuf->pData, 0, LENGTH_MSG_1M);
|
|
|
+ //TRACE("5\n");
|
|
|
+ //TRACE(_T("13_2 new socket_buffer\n"));
|
|
|
+ memcpy(_sockbuf->pData, &Buf[read_length], nLen - read_length);
|
|
|
+ _sockbuf->wReadLen += nLen - read_length;
|
|
|
+ mp_socket_buffer_list.insert(make_pair(dwConnId, _sockbuf));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
delete[] Buf;
|