Hi Koen,
I hope this was what your had in mind when I proposed it.
Patch attached.
Regards
Gaetano
--
cpp-today.blogspot.com
diff --git a/src/Wt/WAbstractServer b/src/Wt/WAbstractServer
index c7487b4..d80e48b 100644
--- a/src/Wt/WAbstractServer
+++ b/src/Wt/WAbstractServer
@@ -24,7 +24,8 @@ public:
#ifndef WT_CNOR
virtual void post(const std::string& sessionId,
- const boost::function<void ()>& function) = 0;
+ const boost::function<void ()>& function,
+ const boost::function<void ()>& fallBackFunction =
boost::function<void ()>()) = 0;
#endif // WT_CNOR
protected:
diff --git a/src/Wt/WServer b/src/Wt/WServer
index f1b4b46..a241559 100644
--- a/src/Wt/WServer
+++ b/src/Wt/WServer
@@ -287,12 +287,16 @@ public:
* within the thread-pool that handles incoming web requests. In
* this way, it avoids dead-lock scenarios.
*
+ * If the fallBackFunction is specified then in case the session is
+ * dead this function is called.
+ *
* This provides a good alternative to grabbing the update lock of
* an application to directly push changes to a session out of its
* event loop.
*/
virtual void post(const std::string& sessionId,
- const boost::function<void ()>& function);
+ const boost::function<void ()>& function,
+ const boost::function<void ()>& fallBackFunction =
boost::function<void ()>());
/*! \brief Returns the server instance.
*
diff --git a/src/fcgi/Server.C b/src/fcgi/Server.C
index 7be6b39..f16489b 100644
--- a/src/fcgi/Server.C
+++ b/src/fcgi/Server.C
@@ -953,9 +953,10 @@ void WServer::post(const boost::function<void ()>&
function)
}
void WServer::post(const std::string& sessionId,
- const boost::function<void ()>& function)
+ const boost::function<void ()>& function,
+ const boost::function<void ()>& fallBackFunction)
{
- ApplicationEvent event(sessionId, function);
+ ApplicationEvent event(sessionId, function, fallBackFunction);
post(boost::bind(&WebController::handleApplicationEvent,
theController, event));
diff --git a/src/http/WServer.C b/src/http/WServer.C
index bbbcfc4..3e52fba 100644
--- a/src/http/WServer.C
+++ b/src/http/WServer.C
@@ -378,9 +378,10 @@ void WServer::post(const boost::function<void ()>&
function)
}
void WServer::post(const std::string& sessionId,
- const boost::function<void ()>& function)
+ const boost::function<void ()>& function,
+ const boost::function<void ()>& fallBackFunction)
{
- ApplicationEvent event(sessionId, function);
+ ApplicationEvent event(sessionId, function, fallBackFunction);
post(boost::bind(&WebController::handleApplicationEvent,
impl_->webController_, event));
diff --git a/src/web/WebController.C b/src/web/WebController.C
index 676a314..549fab8 100644
--- a/src/web/WebController.C
+++ b/src/web/WebController.C
@@ -484,8 +484,12 @@ bool WebController::handleApplicationEvent(const
ApplicationEvent& event)
if (!session->dead()) {
session->app()->notify(WEvent(WEvent::Impl(event.function)));
return true;
- } else
+ } else {
+ if (!event.fallBackFunction.empty()) {
+ event.fallBackFunction();
+ }
return false;
+ }
}
}
diff --git a/src/web/WebController.h b/src/web/WebController.h
index b5a30ac..b91a65a 100644
--- a/src/web/WebController.h
+++ b/src/web/WebController.h
@@ -41,12 +41,16 @@ class WAbstractServer;
*/
struct ApplicationEvent {
ApplicationEvent(const std::string& aSessionId,
- const boost::function<void ()>& aFunction)
+ const boost::function<void ()>& aFunction,
+ const boost::function<void ()>& aFallBackFunction =
boost::function<void ()>())
: sessionId(aSessionId),
- function(aFunction) { }
+ function(aFunction),
+ fallBackFunction(aFallBackFunction)
+ { }
std::string sessionId;
boost::function<void ()> function;
+ boost::function<void ()> fallBackFunction;
};
#endif
------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest