diff options
-rw-r--r-- | src/anytun.cpp | 5 | ||||
-rw-r--r-- | src/syncQueue.cpp | 18 | ||||
-rw-r--r-- | src/syncQueue.h | 7 | ||||
-rw-r--r-- | src/syncServer.cpp | 8 | ||||
-rw-r--r-- | src/syncServer.h | 1 |
5 files changed, 25 insertions, 14 deletions
diff --git a/src/anytun.cpp b/src/anytun.cpp index 3d7dd5d..4bb6e14 100644 --- a/src/anytun.cpp +++ b/src/anytun.cpp @@ -209,7 +209,7 @@ void syncConnector(void* p ) sc.run(); } -void syncListener(void* p ) +void syncListener(SyncQueue * queue ) { // ThreadParam* param = reinterpret_cast<ThreadParam*>(p); @@ -217,6 +217,7 @@ void syncListener(void* p ) { asio::io_service io_service; SyncServer server(io_service,asio::ip::tcp::endpoint(asio::ip::tcp::v4(), gOpt.getLocalSyncPort())); + queue->setSyncServerPtr(&server); io_service.run(); } catch (std::exception& e) @@ -547,7 +548,7 @@ int main(int argc, char* argv[]) #ifndef ANYTUN_NOSYNC boost::thread * syncListenerThread; if ( gOpt.getLocalSyncPort()) - syncListenerThread = new boost::thread(boost::bind(syncListener,&p)); + syncListenerThread = new boost::thread(boost::bind(syncListener,&queue)); std::list<boost::thread *> connectThreads; for(ConnectToList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) { diff --git a/src/syncQueue.cpp b/src/syncQueue.cpp index 582e8ae..d90caaf 100644 --- a/src/syncQueue.cpp +++ b/src/syncQueue.cpp @@ -41,34 +41,34 @@ #include "syncQueue.h" + void SyncQueue::push(const SyncCommand & scom ) { std::ostringstream sout; boost::archive::text_oarchive oa(sout); oa << scom; - Lock lock(mutex_); std::stringstream lengthout; lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' '; - queue_.push(lengthout.str()+sout.str()); + push(lengthout.str()+sout.str()); } void SyncQueue::push(const std::string & str ) { Lock lock(mutex_); - queue_.push(str); +// std::cout << "Debug" << std:endl; + if( syncServer_) + syncServer_->send(str); } -std::string SyncQueue::pop() +void SyncQueue::setSyncServerPtr(SyncServer * ptr) { - Lock lock(mutex_); - std::string tmp = queue_.front(); - queue_.pop(); - return tmp; + Lock lock(mutex_); + syncServer_=ptr; } bool SyncQueue::empty() { Lock lock(mutex_); - return queue_.empty(); + return 1; } diff --git a/src/syncQueue.h b/src/syncQueue.h index 23d1236..f076b4a 100644 --- a/src/syncQueue.h +++ b/src/syncQueue.h @@ -39,13 +39,15 @@ #include "threadUtils.hpp" #include "datatypes.h" +#include "syncServer.h" class SyncQueue { public: - SyncQueue() {}; + SyncQueue():syncServer_(NULL) {}; ~SyncQueue() {}; + void setSyncServerPtr(SyncServer *); void push(const std::string & ); void push(const SyncCommand & ); std::string pop(); @@ -54,9 +56,8 @@ public: private: SyncQueue(const SyncQueue &s); void operator=(const SyncQueue &s); - typedef std::queue<std::string> StringQueue; - StringQueue queue_; Mutex mutex_; + SyncServer * syncServer_; }; #endif diff --git a/src/syncServer.cpp b/src/syncServer.cpp index fc0c4bc..ea6df4b 100644 --- a/src/syncServer.cpp +++ b/src/syncServer.cpp @@ -19,6 +19,14 @@ void SyncServer::start_accept() asio::placeholders::error)); } +void SyncServer::send(std::string message) +{ +for(std::list<SyncTcpConnection::pointer>::iterator it = conns_.begin() ;it != conns_.end(); ++it) { + (*it)->Send(message); + } + +} + void SyncServer::handle_accept(SyncTcpConnection::pointer new_connection, const asio::error_code& error) { diff --git a/src/syncServer.h b/src/syncServer.h index 3fde1cc..0899d26 100644 --- a/src/syncServer.h +++ b/src/syncServer.h @@ -17,6 +17,7 @@ public: SyncServer(asio::io_service& io_service, asio::ip::tcp::endpoint tcp_endpoint ); std::list<SyncTcpConnection::pointer> conns_; + void send(std::string message); private: void start_accept(); void handle_accept(SyncTcpConnection::pointer new_connection, |