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
94fd8174
Unverified
Commit
94fd8174
authored
Jan 15, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug/SKALE-3662 Adding libzmq
parent
475e9a3c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
11 deletions
+24
-11
ZMQServer.cpp
ZMQServer.cpp
+23
-6
ZMQServer.h
ZMQServer.h
+1
-5
No files found.
ZMQServer.cpp
View file @
94fd8174
...
@@ -31,9 +31,10 @@
...
@@ -31,9 +31,10 @@
using
namespace
std
;
using
namespace
std
;
ZMQServer
::
ZMQServer
()
ZMQServer
::
ZMQServer
()
:
isExitRequested
(
false
),
ctx_
(
1
),
:
isExitRequested
(
false
),
ctx_
(
make_shared
<
zmq
::
context_t
>
(
1
)),
frontend_
(
ctx_
,
ZMQ_ROUTER
),
frontend_
(
*
ctx_
,
ZMQ_ROUTER
),
backend_
(
ctx_
,
ZMQ_DEALER
)
{}
backend_
(
*
ctx_
,
ZMQ_DEALER
)
{
}
void
ZMQServer
::
run
()
{
void
ZMQServer
::
run
()
{
...
@@ -63,7 +64,7 @@ void ZMQServer::run() {
...
@@ -63,7 +64,7 @@ void ZMQServer::run() {
try
{
try
{
for
(
int
i
=
0
;
i
<
kMaxThread
;
++
i
)
{
for
(
int
i
=
0
;
i
<
kMaxThread
;
++
i
)
{
workers
.
push_back
(
make_shared
<
ServerWorker
>
(
ctx_
,
ZMQ_DEALER
));
workers
.
push_back
(
make_shared
<
ServerWorker
>
(
*
ctx_
,
ZMQ_DEALER
));
worker_threads
.
push_back
(
make_shared
<
std
::
thread
>
(
std
::
bind
(
&
ServerWorker
::
work
,
workers
[
i
])));
worker_threads
.
push_back
(
make_shared
<
std
::
thread
>
(
std
::
bind
(
&
ServerWorker
::
work
,
workers
[
i
])));
}
}
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
...
@@ -75,9 +76,17 @@ void ZMQServer::run() {
...
@@ -75,9 +76,17 @@ void ZMQServer::run() {
try
{
try
{
zmq
::
proxy
(
static_cast
<
void
*>
(
frontend_
),
static_cast
<
void
*>
(
backend_
),
nullptr
);
zmq
::
proxy
(
static_cast
<
void
*>
(
frontend_
),
static_cast
<
void
*>
(
backend_
),
nullptr
);
}
catch
(
exception
&
_e
)
{
}
catch
(
exception
&
_e
)
{
if
(
isExitRequested
)
{
spdlog
::
info
(
"Exited ZMQServer main thread"
);
return
;
}
spdlog
::
info
(
"Error, exiting zmq server ... {}"
,
_e
.
what
());
spdlog
::
info
(
"Error, exiting zmq server ... {}"
,
_e
.
what
());
return
;
return
;
}
catch
(...)
{
}
catch
(...)
{
if
(
isExitRequested
)
{
spdlog
::
info
(
"Exited ZMQServer main thread"
);
return
;
}
spdlog
::
info
(
"Error, exiting zmq server ..."
);
spdlog
::
info
(
"Error, exiting zmq server ..."
);
return
;
return
;
}
}
...
@@ -85,15 +94,23 @@ void ZMQServer::run() {
...
@@ -85,15 +94,23 @@ void ZMQServer::run() {
void
ZMQServer
::
exitWorkers
()
{
void
ZMQServer
::
exitWorkers
()
{
auto
doExit
=
!
exiting
.
exchange
(
true
);
auto
doExit
=
!
isExitRequested
.
exchange
(
true
);
if
(
doExit
)
{
if
(
doExit
)
{
spdlog
::
info
(
"Tell
ing
workers to exit"
);
spdlog
::
info
(
"Tell workers to exit"
);
for
(
auto
&&
worker
:
workers
)
{
for
(
auto
&&
worker
:
workers
)
{
worker
->
requestExit
();
worker
->
requestExit
();
}
}
spdlog
::
info
(
"Terminating context ..."
);
// terminate context (destructor will be called)
ctx_
=
nullptr
;
spdlog
::
info
(
"Terminated context ..."
);
spdlog
::
info
(
"joining threads ..."
);
spdlog
::
info
(
"joining threads ..."
);
for
(
auto
&&
thread
:
worker_threads
)
for
(
auto
&&
thread
:
worker_threads
)
thread
->
join
();
thread
->
join
();
...
...
ZMQServer.h
View file @
94fd8174
...
@@ -44,12 +44,8 @@ using namespace std;
...
@@ -44,12 +44,8 @@ using namespace std;
class
ZMQServer
{
class
ZMQServer
{
public
:
public
:
atomic
<
bool
>
exiting
;
ZMQServer
();
ZMQServer
();
enum
{
enum
{
kMaxThread
=
1
kMaxThread
=
1
};
};
...
@@ -59,7 +55,7 @@ public:
...
@@ -59,7 +55,7 @@ public:
void
exitWorkers
();
void
exitWorkers
();
private
:
private
:
zmq
::
context_t
ctx_
;
shared_ptr
<
zmq
::
context_t
>
ctx_
;
zmq
::
socket_t
frontend_
;
zmq
::
socket_t
frontend_
;
zmq
::
socket_t
backend_
;
zmq
::
socket_t
backend_
;
...
...
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