Author: tschoening Date: Mon Feb 10 14:17:26 2014 New Revision: 1566630 URL: http://svn.apache.org/r1566630 Log: LOGCXX-337: Suggested fix for socketappender not reconnecting multiple times
Modified: incubator/log4cxx/trunk/src/changes/changes.xml incubator/log4cxx/trunk/src/main/cpp/socketappenderskeleton.cpp incubator/log4cxx/trunk/src/main/cpp/threadcxx.cpp Modified: incubator/log4cxx/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/changes/changes.xml?rev=1566630&r1=1566629&r2=1566630&view=diff ============================================================================== --- incubator/log4cxx/trunk/src/changes/changes.xml (original) +++ incubator/log4cxx/trunk/src/changes/changes.xml Mon Feb 10 14:17:26 2014 @@ -59,6 +59,7 @@ <action issue="LOGCXX-319" type="fix">Please make sure that the LOG4CXX_* macro's can be used as ordinary statements.</action> <action issue="LOGCXX-331" type="fix">DailyRollingFileAppender should roll if program doesn't run at rolling time</action> <action issue="LOGCXX-336" type="fix">Test compilation fails: Overloading ambiguity</action> + <action issue="LOGCXX-337" type="fix">Suggested fix for socketappender not reconnecting multiple times</action> <action issue="LOGCXX-340" type="fix">Transcoder::encodeCharsetName bungles encoding</action> <action issue="LOGCXX-351" type="fix">Download page does not have link to KEYS file</action> <action issue="LOGCXX-353" type="fix">When a client disconnects the SocketHubAppender crashes on the next log message</action> Modified: incubator/log4cxx/trunk/src/main/cpp/socketappenderskeleton.cpp URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/cpp/socketappenderskeleton.cpp?rev=1566630&r1=1566629&r2=1566630&view=diff ============================================================================== --- incubator/log4cxx/trunk/src/main/cpp/socketappenderskeleton.cpp (original) +++ incubator/log4cxx/trunk/src/main/cpp/socketappenderskeleton.cpp Mon Feb 10 14:17:26 2014 @@ -28,7 +28,6 @@ #include <log4cxx/helpers/transcoder.h> #include <log4cxx/helpers/bytearrayoutputstream.h> - using namespace log4cxx; using namespace log4cxx::helpers; using namespace log4cxx::net; @@ -135,8 +134,13 @@ void SocketAppenderSkeleton::setOption(c void SocketAppenderSkeleton::fireConnector() { synchronized sync(mutex); - if (!thread.isActive()) { - thread.run(monitor, this); + if ( !thread.isAlive() ) { + LogLog::debug(LOG4CXX_STR("Connector thread not alive: starting monitor.")); + try { + thread.run(monitor, this); + } catch( ThreadException& te ) { + LogLog::error(LOG4CXX_STR("Monitor not started: "), te); + } } } Modified: incubator/log4cxx/trunk/src/main/cpp/threadcxx.cpp URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/cpp/threadcxx.cpp?rev=1566630&r1=1566629&r2=1566630&view=diff ============================================================================== --- incubator/log4cxx/trunk/src/main/cpp/threadcxx.cpp (original) +++ incubator/log4cxx/trunk/src/main/cpp/threadcxx.cpp Mon Feb 10 14:17:26 2014 @@ -149,6 +149,11 @@ Thread::~Thread() { void Thread::run(Runnable start, void* data) { #if APR_HAS_THREADS + // Try to join first if previous instance did exit + if ( isActive() && !isAlive() ) { + join(); + } + // now we're ready to create the thread again // // if attempting a second run method on the same Thread object // throw an exception @@ -179,19 +184,24 @@ void Thread::run(Runnable start, void* d if (stat != APR_SUCCESS) { throw ThreadException(stat); } + // we need to set alive here already, since we use isAlive() to check + // if run() has been called in a thread-safe way. + apr_atomic_set32(&alive, 0xFFFFFFFF); #else throw ThreadException(LOG4CXX_STR("APR_HAS_THREADS is not true")); #endif + LaunchPackage* package = (LaunchPackage*) data; + ThreadLocal& tls = getThreadLocal(); + tls.set(package->getThread()); + { + (package->getRunnable())(thread, package->getData()); + package->getThread()->ending(); + } + apr_thread_exit(thread, 0); // this function never returns ! + return 0; } +#endif - - - -void Thread::join() { -#if APR_HAS_THREADS - if (thread != NULL) { - apr_status_t startStat; - apr_status_t stat = apr_thread_join(&startStat, thread); thread = NULL; if (stat != APR_SUCCESS) { throw ThreadException(stat);