#include <HTTP_SessionBase.h>


Definition at line 34 of file HTTP_SessionBase.h.
anonymous enum [protected] |
Definition at line 100 of file HTTP_SessionBase.h.
{
DEFAULT_TIMEOUT = 30, // sec
DEFAULT_KEEP_ALIVE_TIMEOUT = 8 // sec
};
| ACE::HTTP::SessionBase::SessionBase | ( | u_short | port, | |
| bool | keep_alive = false | |||
| ) |
Definition at line 26 of file HTTP_SessionBase.cpp.
: port_ (port), reactive_ (false), in_stream_ (0), out_stream_ (0), http_timeout_ (DEFAULT_TIMEOUT), keep_alive_timeout_ (DEFAULT_KEEP_ALIVE_TIMEOUT), reconnect_timer_ (DEFAULT_KEEP_ALIVE_TIMEOUT), reconnect_countdown_ (&reconnect_timer_), keep_alive_ (keep_alive), needs_reconnect_ (false), cannot_reconnect_ (false), expects_response_body_ (false) { INET_TRACE ("ACE_HTTP_SessionBase - ctor"); }
| ACE::HTTP::SessionBase::SessionBase | ( | u_short | port, | |
| const ACE_Time_Value & | timeout, | |||
| bool | keep_alive = false, |
|||
| const ACE_Time_Value * | alive_timeout = 0 | |||
| ) |
Definition at line 43 of file HTTP_SessionBase.cpp.
: port_ (port), reactive_ (false), in_stream_ (0), out_stream_ (0), http_timeout_ (timeout), keep_alive_timeout_ (DEFAULT_KEEP_ALIVE_TIMEOUT), reconnect_timer_ (DEFAULT_KEEP_ALIVE_TIMEOUT), reconnect_countdown_ (&reconnect_timer_), keep_alive_ (keep_alive), needs_reconnect_ (false), cannot_reconnect_ (false), expects_response_body_ (false) { INET_TRACE ("ACE_HTTP_SessionBase - ctor"); if (keep_alive && alive_timeout) { this->keep_alive_timeout_ = *alive_timeout; } }
| ACE::HTTP::SessionBase::~SessionBase | ( | ) | [virtual] |
Definition at line 67 of file HTTP_SessionBase.cpp.
{
INET_TRACE ("ACE_HTTP_SessionBase - dtor");
this->close_streams ();
}
| void ACE::HTTP::SessionBase::close | ( | void | ) |
Definition at line 302 of file HTTP_SessionBase.cpp.
{
INET_TRACE ("ACE_HTTP_SessionBase::close");
this->close_streams ();
this->close_i ();
}
| virtual void ACE::HTTP::SessionBase::close_i | ( | ) | [protected, pure virtual] |
| void ACE::HTTP::SessionBase::close_streams | ( | ) | [inline, protected] |
Definition at line 108 of file HTTP_SessionBase.inl.
{
if (this->in_stream_)
{
delete this->in_stream_;
this->in_stream_ = 0;
}
if (this->out_stream_)
{
delete this->out_stream_;
this->out_stream_ = 0;
}
}
| bool ACE::HTTP::SessionBase::connect | ( | bool | use_reactor = false |
) |
Definition at line 73 of file HTTP_SessionBase.cpp.
{
INET_TRACE ("ACE_HTTP_SessionBase::connect");
this->close ();
unsigned long f_reactor = use_reactor ? ACE_Synch_Options::USE_REACTOR : 0;
ACE_Synch_Options sync_opt (ACE_Synch_Options::USE_TIMEOUT | f_reactor,
this->http_timeout_);
return this->connect_i (sync_opt);
}
| virtual bool ACE::HTTP::SessionBase::connect_i | ( | const ACE_Synch_Options & | sync_opt | ) | [protected, pure virtual] |
| const ACE_CString & ACE::HTTP::SessionBase::get_host | ( | ) | const [inline] |
Definition at line 65 of file HTTP_SessionBase.inl.
{
return this->host_;
}
| u_short ACE::HTTP::SessionBase::get_port | ( | ) | const [inline] |
Definition at line 71 of file HTTP_SessionBase.inl.
{
return this->port_;
}
| const ACE_CString & ACE::HTTP::SessionBase::get_proxy_target_host | ( | ) | const [inline] |
Definition at line 83 of file HTTP_SessionBase.inl.
{
return this->proxy_target_host_;
}
| u_short ACE::HTTP::SessionBase::get_proxy_target_port | ( | ) | const [inline] |
Definition at line 89 of file HTTP_SessionBase.inl.
{
return this->proxy_target_port_;
}
| virtual bool ACE::HTTP::SessionBase::is_connected | ( | ) | const [pure virtual] |
| bool ACE::HTTP::SessionBase::is_proxy_connection | ( | ) | const [inline] |
Definition at line 77 of file HTTP_SessionBase.inl.
{
return this->proxy_connection_;
}
| bool ACE::HTTP::SessionBase::keep_alive | ( | ) | const [inline] |
Definition at line 18 of file HTTP_SessionBase.inl.
{
return this->keep_alive_;
}
| std::istream & ACE::HTTP::SessionBase::receive_response | ( | Response & | response | ) |
Definition at line 204 of file HTTP_SessionBase.cpp.
{
INET_TRACE ("ACE_HTTP_SessionBase::receive_response");
if (this->in_stream_)
{
INET_ERROR (1, (LM_ERROR, DLINFO
ACE_TEXT ("HTTP_Session::receive_response - ")
ACE_TEXT ("invalid invocation without send_request\n")));
// receive_response called second time without
// new send_request in between
return ACE::IOS::Null::in_stream_;
}
if (this->out_stream_)
{
delete this->out_stream_;
this->out_stream_ = 0;
}
this->sock_stream ().flush ();
do
{
response.clear ();
if (!response.read (this->sock_stream ()))
{
INET_ERROR (1, (LM_ERROR, DLINFO
ACE_TEXT ("(%d) HTTP_Session::receive_response - ")
ACE_TEXT ("failed to read response\n"),
ACE_OS::last_error ()));
return ACE::IOS::Null::in_stream_;
}
}
while (response.get_status ().get_status() == Status::HTTP_CONTINUE);
this->needs_reconnect_ = this->keep_alive () && !response.has_keep_alive ();
if (!this->expects_response_body_)
{
FixedLengthStreamPolicy* pol;
ACE_NEW_RETURN (pol,
FixedLengthStreamPolicy (0),
ACE::IOS::Null::in_stream_);
ACE_NEW_RETURN (this->in_stream_,
IStream (this->sock_stream (), pol),
ACE::IOS::Null::in_stream_);
}
else if (response.has_chunked_transfer_encoding ())
{
ChunkedTransferStreamPolicy* pol;
ACE_NEW_RETURN (pol,
ChunkedTransferStreamPolicy (),
ACE::IOS::Null::in_stream_);
ACE_NEW_RETURN (this->in_stream_,
IStream (this->sock_stream (), pol),
ACE::IOS::Null::in_stream_);
}
else if (response.get_content_length () != Header::UNKNOWN_CONTENT_LENGTH)
{
FixedLengthStreamPolicy* pol;
ACE_NEW_RETURN (pol,
FixedLengthStreamPolicy (response.get_content_length ()),
ACE::IOS::Null::in_stream_);
ACE_NEW_RETURN (this->in_stream_,
IStream (this->sock_stream (), pol),
ACE::IOS::Null::in_stream_);
}
else
{
ACE_NEW_RETURN (this->in_stream_,
IStream (this->sock_stream ()),
ACE::IOS::Null::in_stream_);
}
return *this->in_stream_;
}
| bool ACE::HTTP::SessionBase::reconnect_needed | ( | ) | [inline, protected] |
Definition at line 95 of file HTTP_SessionBase.inl.
{
if (this->cannot_reconnect_)
return false;
if (!this->needs_reconnect_)
{
this->reconnect_countdown_.update ();
return this->reconnect_timer_ == ACE_Time_Value::zero;
}
return true;
}
| std::ostream & ACE::HTTP::SessionBase::request_stream | ( | ACE::IOS::StreamInterceptor & | interceptor | ) |
Definition at line 192 of file HTTP_SessionBase.cpp.
{
if (this->out_stream_)
{
this->out_stream_->set_interceptor (interceptor);
return *this->out_stream_;
}
else
return ACE::IOS::Null::out_stream_;
}
| std::ostream & ACE::HTTP::SessionBase::request_stream | ( | ) |
Definition at line 184 of file HTTP_SessionBase.cpp.
{
if (this->out_stream_)
return *this->out_stream_;
else
return ACE::IOS::Null::out_stream_;
}
| std::istream & ACE::HTTP::SessionBase::response_stream | ( | ) |
Definition at line 282 of file HTTP_SessionBase.cpp.
{
if (this->in_stream_)
return *this->in_stream_;
else
return ACE::IOS::Null::in_stream_;
}
| std::istream & ACE::HTTP::SessionBase::response_stream | ( | ACE::IOS::StreamInterceptor & | interceptor | ) |
Definition at line 290 of file HTTP_SessionBase.cpp.
{
if (this->in_stream_)
{
this->in_stream_->set_interceptor (interceptor);
return *this->in_stream_;
}
else
return ACE::IOS::Null::in_stream_;
}
| std::ostream & ACE::HTTP::SessionBase::send_request | ( | Request & | request | ) |
Definition at line 86 of file HTTP_SessionBase.cpp.
{
INET_TRACE ("ACE_HTTP_SessionBase::send_request");
if (this->in_stream_)
{
delete this->in_stream_;
this->in_stream_ = 0;
}
bool keep_alive = this->keep_alive ();
if ((this->is_connected () && !keep_alive) || this->reconnect_needed ())
{
close();
this->needs_reconnect_ = false;
}
if (this->out_stream_)
{
delete this->out_stream_;
this->out_stream_ = 0;
}
if (!this->is_connected ())
{
if (this->cannot_reconnect_ || !this->connect(this->reactive_))
{
if (!this->cannot_reconnect_)
INET_ERROR (1, (LM_ERROR, DLINFO
ACE_TEXT ("(%d) HTTP_SessionBase::send_request - ")
ACE_TEXT ("reconnect failed\n"),
ACE_OS::last_error ()));
return ACE::IOS::Null::out_stream_;
}
}
if (!keep_alive)
request.set_keep_alive (false);
if (!request.has_host ())
{
if (this->port_ == URL::HTTP_PORT)
request.set_host (this->host_);
else
request.set_host (this->host_, this->port_);
}
this->expects_response_body_ = request.get_method() != Request::HTTP_HEAD;
if (request.has_chunked_transfer_encoding ())
{
request.write (this->sock_stream ());
ChunkedTransferStreamPolicy* pol;
ACE_NEW_RETURN (pol,
ChunkedTransferStreamPolicy (),
ACE::IOS::Null::out_stream_);
ACE_NEW_RETURN (this->out_stream_,
OStream (this->sock_stream (), pol),
ACE::IOS::Null::out_stream_);
}
else if (request.get_content_length () != Header::UNKNOWN_CONTENT_LENGTH)
{
ACE::IOS::CString_OStream cs;
request.write (cs);
FixedLengthStreamPolicy* pol;
ACE_NEW_RETURN (pol,
FixedLengthStreamPolicy (cs.str ().length () + request.get_content_length ()),
ACE::IOS::Null::out_stream_);
ACE_NEW_RETURN (this->out_stream_,
OStream (this->sock_stream (), pol),
ACE::IOS::Null::out_stream_);
(*this->out_stream_) << cs.str ().c_str ();
}
else if (request.get_method () != Request::HTTP_PUT && request.get_method() != Request::HTTP_POST)
{
ACE::IOS::CString_OStream cs;
request.write (cs);
FixedLengthStreamPolicy* pol;
ACE_NEW_RETURN (pol,
FixedLengthStreamPolicy (cs.str ().length ()),
ACE::IOS::Null::out_stream_);
ACE_NEW_RETURN (this->out_stream_,
OStream (this->sock_stream (), pol),
ACE::IOS::Null::out_stream_);
(*this->out_stream_) << cs.str ().c_str ();
}
else
{
ACE_NEW_RETURN (this->out_stream_,
OStream (this->sock_stream ()),
ACE::IOS::Null::out_stream_);
request.write (*this->out_stream_);
}
// reset reconnect timer
this->reconnect_timer_ = this->keep_alive_timeout_;
this->reconnect_countdown_.start ();
return *this->out_stream_;
}
| void ACE::HTTP::SessionBase::set_host | ( | const ACE_CString & | host | ) | [inline] |
Definition at line 35 of file HTTP_SessionBase.inl.
{
if (!this->is_connected ())
{
this->host_ = host;
this->proxy_connection_ = false;
}
}
| void ACE::HTTP::SessionBase::set_host | ( | const ACE_CString & | host, | |
| u_short | port | |||
| ) | [inline] |
Definition at line 24 of file HTTP_SessionBase.inl.
{
if (!this->is_connected ())
{
this->host_ = host;
this->port_ = port;
this->proxy_connection_ = false;
}
}
| void ACE::HTTP::SessionBase::set_keep_alive | ( | bool | f | ) | [inline] |
Definition at line 12 of file HTTP_SessionBase.inl.
{
this->keep_alive_ = f;
}
| void ACE::HTTP::SessionBase::set_port | ( | u_short | port | ) | [inline] |
Definition at line 45 of file HTTP_SessionBase.inl.
{
if (!this->is_connected ())
{
this->port_ = port;
}
}
| void ACE::HTTP::SessionBase::set_proxy_target | ( | const ACE_CString & | host, | |
| u_short | port | |||
| ) | [inline] |
Definition at line 54 of file HTTP_SessionBase.inl.
{
if (!this->is_connected ())
{
this->proxy_target_host_ = host;
this->proxy_target_port_ = port;
this->proxy_connection_ = true;
}
}
| virtual std::iostream& ACE::HTTP::SessionBase::sock_stream | ( | ) | [protected, pure virtual] |
bool ACE::HTTP::SessionBase::cannot_reconnect_ [protected] |
Definition at line 121 of file HTTP_SessionBase.h.
bool ACE::HTTP::SessionBase::expects_response_body_ [protected] |
Definition at line 122 of file HTTP_SessionBase.h.
ACE_CString ACE::HTTP::SessionBase::host_ [protected] |
Definition at line 106 of file HTTP_SessionBase.h.
ACE_Time_Value ACE::HTTP::SessionBase::http_timeout_ [protected] |
Definition at line 115 of file HTTP_SessionBase.h.
IStream* ACE::HTTP::SessionBase::in_stream_ [protected] |
Definition at line 113 of file HTTP_SessionBase.h.
bool ACE::HTTP::SessionBase::keep_alive_ [protected] |
Definition at line 119 of file HTTP_SessionBase.h.
Definition at line 116 of file HTTP_SessionBase.h.
bool ACE::HTTP::SessionBase::needs_reconnect_ [protected] |
Definition at line 120 of file HTTP_SessionBase.h.
OStream* ACE::HTTP::SessionBase::out_stream_ [protected] |
Definition at line 114 of file HTTP_SessionBase.h.
u_short ACE::HTTP::SessionBase::port_ [protected] |
Definition at line 107 of file HTTP_SessionBase.h.
bool ACE::HTTP::SessionBase::proxy_connection_ [protected] |
Definition at line 108 of file HTTP_SessionBase.h.
Definition at line 109 of file HTTP_SessionBase.h.
u_short ACE::HTTP::SessionBase::proxy_target_port_ [protected] |
Definition at line 110 of file HTTP_SessionBase.h.
bool ACE::HTTP::SessionBase::reactive_ [protected] |
Definition at line 112 of file HTTP_SessionBase.h.
Definition at line 118 of file HTTP_SessionBase.h.
Definition at line 117 of file HTTP_SessionBase.h.
1.7.0