Represents a single request/response pair of an application process. More...
#include <Session.h>
Public Member Functions | |
virtual | ~Session () |
Concrete classes might throw arbitrary exceptions. | |
virtual void | initiate ()=0 |
Initiate the session by connecting to the associated process. | |
virtual bool | initiated () const =0 |
Returns whether this session has been initiated (that is, whether initiate() had been called in the past). | |
virtual string | getSocketType () const =0 |
Returns the type of the socket that this session is served from, e.g. | |
virtual string | getSocketName () const =0 |
Returns the address of the socket that this session is served from. | |
virtual void | sendHeaders (const char *headers, unsigned int size) |
Send HTTP request headers to the application. | |
virtual void | sendHeaders (const StaticString &headers) |
Convenience shortcut for sendHeaders(const char *, unsigned int). | |
virtual void | sendBodyBlock (const char *block, unsigned int size) |
Send a chunk of HTTP request body data to the application. | |
virtual int | getStream () const =0 |
Returns this session's channel's file descriptor. | |
virtual void | setReaderTimeout (unsigned int msec)=0 |
Set the timeout value for reading data from the I/O channel. | |
virtual void | setWriterTimeout (unsigned int msec)=0 |
Set the timeout value for writing data from the I/O channel. | |
virtual void | shutdownReader ()=0 |
Indicate that we don't want to read data anymore from the I/O channel. | |
virtual void | shutdownWriter ()=0 |
Indicate that we don't want to write data anymore to the I/O channel. | |
virtual void | closeStream ()=0 |
Close the I/O stream. | |
virtual void | discardStream ()=0 |
Discard the I/O channel's file descriptor, so that the destructor won't automatically close it. | |
virtual pid_t | getPid () const =0 |
Get the process ID of the application process that this session belongs to. | |
const string | getConnectPassword () const |
Returns this session's process's connect password. |
Represents a single request/response pair of an application process.
Session is used to forward a single HTTP request to an application process, and to read back the HTTP response. A Session object is to be used in the following manner:
A usage example is shown in Process::newSession().
Session is an abstract base class. Concrete implementations can be found in StandardSession and ApplicationPool::Client::RemoteSession.
Session is not guaranteed to be thread-safe.
virtual void Passenger::Session::closeStream | ( | ) | [pure virtual] |
Close the I/O stream.
SystemException | Something went wrong. | |
boost::thread_interrupted |
Implemented in Passenger::StandardSession.
virtual void Passenger::Session::discardStream | ( | ) | [pure virtual] |
Discard the I/O channel's file descriptor, so that the destructor won't automatically close it.
Implemented in Passenger::StandardSession.
const string Passenger::Session::getConnectPassword | ( | ) | const [inline] |
Returns this session's process's connect password.
This password is guaranteed to be valid ASCII.
virtual string Passenger::Session::getSocketName | ( | ) | const [pure virtual] |
Returns the address of the socket that this session is served from.
This can be a Unix socket filename or a TCP host:port string like "127.0.0.1:1234".
Implemented in Passenger::StandardSession.
virtual string Passenger::Session::getSocketType | ( | ) | const [pure virtual] |
Returns the type of the socket that this session is served from, e.g.
"unix" indicating a Unix socket.
Implemented in Passenger::StandardSession.
virtual int Passenger::Session::getStream | ( | ) | const [pure virtual] |
Returns this session's channel's file descriptor.
This stream is full-duplex, and will be automatically closed upon Session's destruction, unless discardStream() is called.
Implemented in Passenger::StandardSession.
virtual void Passenger::Session::initiate | ( | ) | [pure virtual] |
Initiate the session by connecting to the associated process.
A Session is not usable until it's initiated.
SystemException | Something went wrong. | |
IOException | Something went wrong. | |
boost::thread_interrupted |
Implemented in Passenger::StandardSession.
virtual void Passenger::Session::sendBodyBlock | ( | const char * | block, | |
unsigned int | size | |||
) | [inline, virtual] |
Send a chunk of HTTP request body data to the application.
You can call this method as many times as is required to transfer the entire HTTP request body.
This method must only be called after a sendHeaders(), otherwise strange things may happen.
block | A block of HTTP request body data to send. | |
size | The size, in bytes, of block . |
IOException | The I/O channel has already been closed or discarded. | |
SystemException | Something went wrong during writing. | |
boost::thread_interrupted |
virtual void Passenger::Session::sendHeaders | ( | const StaticString & | headers | ) | [inline, virtual] |
Convenience shortcut for sendHeaders(const char *, unsigned int).
headers | The headers |
IOException | The I/O channel has already been closed or discarded. | |
SystemException | Something went wrong during writing. | |
boost::thread_interrupted |
virtual void Passenger::Session::sendHeaders | ( | const char * | headers, | |
unsigned int | size | |||
) | [inline, virtual] |
Send HTTP request headers to the application.
The HTTP headers must be converted into CGI headers, and then encoded into a string that matches this grammar:
headers ::= header* header ::= name NUL value NUL name ::= notnull+ value ::= notnull+ notnull ::= "\x01" | "\x02" | "\x02" | ... | "\xFF" NUL = "\x00"
There must be a header with the name "PASSWORD_CONNECT_PASSWORD", and it must have the same value as the string returned by getConnectPassword().
This method should be the first one to be called during the lifetime of a Session object, otherwise strange things may happen.
headers | The HTTP request headers, converted into CGI headers and encoded as a string, according to the description. | |
size | The size, in bytes, of headers . |
IOException | The I/O channel has already been closed or discarded. | |
SystemException | Something went wrong during writing. | |
boost::thread_interrupted |
virtual void Passenger::Session::setReaderTimeout | ( | unsigned int | msec | ) | [pure virtual] |
Set the timeout value for reading data from the I/O channel.
If no data can be read within the timeout period, then the read call will fail with error EAGAIN or EWOULDBLOCK.
msec | The timeout, in milliseconds. If 0 is given, there will be no timeout. |
SystemException | Cannot set the timeout. |
Implemented in Passenger::StandardSession.
virtual void Passenger::Session::setWriterTimeout | ( | unsigned int | msec | ) | [pure virtual] |
Set the timeout value for writing data from the I/O channel.
If no data can be written within the timeout period, then the write call will fail with error EAGAIN or EWOULDBLOCK.
msec | The timeout, in milliseconds. If 0 is given, there will be no timeout. |
SystemException | Cannot set the timeout. |
Implemented in Passenger::StandardSession.
virtual void Passenger::Session::shutdownReader | ( | ) | [pure virtual] |
Indicate that we don't want to read data anymore from the I/O channel.
Calling this method after closeStream()/discardStream() is called will have no effect.
SystemException | Something went wrong. | |
boost::thread_interrupted |
Implemented in Passenger::StandardSession.
virtual void Passenger::Session::shutdownWriter | ( | ) | [pure virtual] |
Indicate that we don't want to write data anymore to the I/O channel.
Calling this method after closeStream()/discardStream() is called will have no effect.
SystemException | Something went wrong. | |
boost::thread_interrupted |
Implemented in Passenger::StandardSession.