Permalink
Browse files

Replace some usages of MessageChannel with MessageIO.

  • Loading branch information...
1 parent e9c6ab3 commit c1bbb69622f85082fd0991bc376faa67b7fd5e4d @FooBarWidget FooBarWidget committed Sep 5, 2011
@@ -26,17 +26,12 @@
#define _PASSENGER_CONFIGURATION_HPP_
#include "Utils.h"
-#include "MessageChannel.h"
#include "Logging.h"
#include "ServerInstanceDir.h"
#include "Constants.h"
/* The APR headers must come after the Passenger headers. See Hooks.cpp
* to learn why.
- *
- * MessageChannel.h must be included -- even though we don't actually use
- * MessageChannel.h in here, it's necessary to make sure that apr_want.h
- * doesn't b0rk on 'struct iovec'.
*/
#include "Configuration.h"
@@ -49,12 +49,12 @@
#include "MessageServer.h"
#include "ServerInstanceDir.h"
#include "ResourceLocator.h"
-#include "MessageChannel.h"
#include "FileDescriptor.h"
#include "Logging.h"
#include "Exceptions.h"
#include "Utils.h"
#include "Utils/Timer.h"
+#include "Utils/MessageIO.h"
using namespace std;
using namespace boost;
@@ -137,7 +137,6 @@ class Server {
ServerInstanceDir serverInstanceDir;
ServerInstanceDir::GenerationPtr generation;
FileDescriptor feedbackFd;
- MessageChannel feedbackChannel;
AnalyticsLoggerPtr analyticsLogger;
AccountsDatabasePtr accountsDatabase;
MessageServerPtr messageServer;
@@ -152,7 +151,7 @@ class Server {
TRACE_POINT();
vector<string> args;
- if (!feedbackChannel.read(args)) {
+ if (!readArrayMessage(feedbackFd, args)) {
throw IOException("The watchdog unexpectedly closed the connection.");
}
if (args[0] != "request socket password" && args[0] != "message socket password") {
@@ -218,7 +217,6 @@ class Server {
string loggingAgentPassword;
this->feedbackFd = feedbackFd;
- feedbackChannel = MessageChannel(feedbackFd);
UPDATE_TRACE_POINT();
messageSocketPassword = Base64::decode(options.get("message_socket_password"));
@@ -259,7 +257,8 @@ class Server {
messageServer->addHandler(ptr(new ExitHandler(exitEvent)));
UPDATE_TRACE_POINT();
- feedbackChannel.write("initialized",
+ writeArrayMessage(feedbackFd,
+ "initialized",
"", // Request socket filename; not available in the Apache helper server.
messageServer->getSocketFilename().c_str(),
NULL);
View
@@ -54,16 +54,11 @@
#include "Logging.h"
#include "AgentsStarter.hpp"
#include "ApplicationPool/Client.h"
-#include "MessageChannel.h"
#include "DirectoryMapper.h"
#include "Constants.h"
/* The Apache/APR headers *must* come after the Boost headers, otherwise
* compilation will fail on OpenBSD.
- *
- * apr_want.h *must* come after MessageChannel.h, otherwise compilation will
- * fail on platforms on which apr_want.h tries to redefine 'struct iovec'.
- * http://groups.google.com/group/phusion-passenger/browse_thread/thread/7e162f60df212e9c
*/
#include <ap_config.h>
#include <ap_release.h>
@@ -36,19 +36,19 @@
#include <unistd.h>
#include <signal.h>
-#include "Constants.h"
-#include "FileDescriptor.h"
-#include "MessageChannel.h"
-#include "MessageClient.h"
-#include "ServerInstanceDir.h"
-#include "Exceptions.h"
-#include "ResourceLocator.h"
-#include "Utils.h"
-#include "Utils/IOUtils.h"
-#include "Utils/Base64.h"
-#include "Utils/Timer.h"
-#include "Utils/ScopeGuard.h"
-#include "Utils/VariantMap.h"
+#include <Constants.h>
+#include <FileDescriptor.h>
+#include <MessageClient.h>
+#include <ServerInstanceDir.h>
+#include <Exceptions.h>
+#include <ResourceLocator.h>
+#include <Utils.h>
+#include <Utils/IOUtils.h>
+#include <Utils/MessageIO.h>
+#include <Utils/Base64.h>
+#include <Utils/Timer.h>
+#include <Utils/ScopeGuard.h>
+#include <Utils/VariantMap.h>
namespace Passenger {
@@ -125,8 +125,8 @@ class AgentsStarter {
if (fd != FEEDBACK_FD && syscalls::dup2(fd, FEEDBACK_FD) == -1) {
int e = errno;
try {
- MessageChannel channel(fd);
- channel.write("system error",
+ writeArrayMessage(fd,
+ "system error",
"dup2() failed",
toString(e).c_str(),
NULL);
@@ -466,8 +466,10 @@ class AgentsStarter {
execl(watchdogFilename.c_str(), "PassengerWatchdog", (char *) 0);
e = errno;
try {
- MessageChannel channel(FEEDBACK_FD);
- channel.write("exec error", toString(e).c_str(), NULL);
+ writeArrayMessage(FEEDBACK_FD,
+ "exec error",
+ toString(e).c_str(),
+ NULL);
_exit(1);
} catch (...) {
fprintf(stderr, "Passenger AgentsStarter: could not execute %s: %s (%d)\n",
@@ -483,7 +485,6 @@ class AgentsStarter {
// Parent
UPDATE_TRACE_POINT();
FileDescriptor feedbackFd = fds[0];
- MessageChannel feedbackChannel(fds[0]);
vector<string> args;
bool result, allAgentsStarted;
@@ -501,7 +502,7 @@ class AgentsStarter {
* reading the arguments. We'll notice that later.
*/
try {
- watchdogArgs.writeToChannel(feedbackChannel);
+ watchdogArgs.writeToFd(feedbackFd);
} catch (const SystemException &e) {
if (e.code() != EPIPE && e.code() != ECONNRESET) {
inspectWatchdogCrashReason(pid);
@@ -516,7 +517,7 @@ class AgentsStarter {
UPDATE_TRACE_POINT();
try {
- result = feedbackChannel.read(args);
+ result = readArrayMessage(feedbackFd, args);
} catch (const SystemException &ex) {
if (ex.code() == ECONNRESET) {
inspectWatchdogCrashReason(pid);
@@ -585,7 +586,7 @@ class AgentsStarter {
while (!allAgentsStarted) {
try {
UPDATE_TRACE_POINT();
- result = feedbackChannel.read(args);
+ result = readArrayMessage(feedbackFd, args);
} catch (const SystemException &ex) {
killProcessGroupAndWait(&pid, 5000);
guard.clear();
@@ -49,11 +49,11 @@
#include "../MessageReadersWriters.h"
#include "../StaticString.h"
#include "../Exceptions.h"
-#include "../MessageChannel.h"
#include "../Constants.h"
#include "../Utils.h"
#include "../Utils/MD5.h"
#include "../Utils/IOUtils.h"
+#include "../Utils/MessageIO.h"
#include "../Utils/StrIntUtils.h"
#include "../Utils/StringMap.h"
@@ -44,6 +44,7 @@
#include "../Exceptions.h"
#include "../Utils.h"
#include "../Utils/IOUtils.h"
+#include "../Utils/MessageIO.h"
#include "../Utils/Base64.h"
#include "../Utils/VariantMap.h"
@@ -265,10 +266,9 @@ main(int argc, char *argv[]) {
ev::sig sigquitWatcher(eventLoop);
if (feedbackFdAvailable()) {
- MessageChannel feedbackChannel(FEEDBACK_FD);
feedbackFdWatcher.set<&feedbackFdBecameReadable>();
feedbackFdWatcher.start(FEEDBACK_FD, ev::READ);
- feedbackChannel.write("initialized", NULL);
+ writeArrayMessage(FEEDBACK_FD, "initialized");
}
sigintWatcher.set<&caughtExitSignal>();
sigintWatcher.start(SIGINT);
View
@@ -40,15 +40,16 @@
#include <cerrno>
#include <cassert>
-#include "Account.h"
-#include "AccountsDatabase.h"
-#include "Constants.h"
-#include "FileDescriptor.h"
-#include "MessageChannel.h"
-#include "Logging.h"
-#include "Exceptions.h"
-#include "Utils/StrIntUtils.h"
-#include "Utils/IOUtils.h"
+#include <Account.h>
+#include <AccountsDatabase.h>
+#include <Constants.h>
+#include <MessageChannel.h>
+#include <FileDescriptor.h>
+#include <Logging.h>
+#include <Exceptions.h>
+#include <Utils/StrIntUtils.h>
+#include <Utils/IOUtils.h>
+#include <Utils/MessageIO.h>
namespace Passenger {
@@ -181,8 +182,6 @@ class MessageServer {
public:
/** The client's socket file descriptor. */
FileDescriptor fd;
-
- /** The channel that's associated with the client's socket. */
MessageChannel channel;
/** The account with which the client authenticated. */
@@ -195,7 +194,7 @@ class MessageServer {
/** Returns a string representation for this client context. */
string name() {
- return toString(channel.filenum());
+ return toString(fd);
}
/**
@@ -210,10 +209,13 @@ class MessageServer {
void requireRights(Account::Rights rights) {
if (!account->hasRights(rights)) {
P_TRACE(2, "Security error: insufficient rights to execute this command.");
- channel.write("SecurityException", "Insufficient rights to execute this command.", NULL);
+ writeArrayMessage(fd,
+ "SecurityException",
+ "Insufficient rights to execute this command.",
+ NULL);
throw SecurityException("Insufficient rights to execute this command.");
} else {
- channel.write("Passed security", NULL);
+ writeArrayMessage(fd, "Passed security");
}
}
};
@@ -356,40 +358,39 @@ class MessageServer {
*
* @return A smart pointer to an Account object, or NULL if authentication failed.
*/
- AccountPtr authenticate(FileDescriptor &client) {
- MessageChannel channel(client);
+ AccountPtr authenticate(const FileDescriptor &client) {
string username, password;
MemZeroGuard passwordGuard(password);
unsigned long long timeout = loginTimeout;
try {
- channel.write("version", "1", NULL);
+ writeArrayMessage(client, "version", "1", NULL);
try {
- if (!channel.readScalar(username, MESSAGE_SERVER_MAX_USERNAME_SIZE, &timeout)) {
+ if (!readScalarMessage(client, username, MESSAGE_SERVER_MAX_USERNAME_SIZE, &timeout)) {
return AccountPtr();
}
} catch (const SecurityException &) {
- channel.write("The supplied username is too long.", NULL);
+ writeArrayMessage(client, "The supplied username is too long.");
return AccountPtr();
}
try {
- if (!channel.readScalar(password, MESSAGE_SERVER_MAX_PASSWORD_SIZE, &timeout)) {
+ if (!readScalarMessage(client, password, MESSAGE_SERVER_MAX_PASSWORD_SIZE, &timeout)) {
return AccountPtr();
}
} catch (const SecurityException &) {
- channel.write("The supplied password is too long.", NULL);
+ writeArrayMessage(client, "The supplied password is too long.");
return AccountPtr();
}
AccountPtr account = accountsDatabase->authenticate(username, password);
passwordGuard.zeroNow();
if (account == NULL) {
- channel.write("Invalid username or password.", NULL);
+ writeArrayMessage(client, "Invalid username or password.");
return AccountPtr();
} else {
- channel.write("ok", NULL);
+ writeArrayMessage(client, "ok");
return account;
}
} catch (const SystemException &) {
@@ -459,7 +460,7 @@ class MessageServer {
while (!this_thread::interruption_requested()) {
UPDATE_TRACE_POINT();
- if (!commonContext.channel.read(args)) {
+ if (!readArrayMessage(commonContext.fd, args)) {
// Client closed connection.
break;
}
View
@@ -36,11 +36,10 @@
#include <unistd.h>
#include <errno.h>
-#include "Session.h"
-#include "MessageChannel.h"
-#include "Exceptions.h"
-#include "Logging.h"
-#include "Utils.h"
+#include <Session.h>
+#include <Exceptions.h>
+#include <Logging.h>
+#include <Utils.h>
namespace Passenger {
Oops, something went wrong.

0 comments on commit c1bbb69

Please sign in to comment.