• Main Page
  • Modules
  • Classes
  • Files
  • File List

Bucket.h

00001 /*
00002  *  Phusion Passenger - http://www.modrails.com/
00003  *  Copyright (c) 2008, 2009 Phusion
00004  *
00005  *  "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
00006  *
00007  *  Permission is hereby granted, free of charge, to any person obtaining a copy
00008  *  of this software and associated documentation files (the "Software"), to deal
00009  *  in the Software without restriction, including without limitation the rights
00010  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  *  copies of the Software, and to permit persons to whom the Software is
00012  *  furnished to do so, subject to the following conditions:
00013  *
00014  *  The above copyright notice and this permission notice shall be included in
00015  *  all copies or substantial portions of the Software.
00016  *
00017  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023  *  THE SOFTWARE.
00024  */
00025 #ifndef _PASSENGER_BUCKET_H_
00026 #define _PASSENGER_BUCKET_H_
00027 
00028 #include <boost/shared_ptr.hpp>
00029 #include <apr_buckets.h>
00030 #include "Application.h"
00031 
00032 namespace Passenger {
00033 
00034 using namespace boost;
00035 
00036 struct PassengerBucketState {
00037         /** The number of bytes that this PassengerBucket has read so far. */
00038         unsigned long bytesRead;
00039         
00040         /** Whether this PassengerBucket is completed, i.e. no more data
00041          * can be read from the underlying file descriptor. When true,
00042          * this can either mean that EOF has been reached, or that an I/O
00043          * error occured. Use errorCode to check whether an error occurred.
00044          */
00045         bool completed;
00046         
00047         /** When completed is true, errorCode contains the errno value of
00048          * the last read() call.
00049          *
00050          * A value of 0 means that no error occured.
00051          */
00052         int errorCode;
00053         
00054         PassengerBucketState() {
00055                 bytesRead = 0;
00056                 completed = false;
00057                 errorCode = 0;
00058         }
00059 };
00060 
00061 typedef shared_ptr<PassengerBucketState> PassengerBucketStatePtr;
00062 
00063 /**
00064  * We used to use an apr_bucket_pipe for forwarding the backend process's
00065  * response to the HTTP client. However, apr_bucket_pipe has a number of
00066  * issues:
00067  * - It closes the pipe's file descriptor when it has reached
00068  *   end-of-stream, but not when an error has occurred. This behavior is
00069  *   undesirable because it can easily cause file descriptor leaks.
00070  * - It does weird non-blocking-I/O related things which can cause it
00071  *   to read less data than can actually be read.
00072  *
00073  * PassengerBucket is like apr_bucket_pipe, but:
00074  * - It also holds a reference to a Session. When a read error has occured
00075  *   or when end-of-stream has been reached, the Session will be
00076  *   dereferenced, so that the underlying file descriptor is closed.
00077  * - It ignores the APR_NONBLOCK_READ flag because that's known to cause
00078  *   strange I/O problems.
00079  * - It can store its current state in a PassengerBucketState data structure.
00080  */
00081 apr_bucket *passenger_bucket_create(Passenger::Application::SessionPtr session,
00082                                     PassengerBucketStatePtr state,
00083                                     apr_bucket_alloc_t *list);
00084 
00085 } // namespace Passenger
00086 
00087 #endif /* _PASSENGER_BUCKET_H_ */

Generated on Sun Oct 17 2010 13:52:50 for Passenger by  doxygen 1.7.1