From 0a421c36ccb98b80930cd67f66c55ee6e1ecdc97 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Thu, 19 Jun 2008 21:57:00 +0000 Subject: !!!!!!!!!!!!!!!!!!!!!!!!!! Big changes: Moved from pThread to boost::threads further testing needed. Version before this was testet pretty well and should become the new release. !!!!!!!!!!!!!!!!!!!!!!!!!! --- src/anytun.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src/anytun.cpp') diff --git a/src/anytun.cpp b/src/anytun.cpp index fdeaead..1d4ac5b 100644 --- a/src/anytun.cpp +++ b/src/anytun.cpp @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include // for ENOMEM @@ -114,7 +114,7 @@ bool checkPacketSeqNr(EncryptedPacket& pack,ConnectionParam& conn) return true; } -void* sender(void* p) +void sender(void* p) { try { @@ -199,11 +199,10 @@ void* sender(void* p) { cLog.msg(Log::PRIO_ERR) << "sender thread died due to an uncaught exception: " << e.what(); } - pthread_exit(NULL); } #ifndef ANYTUN_NOSYNC -void* syncConnector(void* p ) +void syncConnector(void* p ) { ThreadParam* param = reinterpret_cast(p); @@ -216,10 +215,9 @@ void* syncConnector(void* p ) { h.Select(); } - pthread_exit(NULL); } -void* syncListener(void* p ) +void syncListener(void* p ) { ThreadParam* param = reinterpret_cast(p); @@ -227,7 +225,7 @@ void* syncListener(void* p ) SyncListenSocket l(h,param->cl); if (l.Bind(gOpt.getLocalSyncPort())) - pthread_exit(NULL); + return; Utility::ResolveLocal(); // resolve local hostname h.Add(&l); @@ -238,7 +236,7 @@ void* syncListener(void* p ) } #endif -void* receiver(void* p) +void receiver(void* p) { try { @@ -335,7 +333,6 @@ void* receiver(void* p) { cLog.msg(Log::PRIO_ERR) << "receiver thread died due to an uncaught exception: " << e.what(); } - pthread_exit(NULL); } #define MIN_GCRYPT_VERSION "1.2.0" @@ -534,26 +531,26 @@ int main(int argc, char* argv[]) // this must be called before any other libgcrypt call if(!initLibGCrypt()) return -1; - - pthread_t senderThread; - pthread_create(&senderThread, NULL, sender, &p); - pthread_t receiverThread; - pthread_create(&receiverThread, NULL, receiver, &p); + + boost::thread senderThread(boost::bind(sender,&p)); + boost::thread receiverThread(boost::bind(receiver,&p)); #ifndef ANYTUN_NOSYNC - pthread_t syncListenerThread; + boost::thread * syncListenerThread; if ( gOpt.getLocalSyncPort()) - pthread_create(&syncListenerThread, NULL, syncListener, &p); + syncListenerThread = new boost::thread(boost::bind(syncListener,&p)); - std::list connectThreads; + std::list connectThreads; for(ConnectToList::iterator it = connect_to.begin() ;it != connect_to.end(); ++it) { - connectThreads.push_back(pthread_t()); ThreadParam * point = new ThreadParam(dev, *src, cl, queue,*it); - pthread_create(& connectThreads.back(), NULL, syncConnector, point); + connectThreads.push_back(new boost::thread(boost::bind(syncConnector,point))); } #endif int ret = sig.run(); + return ret; + // TODO cleanup here! + /* pthread_cancel(senderThread); pthread_cancel(receiverThread); #ifndef ANYTUN_NOSYNC @@ -575,7 +572,8 @@ int main(int argc, char* argv[]) delete src; delete &p.connto; - return ret; + return ret; + */ } catch(std::runtime_error e) { -- cgit v1.2.3