Commit 886fbb67 by 刘帅

1. 捕获退出消息,正确停止线程,进行清理工作

2. 修改socket属性设置SO_RESUEADDR
parent d0ebe816
...@@ -3,4 +3,4 @@ partner_id=1371 ...@@ -3,4 +3,4 @@ partner_id=1371
store_id=fm99999 store_id=fm99999
pos_id=1 pos_id=1
operator_id=001 operator_id=001
business_date=20171016 business_date=20171205
...@@ -4,14 +4,36 @@ ...@@ -4,14 +4,36 @@
//不显示控制台 //不显示控制台
//#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) //#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
BOOL WINAPI HandlerRoutine(_In_ DWORD dwCtrlType);
QFmClient* pFm = nullptr;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
SetConsoleCtrlHandler(HandlerRoutine, TRUE);
InitLogger(); InitLogger();
QLOG_INFO()<<"start client..."; QLOG_INFO()<<"start client...";
QFmClient client; QFmClient client;
pFm = &client;
client.start(); client.start();
return a.exec(); return a.exec();
} }
BOOL WINAPI HandlerRoutine(_In_ DWORD dwCtrlType)
{
switch (dwCtrlType)
{
// Handle the CTRL + C signal.
case CTRL_C_EVENT:
case CTRL_CLOSE_EVENT:
OutputDebugStringA("quit client...\n");
pFm->CloseSock();
pFm->wait();
QLOG_INFO()<<"quit client...\n\n\n\n";
break;
// CTRL-CLOSE: confirm that the user wants to exit.
default:
break;
}
return FALSE;
}
...@@ -40,6 +40,11 @@ QFmClient::QFmClient(QObject *parent) : QThread(parent),store_info("1371","fm999 ...@@ -40,6 +40,11 @@ QFmClient::QFmClient(QObject *parent) : QThread(parent),store_info("1371","fm999
_endflag = false; _endflag = false;
} }
QFmClient::~QFmClient()
{
OutputDebugStringA("~QFmClient()");
}
bool QFmClient::Init(QString proxy_IP, unsigned short proxy_port, unsigned short listen_prot, unsigned short long_timeout, unsigned short short_timeout) bool QFmClient::Init(QString proxy_IP, unsigned short proxy_port, unsigned short listen_prot, unsigned short long_timeout, unsigned short short_timeout)
{ {
...@@ -116,6 +121,14 @@ bool QFmClient::InitStoreInfo() ...@@ -116,6 +121,14 @@ bool QFmClient::InitStoreInfo()
return true; return true;
} }
void QFmClient::CloseSock()
{
_endflag = true;
closesocket(_listenSock);
requestInterruption();
OutputDebugStringA("close listen socket");
}
int QFmClient::RecvSockData(int sock, char *buffer, int length) int QFmClient::RecvSockData(int sock, char *buffer, int length)
{ {
#ifdef WIN32 #ifdef WIN32
...@@ -976,15 +989,6 @@ void QFmClient::run() ...@@ -976,15 +989,6 @@ void QFmClient::run()
} }
} }
CloseSocket(&_zhProxySock); CloseSocket(&_zhProxySock);
// if (0 != rlt)
// {
// if (nResult == FREEMUD_PAY)
// {
// //is write off data, need to check roll back
// BackupPosReq(temp_recv);
// break;
// }
// }
CloseSocket(&_acceptedSock); CloseSocket(&_acceptedSock);
}while(1); }while(1);
if(bBackup) if(bBackup)
...@@ -993,10 +997,12 @@ void QFmClient::run() ...@@ -993,10 +997,12 @@ void QFmClient::run()
QLOG_INFO()<<"backup:\n"<<_sendbuf; QLOG_INFO()<<"backup:\n"<<_sendbuf;
bBackup = false; bBackup = false;
} }
if(_endflag)
WaitAndSleep(3000); WaitAndSleep(3000);
}while(!_endflag); }while(!isInterruptionRequested());
qDebug() << "Exit ZH Client!\r\n"; qDebug() << "Exit ZH Client!\r\n";
QLOG_INFO()<< "Exit ZH Client!\r\n";
#ifdef WIN32 #ifdef WIN32
WSACleanup(); WSACleanup();
......
...@@ -23,9 +23,11 @@ class QFmClient : public QThread ...@@ -23,9 +23,11 @@ class QFmClient : public QThread
Q_OBJECT Q_OBJECT
public: public:
QFmClient(QObject *parent = NULL); QFmClient(QObject *parent = NULL);
~QFmClient();
void run(); void run();
bool Init(QString proxy_IP, unsigned short proxy_port, unsigned short listen_prot, unsigned short long_timeout, unsigned short short_timeout); bool Init(QString proxy_IP, unsigned short proxy_port, unsigned short listen_prot, unsigned short long_timeout, unsigned short short_timeout);
bool InitStoreInfo(); bool InitStoreInfo();
void CloseSock();
signals: signals:
void Error(QString error); void Error(QString error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment