Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmp_vip
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
fmp_vip
Commits
88afe087
Commit
88afe087
authored
Jul 04, 2017
by
guanghui.cui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
肚子里有料 异步socket
parent
f5e69428
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
4 deletions
+47
-4
fmp_vip_server.cpp
+46
-3
fmp_vip_server.h
+1
-1
No files found.
fmp_vip_server.cpp
View file @
88afe087
...
...
@@ -59,11 +59,54 @@ void FMPVipServer::onReadyRead()
QByteArray
rspData
;
dispatcher
->
doTask
(
recvData
,
rspData
);
rspData
;
Write
(
rspData
);
if
(
socket
->
isValid
()){
rspData
;
Write
(
rspData
);
}
else
{
//向23771发送数据
SendToMonitor
(
rspData
);
}
socket
->
waitForDisconnected
();
socket
->
deleteLater
();
socket
=
nullptr
;
}
void
FMPVipServer
::
SendToMonitor
(
const
QByteArray
&
data
)
{
QTcpSocket
client
;
int
jsonLength
=
data
.
length
();
char
*
m_pFmPackage
=
new
char
[
jsonLength
+
sizeof
(
FMSOCKEHEADER
)];
FMSOCKEHEADER
header
=
{
0
,
0
,
0
};
header
.
flag
=
0x4d46
;
header
.
len
=
jsonLength
;
header
.
ver
=
0x1
;
memcpy
(
m_pFmPackage
,
&
header
,
sizeof
(
FMSOCKEHEADER
));
memcpy
(
m_pFmPackage
+
sizeof
(
FMSOCKEHEADER
),
data
,
jsonLength
);
int
toSendLength
=
jsonLength
+
sizeof
(
FMSOCKEHEADER
);
int
curSendLength
=
0
;
client
.
connectToHost
(
"127.0.0.1"
,
23771
);
if
(
client
.
waitForConnected
()){
while
(
curSendLength
<
toSendLength
)
{
int
rlt
=
client
.
write
(
m_pFmPackage
+
curSendLength
,
toSendLength
-
curSendLength
);
client
.
waitForBytesWritten
();
if
(
rlt
==-
1
){
FMP_DEBUG
()
<<
"发送数据失败:"
<<
data
;
break
;
}
curSendLength
+=
rlt
;
}
}
else
{
FMP_DEBUG
()
<<
"socket 连接失败!"
;
}
client
.
close
();
}
fmp_vip_server.h
View file @
88afe087
...
...
@@ -28,7 +28,7 @@ private slots:
void
onNewConnection
();
void
onDisconnected
();
void
onReadyRead
();
void
SendToMonitor
(
const
QByteArray
&
data
);
private
:
explicit
FMPVipServer
();
...
...
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