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
9e9f36bc
Unverified
Commit
9e9f36bc
authored
3 years ago
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-4586 Added Thread Pool
parent
a36f87e3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
34 deletions
+41
-34
ExitRequestedException.cpp
ExitRequestedException.cpp
+2
-5
ExitRequestedException.h
ExitRequestedException.h
+3
-4
ZMQServer.cpp
zmq_src/ZMQServer.cpp
+32
-25
ZMQServer.h
zmq_src/ZMQServer.h
+4
-0
No files found.
ExitRequestedException.cpp
View file @
9e9f36bc
...
...
@@ -21,12 +21,9 @@
@date 2018
*/
#include "common.h"
#include "Log.h"
#include "ExitRequestedException.h"
ExitRequestedException
::
ExitRequestedException
(
const
std
::
string
&
_message
,
const
string
&
_className
)
:
Exception
(
_message
,
_className
)
{
fatal
=
false
;
ExitRequestedException
::
ExitRequestedException
()
{
}
This diff is collapsed.
Click to expand it.
ExitRequestedException.h
View file @
9e9f36bc
...
...
@@ -23,10 +23,9 @@
#pragma once
#include
"Exception.h"
#include
<exception>
class
ExitRequestedException
:
public
Exception
{
class
ExitRequestedException
:
public
std
::
exception
{
public
:
ExitRequestedException
(
const
std
::
string
&
_message
,
const
std
::
string
&
_className
);
ExitRequestedException
();
};
This diff is collapsed.
Click to expand it.
zmq_src/ZMQServer.cpp
View file @
9e9f36bc
...
...
@@ -61,7 +61,7 @@ ZMQServer::ZMQServer(bool _checkSignature, bool _checkKeyOwnership, const string
}
void
ZMQServer
::
run
()
{
void
ZMQServer
::
initListenSocket
()
{
auto
port
=
BASE_PORT
+
5
;
...
...
@@ -71,20 +71,29 @@ void ZMQServer::run() {
CHECK_STATE
(
socket
);
socket
->
bind
(
"tcp://*:"
+
to_string
(
port
));
}
catch
(...)
{
spdlog
::
error
(
"
S
erver task could not bind to port:{}"
,
port
);
spdlog
::
error
(
"
Zmq s
erver task could not bind to port:{}"
,
port
);
throw
SGXException
(
ZMQ_COULD_NOT_BIND_FRONT_END
,
"Server task could not bind."
);
}
spdlog
::
info
(
"Bound port ..."
);
spdlog
::
info
(
"ZMQ server socket created and bound."
);
}
void
ZMQServer
::
run
()
{
spdlog
::
info
(
"Started zmq read loop ..."
);
zmqServer
->
initListenSocket
();
spdlog
::
info
(
"Started zmq read loop."
);
while
(
!
isExitRequested
)
{
try
{
zmqServer
->
doOneServerLoop
();
}
catch
(...)
{
}
catch
(
ExitRequestedException
&
e
)
{
spdlog
::
info
(
"Exit requested. Exiting server loop"
);
break
;
}
catch
(...)
{
spdlog
::
error
(
"doOneServerLoop threw exception. This should never happen!"
);
}
}
...
...
@@ -158,6 +167,12 @@ ZMQServer::~ZMQServer() {
exitZMQServer
();
}
void
ZMQServer
::
checkForExit
()
{
if
(
isExitRequested
)
{
throw
ExitRequestedException
();
}
}
void
ZMQServer
::
doOneServerLoop
()
{
string
replyStr
;
...
...
@@ -172,7 +187,6 @@ void ZMQServer::doOneServerLoop() {
try
{
zmq_pollitem_t
items
[
1
];
items
[
0
].
socket
=
*
socket
;
items
[
0
].
events
=
ZMQ_POLLIN
;
...
...
@@ -180,21 +194,19 @@ void ZMQServer::doOneServerLoop() {
int
pollResult
=
0
;
do
{
checkForExit
();
pollResult
=
zmq_poll
(
items
,
1
,
1000
);
if
(
isExitRequested
)
{
return
;
}
}
while
(
pollResult
==
0
);
if
(
!
socket
->
recv
(
&
identity
))
{
// something terrible happened
spdlog
::
error
(
"Fatal error: socket->recv(&identity) returned false"
);
spdlog
::
error
(
"Fatal error: socket->recv(&identity) returned false
. Exiting.
"
);
exit
(
-
11
);
}
if
(
!
identity
.
more
())
{
// something terrible happened
spdlog
::
error
(
"Fatal error: zmq_msg_more(identity) returned false"
);
spdlog
::
error
(
"Fatal error: zmq_msg_more(identity) returned false
. Existing.
"
);
exit
(
-
12
);
}
...
...
@@ -202,7 +214,7 @@ void ZMQServer::doOneServerLoop() {
if
(
!
socket
->
recv
(
&
reqMsg
,
0
))
{
// something terrible happened
spdlog
::
error
(
"Fatal error: socket.recv(&reqMsg, 0) returned false"
);
spdlog
::
error
(
"Fatal error: socket.recv(&reqMsg, 0) returned false
. Exiting
"
);
exit
(
-
13
);
}
...
...
@@ -216,23 +228,18 @@ void ZMQServer::doOneServerLoop() {
CHECK_STATE2
(
parsedMsg
,
ZMQ_COULD_NOT_PARSE
);
result
=
parsedMsg
->
process
();
}
catch
(
std
::
exception
&
e
)
{
if
(
isExitRequested
)
{
return
;
}
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
*
)
identity
.
data
(),
identity
.
size
()));
spdlog
::
error
(
"Client request :"
+
stringToParse
);
}
catch
(...)
{
if
(
isExitRequested
)
{
return
;
}
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
*
)
identity
.
data
(),
identity
.
size
()));
spdlog
::
error
(
"Client request :"
+
stringToParse
);
}
...
...
@@ -260,7 +267,7 @@ void ZMQServer::doOneServerLoop() {
exit
(
-
16
);
}
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
if
(
isExitRequested
)
{
return
;
}
...
...
@@ -280,16 +287,16 @@ void ZMQServer::workerThreadProcessNextMessage() {
cerr
<<
"WORKER LOOP"
<<
endl
;
}
void
ZMQServer
::
workerThreadMessageProcessLoop
(
ZMQServer
*
_agent
)
{
void
ZMQServer
::
workerThreadMessageProcessLoop
(
ZMQServer
*
_agent
)
{
CHECK_STATE
(
_agent
);
_agent
->
waitOnGlobalStartBarrier
();
// do work forever until told to exit
while
(
!
isExitRequested
)
{
try
{
_agent
->
workerThreadProcessNextMessage
();
}
catch
(
ExitRequestedException
&
e
)
{
}
catch
(
ExitRequestedException
&
e
)
{
break
;
}
catch
(
Exception
&
e
)
{
}
catch
(
Exception
&
e
)
{
spdlog
::
error
(
string
(
"Caught exception in worker thread loop:"
)
+
e
.
what
());
}
}
...
...
This diff is collapsed.
Click to expand it.
zmq_src/ZMQServer.h
View file @
9e9f36bc
...
...
@@ -74,6 +74,8 @@ public:
void
run
();
void
initListenSocket
();
static
void
initZMQServer
(
bool
_checkSignature
,
bool
_checkKeyOwnership
);
static
void
exitZMQServer
();
...
...
@@ -81,6 +83,8 @@ public:
void
workerThreadProcessNextMessage
();
void
checkForExit
();
};
...
...
This diff is collapsed.
Click to expand it.
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