Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
FMVip_Today
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhenfei.zhang
FMVip_Today
Commits
59e0488a
Commit
59e0488a
authored
Nov 15, 2016
by
Carwyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes: 监听 Socket 状态时,主动关闭会导致卡死问题;
parent
3eb917df
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
16 deletions
+41
-16
FMVip/fmvipdispatcher.cpp
+37
-12
FMVip/fmvipdispatcher.h
+4
-4
No files found.
FMVip/fmvipdispatcher.cpp
View file @
59e0488a
...
@@ -10,6 +10,8 @@
...
@@ -10,6 +10,8 @@
#include <QApplication>
#include <QApplication>
#include <QMessageBox>
#include <QMessageBox>
#include <QMenu>
#include <QMenu>
#include <QTimer>
#include <winsock2.h>
FMVipDispatcher
::
FMVipDispatcher
(
QObject
*
parent
)
FMVipDispatcher
::
FMVipDispatcher
(
QObject
*
parent
)
:
QObject
(
parent
),
:
QObject
(
parent
),
...
@@ -17,14 +19,17 @@ FMVipDispatcher::FMVipDispatcher(QObject *parent)
...
@@ -17,14 +19,17 @@ FMVipDispatcher::FMVipDispatcher(QObject *parent)
_vindow
(
0
),
_vindow
(
0
),
isLastOne
(
true
),
isLastOne
(
true
),
_windowReturn
(
0
),
_windowReturn
(
0
),
_posSocket
(
new
QTcpSocket
(
this
)),
_posSocket
Timer
(
new
QTimer
(
this
)),
_sysIcon
(
new
QSystemTrayIcon
)
_sysIcon
(
new
QSystemTrayIcon
)
{
{
connect
(
this
,
SIGNAL
(
requested
(
QJsonObject
)),
SLOT
(
onRequest
(
QJsonObject
)));
connect
(
this
,
SIGNAL
(
requested
(
QJsonObject
)),
SLOT
(
onRequest
(
QJsonObject
)));
connect
(
this
,
SIGNAL
(
responded
(
QByteArray
)),
SLOT
(
onResponse
(
QByteArray
)));
connect
(
this
,
SIGNAL
(
responded
(
QByteArray
)),
SLOT
(
onResponse
(
QByteArray
)));
connect
(
FMVipForward
::
instance
(),
SIGNAL
(
serverResponsed
(
QJsonObject
)),
SLOT
(
onServerResponsed
(
QJsonObject
)));
connect
(
FMVipForward
::
instance
(),
SIGNAL
(
serverResponsed
(
QJsonObject
)),
SLOT
(
onServerResponsed
(
QJsonObject
)));
connect
(
this
,
SIGNAL
(
initSocket
()),
this
,
SLOT
(
onInitSocket
()));
_posSocketTimer
->
setInterval
(
5000
);
connect
(
_posSocketTimer
,
SIGNAL
(
timeout
()),
SLOT
(
onCheckSocket
()));
connect
(
this
,
SIGNAL
(
stopSocketTimer
()),
_posSocketTimer
,
SLOT
(
stop
()));
connect
(
this
,
SIGNAL
(
startSocketTimer
()),
_posSocketTimer
,
SLOT
(
start
()));
QIcon
icon
=
QIcon
(
":/img_logo.png"
);
QIcon
icon
=
QIcon
(
":/img_logo.png"
);
_sysIcon
->
setIcon
(
icon
);
_sysIcon
->
setIcon
(
icon
);
...
@@ -50,9 +55,9 @@ FMVipDispatcher::~FMVipDispatcher()
...
@@ -50,9 +55,9 @@ FMVipDispatcher::~FMVipDispatcher()
_sysIcon
=
NULL
;
_sysIcon
=
NULL
;
}
}
if
(
_posSocket
!=
nullptr
)
{
if
(
_posSocket
Timer
!=
nullptr
)
{
delete
_posSocket
;
delete
_posSocket
Timer
;
_posSocket
=
nullptr
;
_posSocket
Timer
=
nullptr
;
}
}
}
}
...
@@ -91,16 +96,13 @@ INT FMVipDispatcher::_ParseRequest(LPSTR data)
...
@@ -91,16 +96,13 @@ INT FMVipDispatcher::_ParseRequest(LPSTR data)
// 唤起客户端界面
// 唤起客户端界面
emit
requested
(
_posReqObj
);
emit
requested
(
_posReqObj
);
return
FM_API_SUCCESS
;
return
FM_API_SUCCESS
;
}
}
BOOL
FMVipDispatcher
::
_GetResponse
(
LPSTR
&
rsp
,
UINT
&
len
)
BOOL
FMVipDispatcher
::
_GetResponse
(
LPSTR
&
rsp
,
UINT
&
len
)
{
{
emit
startSocketTimer
();
mutex
.
lock
();
mutex
.
lock
();
emit
initSocket
();
if
(
_serverRspData
.
isEmpty
())
if
(
_serverRspData
.
isEmpty
())
{
{
// 服务器还未返回则一直阻塞
// 服务器还未返回则一直阻塞
...
@@ -112,6 +114,8 @@ BOOL FMVipDispatcher::_GetResponse(LPSTR &rsp, UINT &len)
...
@@ -112,6 +114,8 @@ BOOL FMVipDispatcher::_GetResponse(LPSTR &rsp, UINT &len)
qDebug
()
<<
"发给POS:"
<<
rsp
;
qDebug
()
<<
"发给POS:"
<<
rsp
;
emit
stopSocketTimer
();
return
1
;
return
1
;
}
}
...
@@ -334,10 +338,31 @@ BOOL FMVipDispatcher::isLogined()
...
@@ -334,10 +338,31 @@ BOOL FMVipDispatcher::isLogined()
return
account
!=
""
;
return
account
!=
""
;
}
}
void
FMVipDispatcher
::
on
Init
Socket
()
void
FMVipDispatcher
::
on
Check
Socket
()
{
{
_posSocket
->
setSocketDescriptor
(
_socket
);
if
(
_socket
<=
0
)
{
connect
(
_posSocket
,
SIGNAL
(
error
(
QAbstractSocket
::
SocketError
)),
this
,
SLOT
(
onDisconnected
()),
Qt
::
UniqueConnection
);
emit
stopSocketTimer
();
return
;
}
WORD
wVersionRequested
;
WSADATA
wsaData
;
wVersionRequested
=
MAKEWORD
(
2
,
2
);
WSAStartup
(
wVersionRequested
,
&
wsaData
);
HANDLE
closeEvent
=
WSACreateEvent
();
WSAEventSelect
(
_socket
,
closeEvent
,
FD_CLOSE
);
DWORD
dwRet
=
WaitForSingleObject
(
closeEvent
,
0
);
if
(
dwRet
==
WSA_WAIT_EVENT_0
)
{
onDisconnected
();
}
WSACloseEvent
(
closeEvent
);
WSACleanup
();
}
}
void
FMVipDispatcher
::
onDisconnected
()
void
FMVipDispatcher
::
onDisconnected
()
...
...
FMVip/fmvipdispatcher.h
View file @
59e0488a
...
@@ -41,8 +41,8 @@ protected:
...
@@ -41,8 +41,8 @@ protected:
signals
:
signals
:
void
requested
(
const
QJsonObject
&
);
void
requested
(
const
QJsonObject
&
);
void
responded
(
const
QByteArray
&
);
void
responded
(
const
QByteArray
&
);
void
startSocketTimer
();
void
initSocket
();
void
stopSocketTimer
();
private
slots
:
private
slots
:
void
onRequest
(
const
QJsonObject
&
jsonObj
);
void
onRequest
(
const
QJsonObject
&
jsonObj
);
...
@@ -53,7 +53,7 @@ private slots:
...
@@ -53,7 +53,7 @@ private slots:
void
onDoPost
();
void
onDoPost
();
void
on
Init
Socket
();
void
on
Check
Socket
();
void
onDisconnected
();
void
onDisconnected
();
void
onActiveSysTrayIcon
(
QSystemTrayIcon
::
ActivationReason
);
void
onActiveSysTrayIcon
(
QSystemTrayIcon
::
ActivationReason
);
...
@@ -68,7 +68,7 @@ private:
...
@@ -68,7 +68,7 @@ private:
QSystemTrayIcon
*
_sysIcon
;
QSystemTrayIcon
*
_sysIcon
;
QT
cpSocket
*
_posSocket
;
QT
imer
*
_posSocketTimer
;
QMutex
mutex
;
QMutex
mutex
;
QWaitCondition
serverIsBusy
;
QWaitCondition
serverIsBusy
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment