24 #include <core/threading/thread_collector.h>
25 #include <fvutils/net/fuse_server.h>
26 #include <fvutils/net/fuse_server_client_thread.h>
27 #include <netcomm/utils/acceptor_thread.h>
33 namespace firevision {
56 FuseServer::FuseServer(
bool enable_ipv4,
58 const std::string &listen_ipv4,
59 const std::string &listen_ipv6,
60 unsigned short int port,
64 thread_collector_ = collector;
68 this, Socket::IPv4, listen_ipv4, port,
"FuseNetworkAcceptorThread"));
72 this, Socket::IPv6, listen_ipv6, port,
"FuseNetworkAcceptorThread"));
74 if (thread_collector_) {
75 for (
size_t i = 0; i < acceptor_threads_.size(); ++i) {
76 thread_collector_->
add(acceptor_threads_[i]);
79 for (
size_t i = 0; i < acceptor_threads_.size(); ++i) {
80 acceptor_threads_[i]->start();
88 for (
size_t i = 0; i < acceptor_threads_.size(); ++i) {
89 if (thread_collector_) {
90 thread_collector_->
remove(acceptor_threads_[i]);
92 acceptor_threads_[i]->cancel();
93 acceptor_threads_[i]->join();
95 delete acceptor_threads_[i];
97 acceptor_threads_.clear();
99 for (cit_ = clients_.begin(); cit_ != clients_.end(); ++cit_) {
100 if (thread_collector_) {
102 thread_collector_->
remove(*cit_);
116 if (thread_collector_) {
117 thread_collector_->add(client);
121 clients_.push_back_locked(client);
130 dead_clients_.push_back_locked(client);
138 dead_clients_.lock();
143 while (!dead_clients_.empty()) {
144 dcit = dead_clients_.begin();
146 if (thread_collector_) {
148 thread_collector_->
remove(*dcit);
153 if ((cit_ = find(clients_.begin(), clients_.end(), *dcit)) != clients_.end()) {
154 clients_.erase(cit_);
158 dead_clients_.erase(dcit);
163 dead_clients_.unlock();