aboutsummaryrefslogtreecommitdiff
path: root/node/node.cpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-11-21 15:22:48 +0100
committerDennis Brentjes <d.brentjes@gmail.com>2016-11-21 15:22:48 +0100
commit37315f877ef27d0f8585389f0c83cd00a31577c1 (patch)
treecaead8a996811c154859d97ae3c5c946ae8da4b6 /node/node.cpp
parente4cf0d04c4afff98603df440d12a4a19b3717a34 (diff)
downloadcmix-37315f877ef27d0f8585389f0c83cd00a31577c1.tar.gz
cmix-37315f877ef27d0f8585389f0c83cd00a31577c1.tar.bz2
cmix-37315f877ef27d0f8585389f0c83cd00a31577c1.zip
Reworked server and client to do one mix and shutdown.
This is done as cleanly as possible to track down any memory leaks. unfortunately there is still one async operation running on the nodes. when there should be none. So the nodes are still forced to stop with a. io_service.stop().
Diffstat (limited to 'node/node.cpp')
-rw-r--r--node/node.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/node/node.cpp b/node/node.cpp
index 3ad4a2d..cc5e47a 100644
--- a/node/node.cpp
+++ b/node/node.cpp
@@ -154,12 +154,12 @@ void Node::handle_message(Purgatory::iterator handle, cmix_proto::CMixMessage me
void Node::start_precomputation() {
BOOST_LOG_TRIVIAL(trace) << "Starting precomputation for " << clients.size() << " clients.";
index_map.clear();
- if(start_mix(&cmix_ctx, clients.size()) != no_error) {
+ if(start_mix(&cmix_ctx, messages.size()) != no_error) {
exit(-1);
}
unsigned int i = 0;
- for(auto&& pair : clients) {
+ for(auto&& pair : messages) {
index_map[pair.first] = i++;
}
@@ -252,3 +252,26 @@ void Node::start_realtime_phase() {
next_node.async_send(realpre);
}
+
+void Node::shutdown()
+{
+ server.close();
+ for(auto&& pair : clients) {
+ pair.second.async_send(cmix_proto::Bye());
+ }
+}
+
+bool Node::send_bye(bool got_bye)
+{
+ if(got_bye) {
+ if(!shutting_down) {
+ next_node.async_send(cmix_proto::Bye());
+ }
+ io_service.stop();
+ return true;
+ } else {
+ next_node.async_send(cmix_proto::Bye());
+ shutting_down = true;
+ return false;
+ }
+}