0
#define _PASSENGER_APPLICATION_POOL_SERVER_H_
0
#include <boost/shared_ptr.hpp>
0
+#include <boost/thread/mutex.hpp>
0
@@ -135,6 +136,8 @@ private:
0
@@ -161,6 +164,7 @@ private:
0
virtual ~RemoteSession() {
0
+ mutex::scoped_lock(data->lock);
0
MessageChannel(data->server).write("close", toString(id).c_str(), NULL);
0
@@ -187,6 +191,10 @@ private:
0
+ virtual void discardStream() {
0
virtual pid_t getPid() const {
0
@@ -199,7 +207,10 @@ private:
0
class Client: public ApplicationPool {
0
+ // The smart pointer only serves to keep the shared data alive.
0
+ // We access the shared data via a normal pointer, for performance.
0
+ SharedDataPtr dataSmartPointer;
0
@@ -208,27 +219,32 @@ private:
0
* @param sock The newly established socket connection with the ApplicationPoolServer.
0
- data = ptr(new SharedData());
0
+ dataSmartPointer = ptr(new SharedData());
0
+ data = dataSmartPointer.get();
0
MessageChannel channel(data->server);
0
+ mutex::scoped_lock l(data->lock);
0
channel.write("clear", NULL);
0
virtual void setMaxIdleTime(unsigned int seconds) {
0
MessageChannel channel(data->server);
0
+ mutex::scoped_lock l(data->lock);
0
channel.write("setMaxIdleTime", toString(seconds).c_str(), NULL);
0
virtual void setMax(unsigned int max) {
0
MessageChannel channel(data->server);
0
+ mutex::scoped_lock l(data->lock);
0
channel.write("setMax", toString(max).c_str(), NULL);
0
virtual unsigned int getActive() const {
0
MessageChannel channel(data->server);
0
+ mutex::scoped_lock l(data->lock);
0
channel.write("getActive", NULL);
0
@@ -238,6 +254,7 @@ private:
0
virtual unsigned int getCount() const {
0
MessageChannel channel(data->server);
0
+ mutex::scoped_lock l(data->lock);
0
channel.write("getCount", NULL);
0
@@ -247,6 +264,7 @@ private:
0
virtual pid_t getSpawnServerPid() const {
0
MessageChannel channel(data->server);
0
+ mutex::scoped_lock l(data->lock);
0
channel.write("getSpawnServerPid", NULL);
0
@@ -262,8 +280,10 @@ private:
0
const string &spawnMethod = "smart"
0
MessageChannel channel(data->server);
0
+ mutex::scoped_lock l(data->lock);
0
channel.write("get", appRoot.c_str(),
0
@@ -275,18 +295,27 @@ private:
0
} catch (const SystemException &) {
0
throw IOException("The ApplicationPool server exited unexpectedly.");
0
- if (!channel.read(args)) {
0
- throw IOException("The ApplicationPool server unexpectedly closed the connection.");
0
+ result = channel.read(args);
0
+ } catch (const SystemException &e) {
0
+ throw SystemException("Could not read a message from "
0
+ "the ApplicationPool server", e.code());
0
+ throw IOException("The ApplicationPool server unexpectedly "
0
+ "closed the connection.");
0
stream = channel.readFileDescriptor();
0
- return ptr(new RemoteSession(data, atoi(args[1]), atoi(args[2]), stream));
0
+ return ptr(new RemoteSession(dataSmartPointer,
0
+ atoi(args[1]), atoi(args[2]), stream));
0
} else if (args[0] == "SpawnException") {
0
if (args[2] == "true") {
0
if (!channel.readScalar(errorPage)) {
0
- throw IOException("The ApplicationPool server unexpectedly closed the connection.");
0
+ throw IOException("The ApplicationPool server "
0
+ "unexpectedly closed the connection.");
0
throw SpawnException(args[1], errorPage);
0
@@ -295,7 +324,8 @@ private:
0
} else if (args[0] == "IOException") {
0
throw IOException(args[1]);
0
- throw IOException("The ApplicationPool server returned an unknown message.");
0
+ throw IOException("The ApplicationPool server returned "
0
+ "an unknown message: " + toString(args));
Comments
No one has commented yet.