Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
colorEagleStdio
dataproxy
提交
2e3d1201
dataproxy
项目概览
colorEagleStdio
/
dataproxy
通知
9
Star
6
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
dataproxy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2e3d1201
编写于
4月 14, 2017
作者:
丁劲犇
😸
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sloved a fail-diconnect problem when a fast sender sending large data to a slow-reciever
上级
eccdd37f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
58 addition
and
20 deletion
+58
-20
proxyobject.cpp
proxyobject.cpp
+54
-18
proxyobject.h
proxyobject.h
+4
-2
未找到文件。
proxyobject.cpp
浏览文件 @
2e3d1201
...
...
@@ -87,12 +87,21 @@ void ProxyObject::slot_SocketError(QObject * senderSock ,QAbstractSocket::Socket
qWarning
()
<<
msg
;
if
(
m_hash_Inner2Outer
.
contains
(
senderSock
))
{
engine
->
KickClients
(
m_hash_Inner2Outer
[
senderSock
]);
//engine->KickClients(m_hash_Inner2Outer[senderSock]);
//!In some case, the sender has a fast connection, while the reciever is slow.
//!Because of the deep cache method in engine, the sender will cut off tcp connection when
//!It "feels" that sending operation is finished. However, at the time sender closed connection,
//! the other side is still busy recieveing data. In this case, recieving progress will be
//! terminate abnormally.
//! The solution blew can remember the reciever's sock, with a time stamp
//! In ontimer() function, we will check timestamp and disconnect reciever.
pending_kick
[
m_hash_Inner2Outer
[
senderSock
]]
=
QDateTime
::
currentDateTime
();
m_hash_Inner2Outer
.
remove
(
senderSock
);
}
else
if
(
m_hash_Outer2Inner
.
contains
(
senderSock
))
{
engine
->
KickClients
(
m_hash_Outer2Inner
[
senderSock
]);
//engine->KickClients(m_hash_Outer2Inner[senderSock]);
pending_kick
[
m_hash_Inner2Outer
[
senderSock
]]
=
QDateTime
::
currentDateTime
();
m_hash_Outer2Inner
.
remove
(
senderSock
);
}
}
...
...
@@ -115,23 +124,23 @@ void ProxyObject::slot_NewClientConnected(QObject * clientHandle,quint64 extraDa
{
m_hash_Inner2Outer
[
innerClient
]
=
clientHandle
;
m_hash_Outer2Inner
[
clientHandle
]
=
innerClient
;
if
(
peng
ing_data
.
contains
(
innerClient
))
if
(
pend
ing_data
.
contains
(
innerClient
))
{
while
(
peng
ing_data
[
innerClient
].
empty
()
==
false
)
while
(
pend
ing_data
[
innerClient
].
empty
()
==
false
)
{
engine
->
SendDataToClient
(
clientHandle
,
peng
ing_data
[
innerClient
].
first
());
peng
ing_data
[
innerClient
].
pop_front
();
engine
->
SendDataToClient
(
clientHandle
,
pend
ing_data
[
innerClient
].
first
());
pend
ing_data
[
innerClient
].
pop_front
();
}
peng
ing_data
.
remove
(
innerClient
);
pend
ing_data
.
remove
(
innerClient
);
}
if
(
peng
ing_data
.
contains
(
clientHandle
))
if
(
pend
ing_data
.
contains
(
clientHandle
))
{
while
(
peng
ing_data
[
clientHandle
].
empty
()
==
false
)
while
(
pend
ing_data
[
clientHandle
].
empty
()
==
false
)
{
engine
->
SendDataToClient
(
innerClient
,
peng
ing_data
[
clientHandle
].
first
());
peng
ing_data
[
clientHandle
].
pop_front
();
engine
->
SendDataToClient
(
innerClient
,
pend
ing_data
[
clientHandle
].
first
());
pend
ing_data
[
clientHandle
].
pop_front
();
}
peng
ing_data
.
remove
(
clientHandle
);
pend
ing_data
.
remove
(
clientHandle
);
}
}
else
...
...
@@ -168,15 +177,24 @@ void ProxyObject::slot_NewClientConnected(QObject * clientHandle,quint64 extraDa
//this event indicates a client disconnected.
void
ProxyObject
::
slot_ClientDisconnected
(
QObject
*
clientHandle
,
quint64
)
{
peng
ing_data
.
remove
(
clientHandle
);
pend
ing_data
.
remove
(
clientHandle
);
if
(
m_hash_Inner2Outer
.
contains
(
clientHandle
))
{
engine
->
KickClients
(
m_hash_Inner2Outer
[
clientHandle
]);
//engine->KickClients(m_hash_Inner2Outer[clientHandle]);
//!In some case, the sender has a fast connection, while the reciever is slow.
//!Because of the deep cache method in engine, the sender will cut off tcp connection when
//!It "feels" that sending operation is finished. However, at the time sender closed connection,
//! the other side is still busy recieveing data. In this case, recieving progress will be
//! terminate abnormally.
//! The solution blew can remember the reciever's sock, with a time stamp
//! In ontimer() function, we will check timestamp and disconnect reciever.
pending_kick
[
m_hash_Inner2Outer
[
clientHandle
]]
=
QDateTime
::
currentDateTime
();
m_hash_Inner2Outer
.
remove
(
clientHandle
);
}
else
if
(
m_hash_Outer2Inner
.
contains
(
clientHandle
))
{
engine
->
KickClients
(
m_hash_Outer2Inner
[
clientHandle
]);
//engine->KickClients(m_hash_Outer2Inner[clientHandle]);
pending_kick
[
m_hash_Outer2Inner
[
clientHandle
]]
=
QDateTime
::
currentDateTime
();
m_hash_Outer2Inner
.
remove
(
clientHandle
);
}
}
...
...
@@ -188,8 +206,11 @@ void ProxyObject::slot_Data_recieved(QObject * clientHandle,QByteArray datablo
engine
->
SendDataToClient
(
m_hash_Inner2Outer
[
clientHandle
],
datablock
);
else
if
(
m_hash_Outer2Inner
.
contains
(
clientHandle
))
engine
->
SendDataToClient
(
m_hash_Outer2Inner
[
clientHandle
],
datablock
);
else
penging_data
[
clientHandle
].
push_back
(
datablock
);
else
if
(
pending_kick
.
contains
(
clientHandle
)
==
false
)
pending_data
[
clientHandle
].
push_back
(
datablock
);
//Keep timestamp fresh
if
(
pending_kick
.
contains
(
clientHandle
))
pending_kick
[
clientHandle
]
=
QDateTime
::
currentDateTime
();
}
void
ProxyObject
::
timerEvent
(
QTimerEvent
*
event
)
...
...
@@ -240,6 +261,21 @@ void ProxyObject::timerEvent(QTimerEvent *event)
}
m_nTimerRefresh
=
startTimer
(
1000
);
}
//kick out clients when the other side is disconnected and
//no data left to be recieved.
if
(
counter
%
30
==
0
)
{
QList
<
QObject
*>
timeoutobjs
;
foreach
(
QObject
*
obj
,
pending_kick
.
keys
())
if
(
pending_kick
[
obj
].
secsTo
(
QDateTime
::
currentDateTime
())
>
30
)
timeoutobjs
.
push_back
(
obj
);
foreach
(
QObject
*
obj
,
pending_kick
.
keys
())
{
pending_kick
.
remove
(
obj
);
engine
->
KickClients
(
obj
);
}
}
}
}
proxyobject.h
浏览文件 @
2e3d1201
#ifndef PROXYOBJECT_H
#define PROXYOBJECT_H
#include <QDateTime>
#include <QObject>
#include <QList>
#include <QHash>
...
...
@@ -26,7 +26,9 @@ private:
ZPNetwork
::
zp_net_Engine
*
engine
;
QHash
<
QObject
*
,
QObject
*>
m_hash_Inner2Outer
;
QHash
<
QObject
*
,
QObject
*>
m_hash_Outer2Inner
;
QHash
<
QObject
*
,
QList
<
QByteArray
>
>
penging_data
;
QHash
<
QObject
*
,
QList
<
QByteArray
>
>
pending_data
;
//Hash table for single-side disconnect protection
QHash
<
QObject
*
,
QDateTime
>
pending_kick
;
public
slots
:
void
slot_Message
(
QObject
*
pSource
,
QString
);
//The socket error message
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录