Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
colorEagleStdio
zoompipeline
提交
3a883c97
zoompipeline
项目概览
colorEagleStdio
/
zoompipeline
通知
181
Star
12
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
zoompipeline
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3a883c97
编写于
9月 16, 2014
作者:
丁劲犇
😸
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of git@github.com:goldenhawking/zpserver.git
上级
7fb9233d
dd42700f
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
38 addition
and
19 deletion
+38
-19
ZoomPipeline_FuncSvr/database/databaseresource.cpp
ZoomPipeline_FuncSvr/database/databaseresource.cpp
+22
-9
ZoomPipeline_FuncSvr/database/databaseresource.h
ZoomPipeline_FuncSvr/database/databaseresource.h
+6
-5
ZoomPipeline_FuncSvr/network/zp_net_threadpool.cpp
ZoomPipeline_FuncSvr/network/zp_net_threadpool.cpp
+2
-2
ZoomPipeline_FuncSvr/network/zp_nettransthread.cpp
ZoomPipeline_FuncSvr/network/zp_nettransthread.cpp
+4
-3
ZoomPipeline_FuncSvr/smartlink/st_clientnode_app_imp.cpp
ZoomPipeline_FuncSvr/smartlink/st_clientnode_app_imp.cpp
+1
-0
ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.cpp
ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.cpp
+3
-0
未找到文件。
ZoomPipeline_FuncSvr/database/databaseresource.cpp
浏览文件 @
3a883c97
...
...
@@ -4,6 +4,7 @@
#include <QSqlError>
#include <QSqlQuery>
#include <QDebug>
#include <QDateTime>
namespace
ZPDatabase
{
...
...
@@ -20,9 +21,9 @@ namespace ZPDatabase{
//Get The quiting thread
if
(
pThread
&&
m_ThreadOwnedMainDBs
.
contains
(
pThread
)
)
{
Q
Set
<
QString
>
mainNames
=
m_ThreadOwnedMainDBs
[
pThread
];
Q
Map
<
QString
,
QDateTime
>
mainNames
=
m_ThreadOwnedMainDBs
[
pThread
];
//Remove every thread-owned db names for this thread.
foreach
(
QString
mainName
,
mainNames
)
foreach
(
QString
mainName
,
mainNames
.
keys
()
)
{
QString
threadName
=
QString
(
"%1_%2"
).
arg
(
mainName
).
arg
((
quint64
)
pThread
);
QSqlDatabase
db
=
QSqlDatabase
::
database
(
threadName
);
...
...
@@ -48,7 +49,7 @@ namespace ZPDatabase{
* @param strDBName the database name
* @return QSqlDatabase return the database object
*/
QSqlDatabase
DatabaseResource
::
databse
(
QString
strDBName
)
QSqlDatabase
DatabaseResource
::
databse
(
QString
strDBName
,
bool
checkConn
)
{
QMutexLocker
locker
(
&
m_mutex_reg
);
if
(
false
==
QSqlDatabase
::
contains
(
strDBName
))
...
...
@@ -85,26 +86,33 @@ namespace ZPDatabase{
//emit evt_Message(this,msg);
}
m_ThreadsDB
[
strDBName
].
insert
(
threadName
);
m_ThreadOwnedMainDBs
[
pThread
]
.
insert
(
strDBName
);
m_ThreadOwnedMainDBs
[
pThread
]
[
strDBName
]
=
QDateTime
::
currentDateTime
(
);
}
//Confirm the thread-owned db is still open
QSqlDatabase
db
=
QSqlDatabase
::
database
(
threadName
);
tagConnectionPara
&
para
=
m_dbNames
[
strDBName
];
bool
bNeedReconnect
=
false
;
if
(
db
.
isOpen
()
==
true
)
{
if
(
para
.
testSQL
.
length
())
QDateTime
dtmLatsAct
=
m_ThreadOwnedMainDBs
[
pThread
][
strDBName
];
if
(
dtmLatsAct
.
addSecs
(
5
)
<
QDateTime
::
currentDateTime
())
checkConn
=
true
;
tagConnectionPara
&
para
=
m_dbNames
[
strDBName
];
if
(
checkConn
==
true
&&
para
.
testSQL
.
length
())
{
QSqlQuery
query
(
db
);
query
.
exec
(
para
.
testSQL
);
if
(
query
.
lastError
().
type
()
!=
QSqlError
::
NoError
)
{
QString
msg
=
"Database:"
+
tr
(
" Connection "
)
+
threadName
+
tr
(
"
confirm failed
. MSG="
);
QString
msg
=
"Database:"
+
tr
(
" Connection "
)
+
threadName
+
tr
(
"
Need re-connect
. MSG="
);
msg
+=
query
.
lastError
().
text
();
qWarning
()
<<
msg
;
emit
evt_Message
(
this
,
msg
);
bNeedReconnect
=
true
;
}
else
m_ThreadOwnedMainDBs
[
pThread
][
strDBName
]
=
QDateTime
::
currentDateTime
();
}
if
(
bNeedReconnect
==
true
)
{
...
...
@@ -115,7 +123,12 @@ namespace ZPDatabase{
}
}
else
{
QSqlDatabase
::
removeDatabase
(
threadName
);
m_ThreadsDB
[
strDBName
].
remove
(
threadName
);
m_ThreadOwnedMainDBs
[
pThread
].
remove
(
strDBName
);
bNeedReconnect
=
true
;
}
if
(
bNeedReconnect
==
true
)
{
db
=
QSqlDatabase
::
cloneDatabase
(
QSqlDatabase
::
database
(
strDBName
),
threadName
);
...
...
@@ -125,7 +138,7 @@ namespace ZPDatabase{
emit
evt_Message
(
this
,
msg
);
qDebug
()
<<
msg
;
m_ThreadsDB
[
strDBName
].
insert
(
threadName
);
m_ThreadOwnedMainDBs
[
pThread
]
.
insert
(
strDBName
);
m_ThreadOwnedMainDBs
[
pThread
]
[
strDBName
]
=
QDateTime
::
currentDateTime
(
);
}
else
{
...
...
@@ -198,7 +211,7 @@ namespace ZPDatabase{
//Remove thread map.
foreach
(
QThread
*
ptr
,
m_ThreadOwnedMainDBs
.
keys
())
{
Q
Set
<
QString
>
&
threadOwnedMainDB
=
m_ThreadOwnedMainDBs
[
ptr
];
Q
Map
<
QString
,
QDateTime
>
&
threadOwnedMainDB
=
m_ThreadOwnedMainDBs
[
ptr
];
threadOwnedMainDB
.
remove
(
mainName
);
}
}
...
...
ZoomPipeline_FuncSvr/database/databaseresource.h
浏览文件 @
3a883c97
...
...
@@ -8,6 +8,7 @@
#include <QMutex>
#include <QThread>
#include <QSet>
#include <QDateTime>
namespace
ZPDatabase
{
/**
* @brief this class provide an database reource pool.In different thread, workers can get existing db connections
...
...
@@ -39,7 +40,7 @@ namespace ZPDatabase{
//!Get an database connection belong to current thread.
//!if database does not exist, it will be added using dbtype
QSqlDatabase
databse
(
QString
strDBName
);
QSqlDatabase
databse
(
QString
strDBName
,
bool
checkConn
=
false
);
//!add connection connName, return true if ok.
bool
addConnection
(
...
...
@@ -66,9 +67,9 @@ namespace ZPDatabase{
protected:
bool
bTerm
;
QMutex
m_mutex_reg
;
QMap
<
QString
,
tagConnectionPara
>
m_dbNames
;
QMap
<
QString
,
QSet
<
QString
>
>
m_ThreadsDB
;
QMap
<
QThread
*
,
Q
Set
<
QString
>
>
m_ThreadOwnedMainDBs
;
QMap
<
QString
,
tagConnectionPara
>
m_dbNames
;
//Each Main connection Name, and their connection para
QMap
<
QString
,
QSet
<
QString
>
>
m_ThreadsDB
;
//Each Main connection Name, and theri thread-owned names
QMap
<
QThread
*
,
Q
Map
<
QString
,
QDateTime
>
>
m_ThreadOwnedMainDBs
;
//Each Thread owns Main connection Names.
void
RemoveTreadsConnections
(
QString
mainName
);
signals:
void
evt_Message
(
QObject
*
,
QString
);
...
...
ZoomPipeline_FuncSvr/network/zp_net_threadpool.cpp
浏览文件 @
3a883c97
...
...
@@ -160,7 +160,7 @@ namespace ZPNetwork{
//emit evt_Message(this,"Info>" + QString(tr("Incomming client arriverd.")));
qDebug
()
<<
tr
(
"Incomming client arriverd."
);
//m_mutex_trans.lock();
int
nsz
=
m_vec_NetTransThreads
.
size
();
int
nMinPay
=
0x7fffffff
;
int
nMinIdx
=
-
1
;
...
...
@@ -192,7 +192,7 @@ namespace ZPNetwork{
emit
evt_Message
(
this
,
"Warning>"
+
QString
(
tr
(
"Need Trans Thread Object for clients."
)));
qCritical
()
<<
tr
(
"Need Trans Thread Object for clients."
);
}
//m_mutex_trans.unlock();
}
/**
* @brief This is a slot function. when a listening thread is terminated,
...
...
ZoomPipeline_FuncSvr/network/zp_nettransthread.cpp
浏览文件 @
3a883c97
...
...
@@ -245,7 +245,7 @@ namespace ZPNetwork{
{
QTcpSocket
*
pSock
=
qobject_cast
<
QTcpSocket
*>
(
sender
());
emit
evt_NewClientConnected
(
pSock
);
//
emit evt_Message(pSock,"Info>" + QString(tr("Client connected.")));
emit
evt_Message
(
pSock
,
"Info>"
+
QString
(
tr
(
"Client connected."
)));
qDebug
()
<<
pSock
->
peerAddress
().
toString
()
<<
pSock
->
peerPort
()
<<
tr
(
"(%1)..connected."
).
arg
((
quint64
)
pSock
);
}
...
...
@@ -410,7 +410,7 @@ namespace ZPNetwork{
return
;
m_mutex_protect
.
lock
();
QList
<
QObject
*>
clientList
=
m_clientList
.
values
();
m_mutex_protect
.
unlock
();
foreach
(
QObject
*
obj
,
clientList
)
{
QTcpSocket
*
pSock
=
qobject_cast
<
QTcpSocket
*>
(
obj
);
...
...
@@ -438,7 +438,8 @@ namespace ZPNetwork{
}
}
m_mutex_protect
.
unlock
();
//m_clientList.clear();
// m_mutex_protect.unlock();
}
void
zp_netTransThread
::
KickClient
(
QObject
*
objClient
)
...
...
ZoomPipeline_FuncSvr/smartlink/st_clientnode_app_imp.cpp
浏览文件 @
3a883c97
...
...
@@ -102,6 +102,7 @@ namespace ExampleServer{
{
//strcpy(reply.TextInfo,"Server Access Error.");
emit
evt_Message
(
this
,
tr
(
"Database Access Error :"
)
+
query
.
lastError
().
text
());
db
.
close
();
}
}
else
...
...
ZoomPipeline_FuncSvr/smartlink/st_clientnode_applayer.cpp
浏览文件 @
3a883c97
...
...
@@ -25,6 +25,7 @@ namespace ExampleServer{
if
(
false
==
query
.
exec
())
{
emit
evt_Message
(
this
,
tr
(
"try to get relations Failed! "
)
+
query
.
lastError
().
text
());
db
.
close
();
return
false
;
}
...
...
@@ -57,6 +58,7 @@ namespace ExampleServer{
if
(
false
==
query
.
exec
())
{
emit
evt_Message
(
this
,
tr
(
"try to del old relations Failed! "
)
+
query
.
lastError
().
text
());
db
.
close
();
return
false
;
}
...
...
@@ -77,6 +79,7 @@ namespace ExampleServer{
if
(
false
==
query
.
exec
())
{
emit
evt_Message
(
this
,
tr
(
"try to insert new relations Failed! "
)
+
query
.
lastError
().
text
());
db
.
close
();
return
false
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录