Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
sgxwallet
Commits
5319afa7
Unverified
Commit
5319afa7
authored
Sep 10, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-4586 Added concurrent queue
parent
597ecc4d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
17 deletions
+21
-17
ZMQServer.cpp
zmq_src/ZMQServer.cpp
+20
-14
ZMQServer.h
zmq_src/ZMQServer.h
+1
-3
No files found.
zmq_src/ZMQServer.cpp
View file @
5319afa7
...
...
@@ -179,7 +179,7 @@ void ZMQServer::checkForExit() {
}
PollResult
ZMQServer
::
pollIncomingAndSendOutgoing
()
{
void
ZMQServer
::
waitForIncomingAndProcessOutgoingMessages
()
{
zmq_pollitem_t
items
[
1
];
items
[
0
].
socket
=
*
socket
;
items
[
0
].
events
=
ZMQ_POLLIN
;
...
...
@@ -198,7 +198,6 @@ PollResult ZMQServer::pollIncomingAndSendOutgoing() {
}
}
while
(
pollResult
==
0
);
return
GOT_INCOMING_MSG
;
}
pair
<
string
,
shared_ptr
<
zmq
::
message_t
>>
ZMQServer
::
receiveMessage
()
{
...
...
@@ -277,7 +276,7 @@ void ZMQServer::doOneServerLoop() {
try
{
poll
();
waitForIncomingAndProcessOutgoingMessages
();
tie
(
msgStr
,
identity
)
=
receiveMessage
();
...
...
@@ -292,9 +291,9 @@ void ZMQServer::doOneServerLoop() {
if
((
dynamic_pointer_cast
<
BLSSignReqMessage
>
(
msg
))
||
dynamic_pointer_cast
<
ECDSASignReqMessage
>
(
msg
))
{
boost
::
hash
<
std
::
string
>
string_hash
;
boost
::
hash
<
std
::
string
>
string_hash
;
auto
hash
=
string_hash
(
string
((
const
char
*
)
identity
->
data
()));
auto
hash
=
string_hash
(
string
((
const
char
*
)
identity
->
data
()));
index
=
hash
%
(
NUM_ZMQ_WORKER_THREADS
-
1
);
}
else
{
...
...
@@ -305,7 +304,6 @@ void ZMQServer::doOneServerLoop() {
(
msg
,
identity
);
incomingQueue
.
at
(
index
).
enqueue
(
element
);
}
catch
(
ExitRequestedException
)
{
...
...
@@ -327,8 +325,6 @@ void ZMQServer::doOneServerLoop() {
}
}
void
ZMQServer
::
workerThreadProcessNextMessage
(
uint64_t
_threadNumber
)
{
...
...
@@ -336,34 +332,44 @@ void ZMQServer::workerThreadProcessNextMessage(uint64_t _threadNumber) {
Json
::
Value
result
;
result
[
"status"
]
=
ZMQ_SERVER_ERROR
;
shared_ptr
<
zmq
::
message_t
>
identity
=
nullptr
;
string
msgStr
;
pair
<
shared_ptr
<
ZMQMessage
>
,
shared_ptr
<
zmq
::
message_t
>>
element
;
try
{
while
(
!
incomingQueue
.
at
(
_threadNumber
)
.
wait_dequeue_timed
(
element
,
std
::
chrono
::
milliseconds
(
1000
)))
{
checkForExit
();
}
}
catch
(
ExitRequestedException
)
{
throw
;
}
catch
(
exception
&
e
)
{
checkForExit
();
result
[
"errorMessage"
]
=
string
(
e
.
what
());
spdlog
::
error
(
"Exception in zmq server :{}"
,
e
.
what
());
spdlog
::
error
(
"Client request :"
+
msgStr
);
}
catch
(...)
{
checkForExit
();
spdlog
::
error
(
"Error in zmq server "
);
result
[
"errorMessage"
]
=
"Error in zmq server "
;
spdlog
::
error
(
"Client request :"
+
msgStr
);
}
try
{
result
=
element
.
first
->
process
();
}
catch
(
ExitRequestedException
)
{
throw
;
}
catch
(
exception
&
e
)
{
checkForExit
();
result
[
"errorMessage"
]
=
string
(
e
.
what
());
spdlog
::
error
(
"Exception in zmq server :{}"
,
e
.
what
());
spdlog
::
error
(
"ID:"
+
string
((
char
*
)
identity
->
data
(),
identity
->
size
()));
spdlog
::
error
(
"ID:"
+
string
((
char
*
)
element
.
second
->
data
(),
element
.
second
->
size
()));
spdlog
::
error
(
"Client request :"
+
msgStr
);
}
catch
(...)
{
checkForExit
();
spdlog
::
error
(
"Error in zmq server "
);
result
[
"errorMessage"
]
=
"Error in zmq server "
;
spdlog
::
error
(
"ID:"
+
string
((
char
*
)
identity
->
data
(),
identity
->
size
()));
spdlog
::
error
(
"ID:"
+
string
((
char
*
)
element
.
second
->
data
(),
element
.
second
->
size
()));
spdlog
::
error
(
"Client request :"
+
msgStr
);
}
...
...
zmq_src/ZMQServer.h
View file @
5319afa7
...
...
@@ -39,8 +39,6 @@
using
namespace
moodycamel
;
typedef
enum
{
GOT_INCOMING_MSG
=
0
,
GOT_OUTFOING_MSG
=
1
}
PollResult
;
static
const
uint64_t
NUM_ZMQ_WORKER_THREADS
=
16
;
...
...
@@ -91,7 +89,7 @@ public:
void
checkForExit
();
PollResult
pollIncomingAndSendOutGoing
();
void
waitForIncomingAndProcessOutgoingMessages
();
pair
<
string
,
shared_ptr
<
zmq
::
message_t
>>
receiveMessage
();
...
...
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