src/nntp/mime/MimeChar.cpp\r
src/nntp/mime/MimeCode.cpp\r
src/nntp/mime/MimeType.cpp\r
+src/pthreadwrapper/guard.cpp\r
+src/pthreadwrapper/mutex.cpp\r
+src/pthreadwrapper/runnable.cpp\r
+src/pthreadwrapper/thread.cpp\r
src/xyssl/sha1.c\r
)\r
\r
ADD_DEFINITIONS(-DTIXML_USE_STL)\r
\r
-IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)\r
+IF(CMAKE_COMPILER_IS_GNUCXX)\r
ADD_DEFINITIONS(-fpermissive)\r
-ENDIF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)\r
+ENDIF(CMAKE_COMPILER_IS_GNUCXX)\r
\r
ADD_EXECUTABLE(fms ${FMS_SRC})\r
\r
-INCLUDE_DIRECTORIES(libs/sqlite3 libs/tinyxml)\r
-\r
IF(WIN32)\r
TARGET_LINK_LIBRARIES(fms ws2_32)\r
ENDIF(WIN32)\r
\r
FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3 sqlite3_s)\r
FIND_LIBRARY(TINYXML_LIBRARY NAMES tinyxml tinyxml_s)\r
-FIND_LIBRARY(ZTHREADS_LIBRARY NAMES zthread ZThread zthread_s)\r
+#FIND_LIBRARY(ZTHREADS_LIBRARY NAMES zthread ZThread zthread_s)\r
+FIND_LIBRARY(PTHREADS_LIBRARY NAMES pthread pthreads pthreadvc2)\r
\r
IF(SQLITE3_LIBRARY)\r
TARGET_LINK_LIBRARIES(fms ${SQLITE3_LIBRARY})\r
MESSAGE(STATUS "Could not find system SQLite library. Will compile from included source.")\r
ADD_LIBRARY(sqlite3 libs/sqlite3/sqlite3.c)\r
TARGET_LINK_LIBRARIES(fms sqlite3)\r
-ADD_LIBRARY(tinyxml libs/tinyxml/tinystr.cpp libs/tinyxml/tinyxml.cpp libs/tinyxml/tinyxmlerror.cpp libs/tinyxml/tinyxmlparser.cpp)\r
-\r
+ INCLUDE_DIRECTORIES(libs/sqlite3)\r
ENDIF(SQLITE3_LIBRARY)\r
\r
IF(TINYXML_LIBRARY)\r
MESSAGE(STATUS "Could not find system TinyXML library. Will compile from included source.")\r
ADD_LIBRARY(tinyxml libs/tinyxml/tinystr.cpp libs/tinyxml/tinyxml.cpp libs/tinyxml/tinyxmlerror.cpp libs/tinyxml/tinyxmlparser.cpp)\r
TARGET_LINK_LIBRARIES(fms tinyxml)\r
+ INCLUDE_DIRECTORIES(libs/tinyxml)\r
ENDIF(TINYXML_LIBRARY)\r
\r
-IF(ZTHREADS_LIBRARY)\r
- TARGET_LINK_LIBRARIES(fms ${ZTHREADS_LIBRARY})\r
-ELSE(ZTHREADS_LIBRARY)\r
- MESSAGE(FATAL_ERROR "Could not find ZThreads library. You must set the location manually.")\r
-ENDIF(ZTHREADS_LIBRARY)\r
+#IF(ZTHREADS_LIBRARY)\r
+# TARGET_LINK_LIBRARIES(fms ${ZTHREADS_LIBRARY})\r
+#ELSE(ZTHREADS_LIBRARY)\r
+# MESSAGE(FATAL_ERROR "Could not find ZThreads library. You must set the location manually.")\r
+#ENDIF(ZTHREADS_LIBRARY)\r
+\r
+IF(PTHREADS_LIBRARY)\r
+ TARGET_LINK_LIBRARIES(fms ${PTHREADS_LIBRARY})\r
+ELSE(PTHREADS_LIBRARY)\r
+ MESSAGE(FATAL ERROR "Could not find pthreads library. You must set the location manually.")\r
+ENDIF(PTHREADS_LIBRARY)\r
#include "ilogger.h"\r
#include "idatabase.h"\r
\r
-#include <zthread/Thread.h>\r
+//#include <zthread/Thread.h>\r
+#include "pthreadwrapper.h"\r
\r
-class CommandThread:public ZThread::Runnable,public ILogger, public IDatabase\r
+class CommandThread:public PThread::Runnable,public ILogger, public IDatabase\r
{\r
public:\r
\r
- void run();\r
+ void Run();\r
\r
private:\r
\r
#ifndef _sqlite3db_\r
#define _sqlite3db_\r
\r
-#include <zthread/Singleton.h>\r
-#include <zthread/Mutex.h>\r
+//#include <zthread/Singleton.h>\r
+//#include <zthread/Mutex.h>\r
#include <sqlite3.h>\r
#include <string>\r
+#include "../../pthreadwrapper/singleton.h"\r
+#include "../../pthreadwrapper/mutex.h"\r
\r
#include "../sqlite3db.h"\r
\r
namespace SQLite3DB\r
{\r
\r
-class DB:public ZThread::Singleton<DB>\r
+class DB:public PThread::Singleton<DB>\r
{\r
public:\r
DB();\r
\r
sqlite3 *GetDB() { return m_db; }\r
\r
- ZThread::Mutex m_mutex; // public so that recordset and statment can lock this mutex themselves\r
+ PThread::Mutex m_mutex; // public so that recordset and statment can lock this mutex themselves\r
\r
private:\r
void Initialize();\r
#include "ifcpconnected.h"\r
#include "iperiodicprocessor.h"\r
\r
-#include <zthread/Runnable.h>\r
+//#include <zthread/Runnable.h>\r
+#include "../pthreadwrapper/runnable.h"\r
\r
// forward declaration\r
class IFreenetRegistrable;\r
\r
-class FreenetMasterThread:public ZThread::Runnable,public ILogger, public IFCPMessageHandler\r
+class FreenetMasterThread:public PThread::Runnable,public ILogger, public IFCPMessageHandler\r
{\r
public:\r
FreenetMasterThread();\r
\r
const bool HandleMessage(FCPMessage &message);\r
\r
- void run();\r
+ void Run();\r
\r
// registration methods for children objects\r
void RegisterPeriodicProcessor(IPeriodicProcessor *obj);\r
void IIndexInserter<IDTYPE>::InitializeIIndexInserter()\r
{\r
m_fcpuniquename="";\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
+ Option::Instance()->Get("MessageBase",m_messagebase);\r
m_lastchecked.SetToGMTime();\r
}\r
\r
m_maxrequests=-1;\r
m_fcpuniquename="";\r
\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
+ Option::Instance()->Get("MessageBase",m_messagebase);\r
m_tempdate.SetToGMTime();\r
}\r
\r
#define _global_\r
\r
#include <vector>\r
-#include <zthread/Thread.h>\r
+//#include <zthread/Thread.h>\r
+#include "pthreadwrapper/thread.h"\r
\r
-#define FMS_VERSION "0.1.2"\r
+#define FMS_VERSION "0.1.3"\r
\r
// opens database and creates tables and initial inserts if necessary\r
void SetupDB();\r
// opens logfile and sets it up\r
void SetupLogFile();\r
\r
-void StartThreads(std::vector<ZThread::Thread *> &threads);\r
-void ShutdownThreads(std::vector<ZThread::Thread *> &threads);\r
+void StartThreads(std::vector<PThread::Thread *> &threads);\r
+void ShutdownThreads(std::vector<PThread::Thread *> &threads);\r
\r
// needed for Windows to setup network\r
void SetupNetwork();\r
class IDatabase\r
{\r
public:\r
- IDatabase():m_db(SQLite3DB::DB::instance()) {}\r
+ IDatabase():m_db(SQLite3DB::DB::Instance()) {}\r
\r
protected:\r
SQLite3DB::DB *m_db;\r
class ILogger\r
{\r
public:\r
- ILogger():m_log(LogFile::instance()) {}\r
+ ILogger():m_log(LogFile::Instance()) {}\r
\r
protected:\r
LogFile *m_log;\r
#ifndef _logfile_\r
#define _logfile_\r
\r
-#include <zthread/Singleton.h>\r
-#include <zthread/Mutex.h>\r
+//#include <zthread/Singleton.h>\r
+//#include <zthread/Mutex.h>\r
+#include "pthreadwrapper/singleton.h"\r
+#include "pthreadwrapper/mutex.h"\r
+#include <string>\r
\r
-class LogFile:public ZThread::Singleton<LogFile>\r
+class LogFile:public PThread::Singleton<LogFile>\r
{\r
public:\r
LogFile();\r
bool m_writenewline;\r
char *m_datebuffer;\r
\r
- ZThread::Mutex m_logmutex;\r
+ PThread::Mutex m_logmutex;\r
\r
};\r
\r
\r
};\r
\r
-#endif // _messagelist_
\ No newline at end of file
+#endif // _messagelist_\r
static const unsigned char m_aCharTbl[128];\r
};\r
\r
-#endif // _MIME_CHAR_H
\ No newline at end of file
+#endif // _MIME_CHAR_H\r
\r
#include <string>\r
#include <vector>\r
-#include <zthread/Runnable.h>\r
+//#include <zthread/Runnable.h>\r
+#include "../pthreadwrapper/runnable.h"\r
\r
#ifdef _WIN32\r
\r
#include <arpa/inet.h>\r
#endif\r
\r
-class NNTPConnection:public ZThread::Runnable,public ILogger//,public IDatabase\r
+class NNTPConnection:public PThread::Runnable,public ILogger\r
{\r
public:\r
NNTPConnection(SOCKET sock);\r
void Disconnect();\r
const bool Disconnected() { return m_socket==INVALID_SOCKET; }\r
\r
- void run();\r
+ void Run();\r
\r
private:\r
\r
\r
#include <list>\r
#include <vector>\r
-#include <zthread/Thread.h>\r
-#include <zthread/Task.h>\r
-#include <zthread/ZThread.h>\r
-#include <zthread/ThreadedExecutor.h>\r
+//#include <zthread/Thread.h>\r
+//#include <zthread/Task.h>\r
+//#include <zthread/ZThread.h>\r
+//#include <zthread/ThreadedExecutor.h>\r
+#include "../pthreadwrapper/runnable.h"\r
\r
#include "../socketdefines.h"\r
\r
/**\r
\brief Listens for NNTP connections\r
*/\r
-class NNTPListener:public ZThread::Runnable\r
+class NNTPListener:public PThread::Runnable\r
{\r
public:\r
NNTPListener();\r
~NNTPListener();\r
\r
- void run();\r
+ void Run();\r
void StartListen();\r
\r
private:\r
\r
unsigned short m_listenport;\r
std::vector<SOCKET> m_listensockets;\r
- ZThread::ThreadedExecutor m_connections;\r
+ //ZThread::ThreadedExecutor m_connections;\r
+ std::vector<PThread::Thread *> m_connectionthreads;\r
\r
};\r
\r
#include "db/sqlite3db.h"\r
\r
#include <sstream>\r
-#include <zthread/Singleton.h>\r
+//#include <zthread/Singleton.h>\r
+#include "pthreadwrapper/singleton.h"\r
\r
//just a wrapper around the database for the options table\r
-class Option:public ZThread::Singleton<Option>\r
+class Option:public PThread::Singleton<Option>\r
{\r
public:\r
const bool Get(const std::string &option, std::string &value);\r
std::string tempval;\r
if(Get(option,tempval)==true)\r
{\r
- SQLite3DB::Statement st=SQLite3DB::DB::instance()->Prepare("UPDATE tblOption SET OptionValue=? WHERE Option=?;");\r
+ SQLite3DB::Statement st=SQLite3DB::DB::Instance()->Prepare("UPDATE tblOption SET OptionValue=? WHERE Option=?;");\r
st.Bind(0,valuestr.str());\r
st.Bind(1,option);\r
st.Step();\r
}\r
else\r
{\r
- SQLite3DB::Statement st=SQLite3DB::DB::instance()->Prepare("INSERT INTO tblOption(Option,OptionValue) VALUES(?,?);");\r
+ SQLite3DB::Statement st=SQLite3DB::DB::Instance()->Prepare("INSERT INTO tblOption(Option,OptionValue) VALUES(?,?);");\r
st.Bind(0,option);\r
st.Bind(1,valuestr.str());\r
st.Step();\r
--- /dev/null
+/**\r
+ Light C++ wrapper around PThreads\r
+*/\r
+\r
+#ifndef _pthread_wrapper_\r
+\r
+#include <pthread.h>\r
+\r
+namespace PThread\r
+{\r
+\r
+ // forward declarations\r
+ class NonCopyable;\r
+ class Mutex;\r
+ class Guard;\r
+ class Runnable;\r
+ class Thread;\r
+\r
+} // namespace\r
+\r
+#include "pthreadwrapper/noncopyable.h"\r
+#include "pthreadwrapper/mutex.h"\r
+#include "pthreadwrapper/guard.h"\r
+#include "pthreadwrapper/runnable.h"\r
+#include "pthreadwrapper/thread.h"\r
+#include "pthreadwrapper/singleton.h"\r
+\r
+#endif // _pthread_wrapper_\r
--- /dev/null
+#ifndef _pthread_guard_\r
+#define _pthread_guard_\r
+\r
+namespace PThread\r
+{\r
+\r
+class Mutex;\r
+\r
+class Guard\r
+{\r
+public:\r
+ Guard();\r
+ Guard(Mutex &mutex);\r
+ ~Guard();\r
+private:\r
+ Mutex *m_mutex;\r
+};\r
+\r
+} // namespace\r
+\r
+#endif // _pthread_guard_\r
--- /dev/null
+#ifndef _pthread_mutex_\r
+#define _pthread_mutex_\r
+\r
+#include <pthread.h>\r
+#include <exception>\r
+\r
+namespace PThread\r
+{\r
+\r
+class Mutex\r
+{\r
+public:\r
+ Mutex();\r
+ ~Mutex();\r
+\r
+ void Acquire() throw(std::exception);\r
+ void Release();\r
+\r
+private:\r
+ pthread_mutex_t m_mutex;\r
+ pthread_mutexattr_t m_attr;\r
+};\r
+\r
+} // namespace\r
+\r
+#endif // _pthread_mutex_\r
--- /dev/null
+#ifndef _pthread_noncopyable_\r
+#define _pthread_noncopyable_\r
+\r
+namespace PThread\r
+{\r
+\r
+class NonCopyable\r
+{\r
+protected:\r
+ NonCopyable() {}\r
+ ~NonCopyable() {}\r
+\r
+private:\r
+ // restrict copy and assignment\r
+ NonCopyable(const NonCopyable &rhs);\r
+ const NonCopyable &operator=(const NonCopyable &rhs);\r
+};\r
+ \r
+} // namespace\r
+\r
+#endif // _pthread_noncopyable_\r
--- /dev/null
+#ifndef _pthread_runnable_\r
+#define _pthread_runnable_\r
+\r
+#include "thread.h"\r
+\r
+namespace PThread\r
+{\r
+\r
+class Thread;\r
+\r
+class Runnable\r
+{\r
+public:\r
+ Runnable():m_thread(0) {}\r
+ ~Runnable() {}\r
+\r
+ virtual void Run()=0;\r
+\r
+protected:\r
+ void Sleep(const long ms);\r
+ const bool IsCancelled();\r
+\r
+private:\r
+\r
+ friend Thread;\r
+ Thread *m_thread;\r
+\r
+};\r
+\r
+} // namespace\r
+\r
+#endif // _pthread_runnable_\r
--- /dev/null
+#ifndef _pthread_singleton_\r
+#define _pthread_singleton_\r
+\r
+#include "noncopyable.h"\r
+#include "guard.h"\r
+\r
+#include <cassert>\r
+\r
+namespace PThread\r
+{\r
+\r
+//! SingletonDestroyer\r
+template <class T>\r
+class Destroyer {\r
+ \r
+ T* doomed;\r
+ \r
+ public:\r
+ \r
+ Destroyer(T* q) : doomed(q) {\r
+ assert(doomed);\r
+ }\r
+ \r
+ ~Destroyer();\r
+\r
+};\r
+\r
+template <class T>\r
+Destroyer<T>::~Destroyer() {\r
+ \r
+ try {\r
+ \r
+ if(doomed)\r
+ delete doomed;\r
+ \r
+ } catch(...) { }\r
+ \r
+ doomed = 0;\r
+ \r
+} \r
+\r
+template <class T>\r
+class Singleton:public NonCopyable\r
+{\r
+public:\r
+\r
+ static T *Instance();\r
+\r
+private:\r
+ \r
+};\r
+\r
+template <class T>\r
+T *Singleton<T>::Instance()\r
+{\r
+ static T *obj=0;\r
+ static Mutex mutex;\r
+ Guard g(mutex);\r
+ if(obj==0)\r
+ {\r
+ obj=new T();\r
+ static Destroyer<T> des(obj);\r
+ }\r
+ return const_cast<T*>(obj);\r
+}\r
+\r
+} // namespace\r
+\r
+#endif // _pthread_singleton_\r
--- /dev/null
+#ifndef _pthread_thread_\r
+#define _pthread_thread_\r
+\r
+#include "noncopyable.h"\r
+#include "runnable.h"\r
+#include <pthread.h>\r
+\r
+namespace PThread\r
+{\r
+\r
+class Runnable;\r
+\r
+class Thread:public NonCopyable\r
+{\r
+public:\r
+ Thread();\r
+ Thread(Runnable *runnable);\r
+ ~Thread();\r
+\r
+ void Join();\r
+ void Cancel();\r
+\r
+ void Sleep(const long ms);\r
+ const bool IsCancelled() { return m_cancelled; }\r
+ const bool IsRunning() { return m_running; }\r
+\r
+private:\r
+ void Start();\r
+ static void *EntryPoint(void *pthis);\r
+\r
+ pthread_t m_thread;\r
+ bool m_running; // thread (object) is currently running\r
+ bool m_cancelled;\r
+ Runnable *m_runnable; // actual object that is being run\r
+\r
+};\r
+\r
+} // namespace\r
+\r
+#endif // _pthread_thread_\r
m_running=false; \r
}\r
\r
-void CommandThread::run()\r
+void CommandThread::Run()\r
{\r
std::string input;\r
m_running=true;\r
+\r
+ m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"CommandThread::run thread started.");\r
\r
do\r
{\r
+\r
+ std::cout << ">";\r
std::cin >> input;\r
\r
HandleInput(input);\r
\r
- }while(m_running==true);\r
+ }while(m_running && !IsCancelled());\r
\r
}\r
{\r
if(IsOpen())\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ PThread::Guard g(m_mutex);\r
m_lastresult=sqlite3_close(m_db);\r
if(m_lastresult==SQLITE_OK)\r
{\r
{\r
if(IsOpen())\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ PThread::Guard g(m_mutex);\r
m_lastresult=sqlite3_exec(m_db,sql.c_str(),NULL,NULL,NULL);\r
if(m_lastresult==SQLITE_OK)\r
{\r
{\r
if(IsOpen())\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ PThread::Guard g(m_mutex);\r
m_lastresult=sqlite3_exec(m_db,sql.c_str(),NULL,NULL,NULL);\r
if(m_lastresult==SQLITE_OK)\r
{\r
{\r
if(IsOpen())\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ PThread::Guard g(m_mutex);\r
int errcode=sqlite3_errcode(m_db);\r
const char *errmsg=sqlite3_errmsg(m_db);\r
if(errmsg)\r
\r
const bool DB::IsOpen()\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ PThread::Guard g(m_mutex);\r
return m_db ? true : false; \r
}\r
\r
}\r
if(IsOpen()==false)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ PThread::Guard g(m_mutex);\r
m_lastresult=sqlite3_open(filename.c_str(),&m_db);\r
if(m_lastresult==SQLITE_OK)\r
{\r
{\r
if(IsOpen())\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ PThread::Guard g(m_mutex);\r
sqlite3_stmt *statement=NULL;\r
m_lastresult=sqlite3_prepare_v2(m_db,sql.c_str(),sql.size(),&statement,NULL);\r
if(m_lastresult==SQLITE_OK)\r
{\r
if(IsOpen())\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ PThread::Guard g(m_mutex);\r
char **rs=NULL;\r
int rows,cols;\r
m_lastresult=sqlite3_get_table(m_db,sql.c_str(),&rs,&rows,&cols,NULL);\r
{\r
if(IsOpen())\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_mutex);\r
+ PThread::Guard g(m_mutex);\r
m_lastresult=sqlite3_busy_timeout(m_db,ms);\r
return m_lastresult;\r
}\r
+ else\r
+ {\r
+ return SQLITE_ERROR;\r
+ }\r
}\r
\r
} // namespace\r
Free();\r
m_currentrow=0;\r
\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
if(sqlite3_get_table(db->GetDB(),sql.c_str(),&m_rs,&m_rows,&m_cols,NULL)==SQLITE_OK)\r
{\r
}\r
{\r
if(Valid() && column>=0 && column<m_parametercount)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
if(sqlite3_bind_null(m_statement,column+1)==SQLITE_OK)\r
{\r
return true;\r
{\r
if(Valid() && column>=0 && column<m_parametercount)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
if(sqlite3_bind_int(m_statement,column+1,value)==SQLITE_OK)\r
{\r
return true;\r
{\r
if(Valid() && column>=0 && column<m_parametercount)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
if(sqlite3_bind_double(m_statement,column+1,value)==SQLITE_OK)\r
{\r
return true;\r
strncpy(text,value.c_str(),value.size());\r
text[value.size()]=NULL;\r
textptrs.push_back(text);\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
if(sqlite3_bind_text(m_statement,column+1,text,value.size(),NULL)==SQLITE_OK)\r
{\r
return true;\r
{\r
if(Valid() && column>=0 && column<m_parametercount)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
if(sqlite3_bind_blob(m_statement,column+1,data,length,NULL)==SQLITE_OK)\r
{\r
return true;\r
{\r
if(m_statement)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
m_statementcount[m_statement]--;\r
if(m_statementcount[m_statement]<=0)\r
{\r
\r
if(m_statement)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
m_statementcount[m_statement]++;\r
}\r
}\r
{\r
if(Valid())\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
if(sqlite3_reset(m_statement)==SQLITE_OK)\r
{\r
return true;\r
{\r
if(Valid() && column>=0 && column<m_resultcolumncount)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
data=(void *)sqlite3_column_blob(m_statement,column);\r
length=sqlite3_column_bytes(m_statement,column);\r
return true;\r
{\r
if(Valid() && column>=0 && column<m_resultcolumncount)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
result=sqlite3_column_double(m_statement,column);\r
return true;\r
}\r
{\r
if(Valid() && column>=0 && column<m_resultcolumncount)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
result=sqlite3_column_int(m_statement,column);\r
return true;\r
}\r
{\r
if(Valid() && column>=0 && column<m_resultcolumncount)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
if(sqlite3_column_type(m_statement,column)==SQLITE_NULL)\r
{\r
return true;\r
{\r
if(Valid() && column>=0 && column<m_resultcolumncount)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
const unsigned char *cresult=sqlite3_column_text(m_statement,column);\r
if(cresult)\r
{\r
m_rowreturned=false;\r
if(Valid())\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
int result=sqlite3_step(m_statement);\r
if(result==SQLITE_OK || result==SQLITE_ROW || result==SQLITE_DONE)\r
{\r
}\r
if(saveinsertrowid)\r
{\r
- m_lastinsertrowid=sqlite3_last_insert_rowid(DB::instance()->GetDB());\r
+ m_lastinsertrowid=sqlite3_last_insert_rowid(DB::Instance()->GetDB());\r
}\r
return true;\r
}\r
\r
const bool Statement::Valid()\r
{\r
- ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(DB::instance()->m_mutex);\r
+ PThread::Guard g(DB::Instance()->m_mutex);\r
return m_statement ? true : false ;\r
}\r
\r
#include "../../include/freenet/messageinserter.h"\r
#include "../../include/freenet/messagelistinserter.h"\r
\r
-#include <zthread/Thread.h>\r
+//#include <zthread/Thread.h>\r
+#include "../../include/pthreadwrapper/thread.h"\r
\r
#ifdef XMEM\r
#include <xmem.h>\r
{\r
std::string fcpport;\r
\r
- if(Option::instance()->Get("FCPHost",m_fcphost)==false)\r
+ if(Option::Instance()->Get("FCPHost",m_fcphost)==false)\r
{\r
m_fcphost="localhost";\r
- Option::instance()->Set("FCPHost",m_fcphost);\r
+ Option::Instance()->Set("FCPHost",m_fcphost);\r
}\r
- if(Option::instance()->Get("FCPPort",fcpport)==false)\r
+ if(Option::Instance()->Get("FCPPort",fcpport)==false)\r
{\r
fcpport="9481";\r
- Option::instance()->Set("FCPPort",fcpport);\r
+ Option::Instance()->Set("FCPPort",fcpport);\r
}\r
\r
// convert fcp port to long, and make sure it's within the valid port range\r
if(StringFunctions::Convert(fcpport,m_fcpport)==false)\r
{\r
m_fcpport=9481;\r
- Option::instance()->Set("FCPPort","9481");\r
+ Option::Instance()->Set("FCPPort","9481");\r
}\r
\r
m_receivednodehello=false;\r
m_processors.push_back(obj);\r
}\r
\r
-void FreenetMasterThread::run()\r
+void FreenetMasterThread::Run()\r
{\r
\r
FCPMessage message;\r
bool done=false;\r
\r
+ m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"FreenetMasterThread::run thread started.");\r
+\r
Setup();\r
\r
do\r
m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"FreenetMasterThread::run could not connect to node. Waiting 60 seconds.");\r
\r
// wait 60 seconds - will then try to connect again\r
+ /*\r
try\r
{\r
ZThread::Thread::sleep(60000);\r
{\r
done=true;\r
}\r
+ */\r
+ for(int i=0; i<60,!IsCancelled(); i++)\r
+ {\r
+ Sleep(1000);\r
+ }\r
}\r
}\r
// fcp is connected\r
}\r
\r
}\r
- }while(!ZThread::Thread::interrupted() && done==false);\r
+// }while(!ZThread::Thread::interrupted() && done==false);\r
+ }while(!IsCancelled() && done==false);\r
\r
m_fcp.Disconnect();\r
\r
// If this is the case, we will skip updating LastInsertedIdentity so that we can insert this identity again for today\r
DateTime lastdate;\r
lastdate.Set(idparts[4]);\r
- if(lastdate.GetDay()!=now.GetDay())\r
+ if(lastdate.GetDay()==now.GetDay())\r
{\r
m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";");\r
}\r
+ else\r
+ {\r
+ m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
+ }\r
m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityInserter::HandleMessage inserted Identity xml");\r
return true;\r
}\r
StringFunctions::Convert(index,indexstr);\r
\r
- Option::instance()->Get("MessageBase",messagebase);\r
+ Option::Instance()->Get("MessageBase",messagebase);\r
\r
if(rs.GetField(0))\r
{\r
void IdentityIntroductionInserter::Initialize()\r
{\r
m_inserting=false;\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
+ Option::Instance()->Get("MessageBase",m_messagebase);\r
}\r
\r
void IdentityIntroductionInserter::Process()\r
void IdentityIntroductionRequester::Initialize()\r
{\r
std::string tempval="";\r
- Option::instance()->Get("MaxIdentityIntroductionRequests",tempval);\r
+ Option::Instance()->Get("MaxIdentityIntroductionRequests",tempval);\r
StringFunctions::Convert(tempval,m_maxrequests);\r
if(m_maxrequests<1)\r
{\r
{\r
m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIdentityIntroductionRequests is currently set at "+tempval+". This value might be incorrectly configured.");\r
}\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
+ Option::Instance()->Get("MessageBase",m_messagebase);\r
m_tempdate.SetToGMTime();\r
}\r
\r
void IdentityRequester::Initialize()\r
{\r
std::string tempval="";\r
- Option::instance()->Get("MaxIdentityRequests",tempval);\r
+ Option::Instance()->Get("MaxIdentityRequests",tempval);\r
StringFunctions::Convert(tempval,m_maxrequests);\r
if(m_maxrequests<1)\r
{\r
{\r
m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIdentityRequests is currently set at "+tempval+". This value might be incorrectly configured.");\r
}\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
+ Option::Instance()->Get("MessageBase",m_messagebase);\r
m_tempdate.SetToGMTime();\r
}\r
\r
privatekey=rs2.GetField(0);\r
}\r
\r
- Option::instance()->Get("MessageBase",messagebase);\r
+ Option::Instance()->Get("MessageBase",messagebase);\r
\r
GenerateCaptcha(encodedpuzzle,solutionstring);\r
\r
void IntroductionPuzzleRequester::Initialize()\r
{\r
std::string tempval="";\r
- Option::instance()->Get("MaxIntroductionPuzzleRequests",tempval);\r
+ Option::Instance()->Get("MaxIntroductionPuzzleRequests",tempval);\r
StringFunctions::Convert(tempval,m_maxrequests);\r
if(m_maxrequests<1)\r
{\r
{\r
m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIntroductionPuzzleRequests is currently set at "+tempval+". This value might be incorrectly configured.");\r
}\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
+ Option::Instance()->Get("MessageBase",m_messagebase);\r
m_tempdate.SetToGMTime();\r
}\r
\r
\r
const bool MessageInserter::HandlePutSuccessful(FCPMessage &message)\r
{\r
+ DateTime date;\r
+ int localidentityid;\r
int index;\r
std::vector<std::string> idparts;\r
StringFunctions::Split(message["Identifier"],"|",idparts);\r
StringFunctions::Convert(idparts[3],index);\r
+ StringFunctions::Convert(idparts[2],localidentityid);\r
\r
SQLite3DB::Statement st=m_db->Prepare("UPDATE tblMessageInserts SET Day=?, InsertIndex=?, Inserted='true' WHERE MessageUUID=?;");\r
st.Bind(0,idparts[5]);\r
st.Bind(2,idparts[1]);\r
st.Step();\r
\r
+ // insert record into temp table so MessageList will be inserted ASAP\r
+ date.SetToGMTime();\r
+ st=m_db->Prepare("INSERT INTO tmpMessageListInsert(LocalIdentityID,Date) VALUES(?,?);");\r
+ st.Bind(0,localidentityid);\r
+ st.Bind(1,date.Format("%Y-%m-%d"));\r
+ st.Step();\r
+\r
RemoveFromInsertList(idparts[1]);\r
\r
m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]);\r
// only do 1 insert at a time\r
if(m_inserting.size()==0)\r
{\r
+ std::string sql;\r
DateTime now;\r
DateTime previous;\r
\r
\r
previous.Add(0,0,0,-m_daysbackward);\r
\r
- // query for identities that have messages in the past X days and we haven't inserted lists for in the past 30 minutes\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT tblLocalIdentity.LocalIdentityID FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID WHERE tblMessageInserts.Day>=? AND (tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='');");\r
+ // query for identities that have messages in the past X days and (we haven't inserted lists for in the past 30 minutes OR identity has a record in tmpMessageListInsert)\r
+ sql="SELECT tblLocalIdentity.LocalIdentityID ";\r
+ sql+="FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID ";\r
+ sql+="WHERE tblMessageInserts.Day>=? AND ((tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='') OR tblLocalIdentity.LocalIdentityID IN (SELECT LocalIdentityID FROM tmpMessageListInsert)) ";\r
+ sql+=";";\r
+\r
+ SQLite3DB::Statement st=m_db->Prepare(sql);\r
st.Bind(0,previous.Format("%Y-%m-%d"));\r
st.Bind(1,(now-(1.0/48.0)).Format("%Y-%m-%d %H:%M:%S"));\r
st.Step();\r
st.Bind(1,localidentityid);\r
st.Step();\r
\r
+ // delete any record from tmpMessageListInsert\r
+ st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE LocalIdentityID=?;");\r
+ st.Bind(0,localidentityid);\r
+ st.Step();\r
+\r
RemoveFromInsertList(localidentityid);\r
\r
+ m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList.");\r
+\r
return true;\r
}\r
\r
\r
m_fcpuniquename="MessageListInserter";\r
m_daysbackward=0;\r
- Option::instance()->Get("MessageListDaysBackward",tempval);\r
+ Option::Instance()->Get("MessageListDaysBackward",tempval);\r
StringFunctions::Convert(tempval,m_daysbackward);\r
}\r
\r
{\r
m_fcpuniquename="MessageListRequester";\r
std::string tempval;\r
- Option::instance()->Get("MaxMessageListRequests",tempval);\r
+ Option::Instance()->Get("MaxMessageListRequests",tempval);\r
StringFunctions::Convert(tempval,m_maxrequests);\r
if(m_maxrequests<1)\r
{\r
{\r
m_fcpuniquename="MessageRequester";\r
std::string tempval;\r
- Option::instance()->Get("MaxMessageRequests",tempval);\r
+ Option::Instance()->Get("MaxMessageRequests",tempval);\r
StringFunctions::Convert(tempval,m_maxrequests);\r
if(m_maxrequests<1)\r
{\r
{\r
m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxMessageRequests is currently set at "+tempval+". This value might be incorrectly configured.");\r
}\r
- Option::instance()->Get("MessageDownloadMaxDaysBackward",tempval);\r
+ Option::Instance()->Get("MessageDownloadMaxDaysBackward",tempval);\r
StringFunctions::Convert(tempval,m_maxdaysbackward);\r
if(m_maxdaysbackward<0)\r
{\r
std::string val1;\r
std::string val2;\r
std::string val3;\r
+ std::string sql;\r
\r
date.SetToGMTime();\r
date.Add(0,0,0,-m_maxdaysbackward);\r
\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentity.IdentityID,Day,RequestIndex FROM tblMessageRequests INNER JOIN tblIdentity ON tblMessageRequests.IdentityID=tblIdentity.IdentityID WHERE tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust') AND FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"';");\r
+ sql="SELECT tblIdentity.IdentityID,Day,RequestIndex ";\r
+ sql+="FROM tblMessageRequests INNER JOIN tblIdentity ON tblMessageRequests.IdentityID=tblIdentity.IdentityID ";\r
+ sql+="WHERE tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust') AND FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"' ";\r
+ sql+="AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) ";\r
+ sql+=";";\r
+\r
+ SQLite3DB::Statement st=m_db->Prepare(sql);\r
st.Step();\r
\r
while(st.RowReturned())\r
\r
m_ids[requestid]=true;\r
\r
-}
\ No newline at end of file
+}\r
\r
void TrustListInserter::Initialize()\r
{\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
+ Option::Instance()->Get("MessageBase",m_messagebase);\r
m_lastchecked.SetToGMTime();\r
}\r
\r
void TrustListRequester::Initialize()\r
{\r
std::string tempval="";\r
- Option::instance()->Get("MaxIdentityRequests",tempval);\r
+ Option::Instance()->Get("MaxIdentityRequests",tempval);\r
StringFunctions::Convert(tempval,m_maxrequests);\r
if(m_maxrequests<1)\r
{\r
{\r
m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxTrustListRequests is currently set at "+tempval+". This value might be incorrectly configured.");\r
}\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
+ Option::Instance()->Get("MessageBase",m_messagebase);\r
m_tempdate.SetToGMTime();\r
}\r
\r
{\r
DateTime date;\r
int id;\r
+ std::string sql;\r
\r
date.SetToGMTime();\r
\r
// select identities we want to query (we've seen them today and they are publishing trust list) - sort by their trust level (descending) with secondary sort on how long ago we saw them (ascending)\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+date.Format("%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;");\r
+ sql="SELECT IdentityID FROM tblIdentity ";\r
+ sql+="WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+date.Format("%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') )";\r
+ sql+="ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;";\r
+\r
+ SQLite3DB::Statement st=m_db->Prepare(sql);\r
st.Step();\r
\r
m_ids.clear();\r
{\r
\r
DateTime date;\r
- SQLite3DB::DB *db=SQLite3DB::DB::instance();\r
+ SQLite3DB::DB *db=SQLite3DB::DB::Instance();\r
\r
db->Open("fms.db3");\r
db->SetBusyTimeout(10000); // set timeout to 10 seconds\r
\r
db->Execute("CREATE TABLE IF NOT EXISTS tblIdentity(\\r
IdentityID INTEGER PRIMARY KEY,\\r
- PublicKey TEXT,\\r
+ PublicKey TEXT UNIQUE,\\r
Name TEXT,\\r
SingleUse BOOL CHECK(SingleUse IN('true','false')) DEFAULT 'false',\\r
PublishTrustList BOOL CHECK(PublishTrustList IN('true','false')) DEFAULT 'false',\\r
\r
db->Execute("CREATE TABLE IF NOT EXISTS tblMessageReplyTo(\\r
MessageID INTEGER,\\r
- ReplyToMessageUUID INTEGER,\\r
+ ReplyToMessageUUID TEXT,\\r
ReplyOrder INTEGER\\r
);");\r
\r
Inserted BOOL CHECK(Inserted IN('true','false')) DEFAULT 'false'\\r
);");\r
\r
+ // MessageInserter will insert a record into this temp table which the MessageListInserter will query for and insert a MessageList when needed\r
+ db->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS tmpMessageListInsert(\\r
+ LocalIdentityID INTEGER,\\r
+ Date DATETIME\\r
+ );");\r
+\r
// low / high / message count for each board\r
- db->Execute("CREATE VIEW IF NOT EXISTS vwBoardStats AS \\r
+ db->Execute("DROP VIEW IF EXISTS vwBoardStats; \\r
+ CREATE VIEW IF NOT EXISTS vwBoardStats AS \\r
SELECT tblBoard.BoardID AS 'BoardID', IFNULL(MIN(MessageID),0) AS 'LowMessageID', IFNULL(MAX(MessageID),0) AS 'HighMessageID', COUNT(MessageID) AS 'MessageCount' \\r
FROM tblBoard LEFT JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID \\r
- WHERE MessageID>=0 \\r
+ WHERE MessageID>=0 OR MessageID IS NULL \\r
GROUP BY tblBoard.BoardID;");\r
\r
// calculates peer trust\r
- db->Execute("CREATE VIEW IF NOT EXISTS vwCalculatedPeerTrust AS \\r
+ db->Execute("DROP VIEW IF EXISTS vwCalculatedPeerTrust; \\r
+ CREATE VIEW IF NOT EXISTS vwCalculatedPeerTrust AS \\r
SELECT TargetIdentityID, \\r
ROUND(SUM(MessageTrust*(LocalMessageTrust/100.0))/SUM(LocalMessageTrust/100.0),0) AS 'PeerMessageTrust', \\r
ROUND(SUM(TrustListTrust*(LocalTrustListTrust/100.0))/SUM(LocalTrustListTrust/100.0),0) AS 'PeerTrustListTrust' \\r
FROM tblPeerTrust INNER JOIN tblIdentity ON tblPeerTrust.IdentityID=tblIdentity.IdentityID \\r
WHERE LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') \\r
+ AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') ) \\r
GROUP BY TargetIdentityID;");\r
\r
// update PeerTrustLevel when deleting a record from tblPeerTrust\r
db->Execute("DELETE FROM tblIntroductionPuzzleInserts WHERE Day<='"+date.Format("%Y-%m-%d")+"';");\r
db->Execute("DELETE FROM tblIntroductionPuzzleRequests WHERE Day<='"+date.Format("%Y-%m-%d")+"';");\r
\r
+ // insert SomeDude's public key\r
+ date.SetToGMTime();\r
+// db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw,iXez4j3qCpd596TxXiJgZyTq9o-CElEuJxm~jNNZAuA,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');");\r
+\r
}\r
\r
void SetupDefaultOptions()\r
// OptionValue should always be inserted as a string, even if the option really isn't a string - just to keep the field data type consistent\r
\r
std::ostringstream tempstr; // must set tempstr to "" between db inserts\r
- SQLite3DB::DB *db=SQLite3DB::DB::instance();\r
+ SQLite3DB::DB *db=SQLite3DB::DB::Instance();\r
SQLite3DB::Statement st=db->Prepare("INSERT INTO tblOption(Option,OptionValue,OptionDescription) VALUES(?,?,?);");\r
\r
// LogLevel\r
st.Step();\r
st.Reset();\r
\r
+ st.Bind(0,"MinPeerMessageTrust");\r
+ st.Bind(1,"25");\r
+ st.Bind(2,"Specifies a peer message trust level that a peer must have before its messages will be downloaded.");\r
+ st.Step();\r
+ st.Reset();\r
+\r
st.Bind(0,"MinLocalTrustListTrust");\r
st.Bind(1,"50");\r
st.Bind(2,"Specifies a local trust list trust level that a peer must have before its trust list will be included in the weighted average. Any peers below this number will be excluded from the results.");\r
st.Step();\r
st.Reset();\r
\r
+ st.Bind(0,"MinPeerTrustListTrust");\r
+ st.Bind(1,"25");\r
+ st.Bind(2,"Specifies a peer trust list trust level that a peer must have before its trust list will be included in the weighted average. Any peers below this number will be excluded from the results.");\r
+ st.Step();\r
+ st.Reset();\r
+\r
st.Bind(0,"MessageDownloadMaxDaysBackward");\r
st.Bind(1,"3");\r
st.Bind(2,"The maximum number of days backward that messages will be downloaded from each identity");\r
\r
date.SetToGMTime();\r
\r
- LogFile::instance()->SetFileName("fms-"+date.Format("%Y-%m-%d")+".log");\r
- LogFile::instance()->OpenFile();\r
- LogFile::instance()->SetWriteNewLine(true);\r
- LogFile::instance()->SetWriteDate(true);\r
- LogFile::instance()->SetWriteLogLevel(true);\r
+ LogFile::Instance()->SetFileName("fms-"+date.Format("%Y-%m-%d")+".log");\r
+ LogFile::Instance()->OpenFile();\r
+ LogFile::Instance()->SetWriteNewLine(true);\r
+ LogFile::Instance()->SetWriteDate(true);\r
+ LogFile::Instance()->SetWriteLogLevel(true);\r
\r
- if(Option::instance()->Get("LogLevel",configval)==false)\r
+ if(Option::Instance()->Get("LogLevel",configval)==false)\r
{\r
configval="4";\r
- Option::instance()->Set("LogLevel",configval);\r
+ Option::Instance()->Set("LogLevel",configval);\r
}\r
if(StringFunctions::Convert(configval,loglevel)==false)\r
{\r
loglevel=LogFile::LOGLEVEL_DEBUG;\r
- Option::instance()->Set("LogLevel",loglevel);\r
+ Option::Instance()->Set("LogLevel",loglevel);\r
}\r
- LogFile::instance()->SetLogLevel((LogFile::LogLevel)loglevel);\r
+ LogFile::Instance()->SetLogLevel((LogFile::LogLevel)loglevel);\r
}\r
\r
void SetupNetwork()\r
#endif\r
}\r
\r
-void ShutdownThreads(std::vector<ZThread::Thread *> &threads)\r
+void ShutdownThreads(std::vector<PThread::Thread *> &threads)\r
{\r
- std::vector<ZThread::Thread *>::iterator i;\r
+ std::vector<PThread::Thread *>::iterator i;\r
for(i=threads.begin(); i!=threads.end(); i++)\r
{\r
- if((*i)->wait(1)==false)\r
+/* if((*i)->wait(1)==false)\r
{\r
try\r
{\r
{\r
}\r
}\r
+ */\r
+ (*i)->Cancel();\r
}\r
\r
for(i=threads.begin(); i!=threads.end(); i++)\r
{\r
- LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ShutdownThreads waiting for thread to exit.");\r
- (*i)->wait();\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"ShutdownThreads waiting for thread to exit.");\r
+ //(*i)->wait();\r
+ (*i)->Join();\r
delete (*i);\r
}\r
\r
\r
}\r
\r
-void StartThreads(std::vector<ZThread::Thread *> &threads)\r
+void StartThreads(std::vector<PThread::Thread *> &threads)\r
{\r
std::string startfreenet;\r
std::string startnntp;\r
\r
- if(Option::instance()->Get("StartFreenetUpdater",startfreenet)==false)\r
+ if(Option::Instance()->Get("StartFreenetUpdater",startfreenet)==false)\r
{\r
startfreenet="true";\r
- Option::instance()->Set("StartFreenetUpdater","true");\r
+ Option::Instance()->Set("StartFreenetUpdater","true");\r
}\r
\r
- if(Option::instance()->Get("StartNNTP",startnntp)==false)\r
+ if(Option::Instance()->Get("StartNNTP",startnntp)==false)\r
{\r
startnntp="true";\r
- Option::instance()->Set("StartNNTP","true");\r
+ Option::Instance()->Set("StartNNTP","true");\r
}\r
\r
if(startfreenet=="true")\r
{\r
- ZThread::Thread *t=new ZThread::Thread(new FreenetMasterThread());\r
+ PThread::Thread *t=new PThread::Thread(new FreenetMasterThread());\r
threads.push_back(t);\r
}\r
\r
if(startnntp=="true")\r
{\r
- ZThread::Thread *t=new ZThread::Thread(new NNTPListener());\r
+ PThread::Thread *t=new PThread::Thread(new NNTPListener());\r
threads.push_back(t);\r
}\r
\r
\r
bool LogFile::CloseFile()\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ PThread::Guard g(m_logmutex);\r
\r
if(m_fileptr)\r
{\r
{\r
CloseFile();\r
\r
- ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ PThread::Guard g(m_logmutex);\r
\r
m_fileptr=fopen(m_filename.c_str(),"a+b");\r
\r
\r
if(m_fileptr)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ PThread::Guard g(m_logmutex);\r
if(m_writedate)\r
{\r
WriteDate();\r
\r
if(m_fileptr)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ PThread::Guard g(m_logmutex);\r
if(m_writedate)\r
{\r
WriteDate(); \r
\r
if(m_fileptr)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ PThread::Guard g(m_logmutex);\r
if(m_writedate)\r
{\r
WriteDate(); \r
\r
if(m_fileptr)\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ PThread::Guard g(m_logmutex);\r
if(m_writedate)\r
{\r
WriteDate(); \r
\r
void LogFile::WriteNewLine()\r
{\r
- ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ //ZThread::Guard<ZThread::Mutex> g(m_logmutex);\r
+ PThread::Guard g(m_logmutex);\r
\r
if(m_fileptr)\r
{\r
xmem_disable_print();\r
#endif\r
\r
- std::vector<ZThread::Thread *> threads;\r
+ std::vector<PThread::Thread *> threads;\r
\r
srand(time(NULL));\r
\r
\r
SetupNetwork();\r
\r
- LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS startup v"FMS_VERSION);\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS startup v"FMS_VERSION);\r
\r
\r
StartThreads(threads);\r
\r
\r
- ZThread::Thread commandthread(new CommandThread());\r
- commandthread.wait();\r
+ //ZThread::Thread commandthread(new CommandThread());\r
+ PThread::Thread commandthread(new CommandThread());\r
+ commandthread.Join();\r
\r
\r
ShutdownThreads(threads);\r
\r
ShutdownNetwork();\r
\r
- LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS shutdown");\r
- LogFile::instance()->WriteNewLine();\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS shutdown");\r
+ LogFile::Instance()->WriteNewLine();\r
\r
return 0;\r
}\r
\r
const bool Message::LoadNext(const long messageid, const long boardid)\r
{\r
- std::string sql="SELECT MessageID FROM tblMessage WHERE MessageID>?";\r
+ std::string sql="SELECT tblMessage.MessageID FROM tblMessage INNER JOIN tblMessageBoard ON tblMessage.MessageID=tblMessageBoard.MessageID WHERE tblMessage.MessageID>?";\r
if(boardid!=-1)\r
{\r
- sql+=" AND BoardID=?";\r
+ sql+=" AND tblMessageBoard.BoardID=?";\r
}\r
sql+=";";\r
\r
\r
const bool Message::LoadPrevious(const long messageid, const long boardid)\r
{\r
- std::string sql="SELECT MessageID FROM tblMessage WHERE MessageID<?";\r
+ std::string sql="SELECT tblMessage.MessageID FROM tblMessage INNER JOIN tblMessageBoard ON tblMessage.MessageID=tblMessageBoard.MessageID WHERE tblMessage.MessageID<?";\r
if(boardid!=-1)\r
{\r
- sql+=" AND BoardID=?";\r
+ sql+=" AND tblMessageBoard.BoardID=?";\r
}\r
- sql+=";";\r
+ sql+=" ORDER BY tblMessage.MessageID DESC;";\r
\r
SQLite3DB::Statement st=m_db->Prepare(sql);\r
\r
#include "../../include/messagelist.h"\r
#include "../../include/option.h"\r
\r
-#include <zthread/Thread.h>\r
+#include <algorithm>\r
+\r
+//#include <zthread/Thread.h>\r
+#include "../../include/pthreadwrapper/thread.h"\r
\r
#ifdef XMEM\r
#include <xmem.h>\r
m_status.m_messageid=-1;\r
m_status.m_mode=MODE_NONE;\r
\r
- Option::instance()->Get("NNTPAllowPost",tempval);\r
+ Option::Instance()->Get("NNTPAllowPost",tempval);\r
if(tempval=="true")\r
{\r
m_status.m_allowpost=true;\r
{\r
Message mess;\r
\r
- if(mess.Load(m_status.m_messageid,m_status.m_boardid))\r
+ if(mess.LoadPrevious(m_status.m_messageid,m_status.m_boardid))\r
{\r
std::ostringstream tempstr;\r
\r
{\r
Message mess;\r
\r
- if(mess.Load(m_status.m_messageid,m_status.m_boardid))\r
+ if(mess.LoadNext(m_status.m_messageid,m_status.m_boardid))\r
{\r
std::ostringstream tempstr;\r
\r
return true;\r
}\r
\r
-void NNTPConnection::run()\r
+void NNTPConnection::Run()\r
{\r
struct timeval tv;\r
fd_set writefs,readfs;\r
SocketSend();\r
}\r
}\r
- else if(rval==-1)\r
+ else if(rval==SOCKET_ERROR)\r
{\r
m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::run select returned -1 : "+GetSocketErrorMessage()); \r
}\r
\r
- }while(!Disconnected() && !ZThread::Thread::interrupted());\r
- \r
+// }while(!Disconnected() && !ZThread::Thread::interrupted());\r
+ }while(!Disconnected() && !IsCancelled());\r
+\r
Disconnect();\r
- \r
+\r
}\r
\r
void NNTPConnection::SendArticleOverInfo(Message &message)\r
\r
}\r
\r
-void NNTPListener::run()\r
+void NNTPListener::Run()\r
{\r
int rval;\r
fd_set readfs;\r
std::vector<SOCKET>::iterator listeni;\r
SOCKET highsocket;\r
\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run thread started.");\r
+\r
StartListen();\r
\r
do\r
{\r
SOCKET newsock;\r
struct sockaddr_storage addr;\r
- int addrlen=sizeof(addr);\r
+ socklen_t addrlen=sizeof(addr);\r
newsock=accept((*listeni),(struct sockaddr *)&addr,&addrlen);\r
- LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::run NNTP client connected");\r
- m_connections.execute(new NNTPConnection(newsock));\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::run NNTP client connected");\r
+ //m_connections.execute(new NNTPConnection(newsock));\r
+ m_connectionthreads.push_back(new PThread::Thread(new NNTPConnection(newsock)));\r
}\r
}\r
}\r
\r
- }while(!ZThread::Thread::interrupted() && m_listensockets.size()>0);\r
+ // check for any non-running connection threads that we can delete\r
+ for(std::vector<PThread::Thread *>::iterator i=m_connectionthreads.begin(); i!=m_connectionthreads.end(); )\r
+ {\r
+ if((*i)->IsRunning()==false)\r
+ {\r
+ delete (*i);\r
+ i=m_connectionthreads.erase(i);\r
+ }\r
+ if(i!=m_connectionthreads.end())\r
+ {\r
+ i++;\r
+ }\r
+ }\r
+\r
+ //}while(!ZThread::Thread::interrupted() && m_listensockets.size()>0);\r
+ }while(!IsCancelled() && m_listensockets.size()>0);\r
\r
// see if any threads are still running - just calling interrupt without check would cause assert in debug mode\r
+ /*\r
if(m_connections.wait(1)==false)\r
{\r
LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run interrupting connection threads and waiting 60 seconds for exit.");\r
{\r
LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run caught unhandled exception.");\r
}\r
- if(m_connections.wait(60)==false)\r
+ if(m_connections.wait(60000)==false)\r
{\r
LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run connection threads did not exit after 60 seconds.");\r
}\r
}\r
+ */\r
+ for(std::vector<PThread::Thread *>::iterator i=m_connectionthreads.begin(); i!=m_connectionthreads.end(); i++)\r
+ {\r
+ if((*i)->IsRunning())\r
+ {\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::Run waiting for connection thread to exit.");\r
+ (*i)->Cancel();\r
+ (*i)->Join();\r
+ }\r
+ delete (*i);\r
+ }\r
\r
for(listeni=m_listensockets.begin(); listeni!=m_listensockets.end(); listeni++)\r
{\r
std::string bindaddresses;\r
std::vector<std::string> listenaddresses;\r
std::string nntpport;\r
- if(Option::instance()->Get("NNTPListenPort",nntpport)==false)\r
+ if(Option::Instance()->Get("NNTPListenPort",nntpport)==false)\r
{\r
nntpport="1119";\r
- Option::instance()->Set("NNTPListenPort",nntpport);\r
+ Option::Instance()->Set("NNTPListenPort",nntpport);\r
}\r
- if(Option::instance()->Get("NNTPBindAddresses",bindaddresses)==false)\r
+ if(Option::Instance()->Get("NNTPBindAddresses",bindaddresses)==false)\r
{\r
bindaddresses="127.0.0.1";\r
- Option::instance()->Set("NNTPBindAddresses",bindaddresses);\r
+ Option::Instance()->Set("NNTPBindAddresses",bindaddresses);\r
}\r
StringFunctions::Split(bindaddresses,",",listenaddresses);\r
\r
{\r
if(listen(sock,10)==0)\r
{\r
- LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::StartListen started listening at "+(*i)+":"+nntpport);\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::StartListen started listening at "+(*i)+":"+nntpport);\r
m_listensockets.push_back(sock);\r
}\r
else\r
{\r
- LogFile::instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket listen failed");\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket listen failed");\r
#ifdef _WIN32\r
closesocket(sock);\r
#else\r
}\r
else\r
{\r
- LogFile::instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket bind failed");\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket bind failed");\r
#ifdef _WIN32\r
closesocket(sock);\r
#else\r
}\r
else\r
{\r
- LogFile::instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen couldn't create socket");\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen couldn't create socket");\r
}\r
}\r
}\r
}\r
if(m_listensockets.size()==0)\r
{\r
- LogFile::instance()->WriteLog(LogFile::LOGLEVEL_FATAL,"NNTPListener::StartListen couldn't start listening on any sockets");\r
+ LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_FATAL,"NNTPListener::StartListen couldn't start listening on any sockets");\r
}\r
}\r
\r
const bool Option::Get(const std::string &option, std::string &value)\r
{\r
- SQLite3DB::Statement st=SQLite3DB::DB::instance()->Prepare("SELECT OptionValue FROM tblOption WHERE Option=?;");\r
+ SQLite3DB::Statement st=SQLite3DB::DB::Instance()->Prepare("SELECT OptionValue FROM tblOption WHERE Option=?;");\r
st.Bind(0,option);\r
st.Step();\r
if(st.RowReturned())\r
--- /dev/null
+#include "../../include/pthreadwrapper/guard.h"\r
+#include "../../include/pthreadwrapper/mutex.h"\r
+\r
+#ifdef XMEM\r
+ #include <xmem.h>\r
+#endif\r
+\r
+namespace PThread\r
+{\r
+\r
+Guard::Guard()\r
+{\r
+ m_mutex=0;\r
+}\r
+\r
+Guard::Guard(Mutex &mutex)\r
+{\r
+ m_mutex=&mutex;\r
+ m_mutex->Acquire(); \r
+}\r
+\r
+Guard::~Guard()\r
+{\r
+ if(m_mutex)\r
+ {\r
+ m_mutex->Release(); \r
+ }\r
+}\r
+\r
+} // namespace\r
--- /dev/null
+#include "../../include/pthreadwrapper/mutex.h"\r
+#include <exception>\r
+\r
+#ifdef XMEM\r
+ #include <xmem.h>\r
+#endif\r
+\r
+namespace PThread\r
+{\r
+\r
+Mutex::Mutex()\r
+{\r
+ pthread_mutexattr_init(&m_attr);\r
+ pthread_mutexattr_settype(&m_attr,PTHREAD_MUTEX_ERRORCHECK);\r
+ pthread_mutex_init(&m_mutex,&m_attr);\r
+}\r
+\r
+Mutex::~Mutex()\r
+{\r
+ pthread_mutex_destroy(&m_mutex);\r
+ pthread_mutexattr_destroy(&m_attr);\r
+}\r
+\r
+void Mutex::Acquire() throw(std::exception)\r
+{\r
+ int rval=0;\r
+ if((rval=pthread_mutex_lock(&m_mutex))!=0)\r
+ {\r
+ // deadlock - throw exception\r
+ if(rval==EDEADLK)\r
+ {\r
+ throw std::exception("Mutex would deadlock!");\r
+ }\r
+ }\r
+}\r
+\r
+void Mutex::Release()\r
+{\r
+ pthread_mutex_unlock(&m_mutex);\r
+}\r
+\r
+} // namespace\r
--- /dev/null
+#include "../../include/pthreadwrapper/runnable.h"\r
+\r
+#ifdef XMEM\r
+ #include <xmem.h>\r
+#endif\r
+\r
+namespace PThread\r
+{\r
+\r
+const bool Runnable::IsCancelled()\r
+{\r
+ if(m_thread)\r
+ {\r
+ return m_thread->IsCancelled();\r
+ }\r
+ else\r
+ {\r
+ return false;\r
+ }\r
+}\r
+\r
+void Runnable::Sleep(const long ms)\r
+{\r
+ if(m_thread)\r
+ {\r
+ m_thread->Sleep(ms);\r
+ }\r
+}\r
+\r
+} // namespace\r
--- /dev/null
+#include "../../include/pthreadwrapper/thread.h"\r
+\r
+#include <sys/timeb.h>\r
+\r
+#ifdef XMEM\r
+ #include <xmem.h>\r
+#endif\r
+\r
+namespace PThread\r
+{\r
+\r
+Thread::Thread()\r
+{\r
+ m_running=false;\r
+ m_cancelled=false;\r
+ m_runnable=0;\r
+}\r
+\r
+Thread::Thread(Runnable *runnable)\r
+{\r
+ m_running=false;\r
+ m_cancelled=false;\r
+ m_runnable=runnable;\r
+ if(m_runnable)\r
+ {\r
+ m_runnable->m_thread=this;\r
+ Start();\r
+ }\r
+}\r
+\r
+Thread::~Thread()\r
+{\r
+ Cancel();\r
+ Join();\r
+ if(m_runnable)\r
+ {\r
+ delete m_runnable;\r
+ }\r
+}\r
+\r
+void Thread::Cancel()\r
+{\r
+ if(m_running)\r
+ {\r
+ m_cancelled=true;\r
+ }\r
+}\r
+\r
+void *Thread::EntryPoint(void *pthis)\r
+{\r
+ if(pthis)\r
+ {\r
+ ((Thread *)pthis)->m_runnable->Run();\r
+ ((Thread *)pthis)->m_running=false;\r
+ ((Thread *)pthis)->m_cancelled=false;\r
+ }\r
+ return NULL;\r
+}\r
+\r
+void Thread::Join()\r
+{\r
+ if(m_running)\r
+ {\r
+ pthread_join(m_thread,NULL);\r
+ }\r
+}\r
+\r
+void Thread::Sleep(const long ms)\r
+{\r
+ if(m_running)\r
+ {\r
+ pthread_cond_t c;\r
+ pthread_mutex_t m;\r
+ timespec t;\r
+ timeb tb;\r
+\r
+ pthread_mutex_init(&m,NULL);\r
+ pthread_cond_init(&c,NULL);\r
+\r
+ ftime(&tb);\r
+\r
+ t.tv_sec=tb.time+(ms/1000);\r
+ t.tv_nsec=((1000000L)*(long)tb.millitm)+((1000000L)*(ms%1000));\r
+\r
+ pthread_mutex_lock(&m);\r
+ pthread_cond_timedwait(&c,&m,&t);\r
+ pthread_mutex_unlock(&m);\r
+ }\r
+}\r
+\r
+void Thread::Start()\r
+{\r
+ m_running=true;\r
+ pthread_create(&m_thread,NULL,Thread::EntryPoint,this);\r
+}\r
+\r
+} // namespace\r
+++ /dev/null
-diff -ru ZThread-2.3.2-old/include/zthread/Guard.h ZThread-2.3.2/include/zthread/Guard.h
---- ZThread-2.3.2-old/include/zthread/Guard.h 2005-03-12 21:10:09.000000000 -0500
-+++ ZThread-2.3.2/include/zthread/Guard.h 2006-09-10 14:10:08.000000000 -0400
-@@ -491,7 +491,7 @@
-
- try {
-
-- if(!isDisabled())
-+ if(!LockHolder<LockType>::isDisabled())
- LockingPolicy::destroyScope(*this);
-
- } catch (...) { /* ignore */ }
-diff -ru ZThread-2.3.2-old/src/MutexImpl.h ZThread-2.3.2/src/MutexImpl.h
---- ZThread-2.3.2-old/src/MutexImpl.h 2005-03-12 22:59:15.000000000 -0500
-+++ ZThread-2.3.2/src/MutexImpl.h 2006-09-10 14:13:31.000000000 -0400
-@@ -153,7 +153,7 @@
-
- _owner = self;
-
-- ownerAcquired(self);
-+ Behavior::ownerAcquired(self);
-
- }
-
-@@ -164,7 +164,7 @@
- _waiters.insert(self);
- m.acquire();
-
-- waiterArrived(self);
-+ Behavior::waiterArrived(self);
-
- {
-
-@@ -173,7 +173,7 @@
-
- }
-
-- waiterDeparted(self);
-+ Behavior::waiterDeparted(self);
-
- m.release();
-
-@@ -192,7 +192,7 @@
- assert(_owner == 0);
- _owner = self;
-
-- ownerAcquired(self);
-+ Behavior::ownerAcquired(self);
-
- break;
-
-@@ -236,7 +236,7 @@
-
- _owner = self;
-
-- ownerAcquired(self);
-+ Behavior::ownerAcquired(self);
-
- }
-
-@@ -253,7 +253,7 @@
-
- m.acquire();
-
-- waiterArrived(self);
-+ Behavior::waiterArrived(self);
-
- {
-
-@@ -262,7 +262,7 @@
-
- }
-
-- waiterDeparted(self);
-+ Behavior::waiterDeparted(self);
-
- m.release();
-
-@@ -284,7 +284,7 @@
- assert(0 == _owner);
- _owner = self;
-
-- ownerAcquired(self);
-+ Behavior::ownerAcquired(self);
-
- break;
-
-@@ -326,7 +326,7 @@
-
- _owner = 0;
-
-- ownerReleased(impl);
-+ Behavior::ownerReleased(impl);
-
- // Try to find a waiter with a backoff & retry scheme
- for(;;) {