0
@@ -11,30 +11,113 @@ namespace Passenger {
0
-// TODO: write better documentation
0
+ * Represents a single instance of a Ruby on Rails application, as spawned by
0
+ * SpawnManager. An Application can handle one CGI request at a time, through its
0
+ * two communication channels: reader and writer.
0
+ * Application is supposed to be used as follows:
0
+ * 1. The web server first opens the Application, thereby telling the Application
0
+ * that the web server wants to establish a new CGI session. Application
0
+ * will return a lock, which the web server must hold onto.
0
+ * 2. The web server sends the CGI request data through the Application's
0
+ * 3. The web server reads the HTTP response from the Application's reader channel,
0
+ * and forwarding that to the web browser.
0
+ * 4. The web server destroys the previously obtained lock.
0
+ * 5. The web server closes the Application, thereby ending the CGI session.
0
+ * An Application can be reopened after it has been closed.
0
+ * // Create a new Application.
0
+ * ApplicationPtr app(some_function_which_returns_an_application());
0
+ * // Open a new CGI session, and save the lock.
0
+ * Application::LockPtr lock(app->openSession());
0
+ * // Process request and response.
0
+ * send_cgi_headers_to(app->getWriter());
0
+ * response = read_response_from(app->getReader());
0
+ * process_response(response);
0
+ * // Now we're done. *First* we destroy the lock!
0
+ * lock = Application::LockPtr();
0
+ * // And *then* we close the session.
0
+ * app->closeSession();
0
+ * <h2>About open/close
0
+ shared_ptr<LockData> lockData;
0
+ friend class Application;
0
+ shared_ptr<LockData> data;
0
+ Lock(shared_ptr<LockData> data) {
0
+ typedef shared_ptr<Lock> LockPtr;
0
Application(const string &theAppRoot, pid_t pid, int reader, int writer) {
0
+ lockData = ptr(new LockData());
0
+ lockData->locked = false;
0
P_TRACE("Application " << this << ": created.");
0
+ virtual ~Application() {
0
P_TRACE("Application " << this << ": destroyed.");
0
- void detachCommunicationChannels() {
0
+ LockPtr openSession() {
0
+ lockData->locked = true;
0
+ return ptr(new Lock(lockData));
0
+ bool hasError() const {
0
+ return opened && !lockData->locked;
0
string getAppRoot() const {
0
@@ -52,20 +135,6 @@ public:
0
int getWriter() const {
0
typedef shared_ptr<Application> ApplicationPtr;
Comments
No one has commented yet.