0
@@ -123,7 +123,6 @@ private:
0
* An Application::Session which works together with ApplicationPoolServer.
0
class RemoteSession: public Application::Session {
0
@@ -217,10 +216,20 @@ private:
0
channel.write("get", appRoot.c_str(), user.c_str(), group.c_str(), NULL);
0
- reader = channel.readFileDescriptor();
0
- writer = channel.readFileDescriptor();
0
- return ptr(new RemoteSession(data, atoi(args[0].c_str()), reader, writer));
0
+ if (!channel.read(args)) {
0
+ throw IOException("The ApplicationPool server unexpectedly disconnected the connection.");
0
+ if (args[0] == "ok") {
0
+ reader = channel.readFileDescriptor();
0
+ writer = channel.readFileDescriptor();
0
+ return ptr(new RemoteSession(data, atoi(args[1]), reader, writer));
0
+ } else if (args[0] == "SpawnException") {
0
+ throw SpawnException(args[1]);
0
+ } else if (args[0] == "IOException") {
0
+ throw IOException(args[1]);
0
+ throw IOException("The ApplicationPool server returned an unknown message.");
0
@@ -270,9 +279,32 @@ private:
0
- socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
0
- MessageChannel(serverSocket).writeFileDescriptor(fds[1]);
0
+ // Incoming connect request.
0
+ ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
0
+ } while (ret == -1 && errno == EINTR);
0
+ P_ERROR("Cannot create an anonymous Unix socket: " <<
0
+ strerror(e) << " (" << e << ")");
0
+ // Shut up compiler warning.
0
+ MessageChannel(serverSocket).writeFileDescriptor(fds[1]);
0
+ } while (ret == -1 && errno == EINTR);
0
+ } catch (const exception &e) {
0
+ P_ERROR("Cannot send a file descriptor: " << e.what());
0
ClientInfoPtr info(new ClientInfo());
0
@@ -291,29 +323,60 @@ private:
0
map<int, Application::SessionPtr> sessions;
0
- if (!channel.read(args)) {
0
+ if (!channel.read(args)) {
0
- if (args[0] == "get" && args.size() == 4) {
0
- Application::SessionPtr session(pool.get(args[1], args[2], args[3]));
0
- channel.write(toString(lastID).c_str(), NULL);
0
- channel.writeFileDescriptor(session->getReader());
0
- channel.writeFileDescriptor(session->getWriter());
0
- session->closeReader();
0
- session->closeWriter();
0
- sessions[lastID] = session;
0
- } else if (args[0] == "close" && args.size() == 2) {
0
- sessions.erase(atoi(args[1].c_str()));
0
- } else if (args[0] == "setMax") {
0
- pool.setMax(atoi(args[1].c_str()));
0
- } else if (args[0] == "getActive") {
0
- channel.write(toString(pool.getActive()).c_str(), NULL);
0
- } else if (args[0] == "getCount") {
0
- channel.write(toString(pool.getCount()).c_str(), NULL);
0
+ if (args[0] == "get" && args.size() == 4) {
0
+ Application::SessionPtr session;
0
+ session = pool.get(args[1], args[2], args[3]);
0
+ } catch (const SpawnException &e) {
0
+ channel.write("SpawnException", e.what(), NULL);
0
+ } catch (const IOException &e) {
0
+ channel.write("IOException", e.what(), NULL);
0
+ channel.write("ok", toString(lastID).c_str(), NULL);
0
+ channel.writeFileDescriptor(session->getReader());
0
+ channel.writeFileDescriptor(session->getWriter());
0
+ session->closeReader();
0
+ session->closeWriter();
0
+ sessions[lastID] = session;
0
+ } else if (args[0] == "close" && args.size() == 2) {
0
+ sessions.erase(atoi(args[1]));
0
+ } else if (args[0] == "setMax" && args.size() == 2) {
0
+ pool.setMax(atoi(args[1]));
0
+ } else if (args[0] == "getActive" && args.size() == 1) {
0
+ channel.write(toString(pool.getActive()).c_str(), NULL);
0
+ } else if (args[0] == "getCount" && args.size() == 1) {
0
+ channel.write(toString(pool.getCount()).c_str(), NULL);
0
+ P_WARN("An ApplicationPoolServer client sent an invalid command: "
0
+ << name << " (" << args.size() << " elements)");
0
+ } catch (const exception &e) {
0
+ P_WARN("Uncaught exception in ApplicationPoolServer client thread: " <<
0
mutex::scoped_lock l(lock);
Comments
No one has commented yet.