summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortschoening <tschoening@13f79535-47bb-0310-9956-ffa450edef68>2014-02-10 14:17:26 +0000
committertschoening <tschoening@13f79535-47bb-0310-9956-ffa450edef68>2014-02-10 14:17:26 +0000
commit2bc0c6adcb2c6770508fb862e939f7d0b8f86bf9 (patch)
tree286a1342625f81f30f64100d71ff294b0bf0d2a1
parentd20b684e7a4f9c24c2f5e4f3482b85b05954749c (diff)
downloadlog4cxx-2bc0c6adcb2c6770508fb862e939f7d0b8f86bf9.tar.gz
LOGCXX-337: Suggested fix for socketappender not reconnecting multiple times
git-svn-id: http://svn.apache.org/repos/asf/incubator/log4cxx/trunk@1566630 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/changes/changes.xml1
-rwxr-xr-xsrc/main/cpp/socketappenderskeleton.cpp10
-rw-r--r--src/main/cpp/threadcxx.cpp26
3 files changed, 26 insertions, 11 deletions
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4478bfc..96b0e7c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -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>
diff --git a/src/main/cpp/socketappenderskeleton.cpp b/src/main/cpp/socketappenderskeleton.cpp
index 29227b4..a6b99cc 100755
--- a/src/main/cpp/socketappenderskeleton.cpp
+++ b/src/main/cpp/socketappenderskeleton.cpp
@@ -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(const LogString& option, const LogString&
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);
+ }
}
}
diff --git a/src/main/cpp/threadcxx.cpp b/src/main/cpp/threadcxx.cpp
index bfc5f9e..1ac9087 100644
--- a/src/main/cpp/threadcxx.cpp
+++ b/src/main/cpp/threadcxx.cpp
@@ -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* data) {
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);