Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::Net::HTTPSession Class Reference

#include <HTTPSession.h>

+ Inheritance diagram for Poco::Net::HTTPSession:
+ Collaboration diagram for Poco::Net::HTTPSession:

Public Types

enum  { HTTP_PORT = 80 }
 

Public Member Functions

void setKeepAlive (bool keepAlive)
 
bool getKeepAlive () const
 
void setTimeout (const Poco::Timespan &timeout)
 
void setTimeout (const Poco::Timespan &connectionTimeout, const Poco::Timespan &sendTimeout, const Poco::Timespan &receiveTimeout)
 Sets the timeout for the HTTP session.
 
Poco::Timespan getTimeout () const
 Sets different timeouts for the HTTP session.
 
bool connected () const
 Returns the timeout for the HTTP session.
 
virtual void abort ()
 Returns true if the underlying socket is connected.
 
const Poco::ExceptionnetworkException () const
 
void attachSessionData (const Poco::Any &data)
 
const Poco::AnysessionData () const
 
StreamSocket detachSocket ()
 
StreamSocketsocket ()
 
void drainBuffer (Poco::Buffer< char > &buffer)
 Returns a reference to the underlying socket.
 

Protected Member Functions

 HTTPSession ()
 
 HTTPSession (const StreamSocket &socket)
 
 HTTPSession (const StreamSocket &socket, bool keepAlive)
 
virtual ~HTTPSession ()
 
int get ()
 
int peek ()
 
virtual int read (char *buffer, std::streamsize length)
 
virtual int write (const char *buffer, std::streamsize length)
 
int receive (char *buffer, int length)
 Writes data to the socket.
 
int buffered () const
 Reads up to length bytes.
 
void refill ()
 Returns the number of bytes in the buffer.
 
virtual void connect (const SocketAddress &address)
 Refills the internal buffer.
 
void attachSocket (const StreamSocket &socket)
 
void close ()
 
void setException (const Poco::Exception &exc)
 Closes the underlying socket.
 
void clearException ()
 Stores a clone of the exception.
 

Private Types

enum  { HTTP_DEFAULT_TIMEOUT = 60000000 , HTTP_DEFAULT_CONNECTION_TIMEOUT = 30000000 }
 Clears the stored exception. More...
 

Private Member Functions

 HTTPSession (const HTTPSession &)
 
HTTPSessionoperator= (const HTTPSession &)
 

Private Attributes

StreamSocket _socket
 
char * _pBuffer
 
char * _pCurrent
 
char * _pEnd
 
bool _keepAlive
 
Poco::Timespan _connectionTimeout
 
Poco::Timespan _receiveTimeout
 
Poco::Timespan _sendTimeout
 
Poco::Exception_pException
 
Poco::Any _data
 

Friends

class HTTPStreamBuf
 
class HTTPHeaderStreamBuf
 
class HTTPFixedLengthStreamBuf
 
class HTTPChunkedStreamBuf
 

Detailed Description

HTTPSession implements basic HTTP session management for both HTTP clients and HTTP servers.

HTTPSession implements buffering for HTTP connections, as well as specific support for the various HTTP stream classes.

This class can not be instantiated. HTTPClientSession or HTTPServerSession must be used instead.

Definition at line 34 of file HTTPSession.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Returns the data attached with attachSessionData(), or an empty Poco::Any if no user data has been attached.

Enumerator
HTTP_PORT 

Definition at line 92 of file HTTPSession.h.

◆ anonymous enum

anonymous enum
private

Clears the stored exception.

Enumerator
HTTP_DEFAULT_TIMEOUT 
HTTP_DEFAULT_CONNECTION_TIMEOUT 

Definition at line 182 of file HTTPSession.h.

Constructor & Destructor Documentation

◆ HTTPSession() [1/4]

Poco::Net::HTTPSession::HTTPSession ( )
protected

Copies all bytes remaining in the internal buffer to the given Poco::Buffer, resizing it as necessary.

This is usually used together with detachSocket() to obtain any data already read from the socket, but not yet processed.

◆ HTTPSession() [2/4]

Poco::Net::HTTPSession::HTTPSession ( const StreamSocket & socket)
protected

Creates a HTTP session using an unconnected stream socket.

◆ HTTPSession() [3/4]

Poco::Net::HTTPSession::HTTPSession ( const StreamSocket & socket,
bool keepAlive )
protected

Creates a HTTP session using the given socket. The session takes ownership of the socket and closes it when it's no longer used.

◆ ~HTTPSession()

virtual Poco::Net::HTTPSession::~HTTPSession ( )
protectedvirtual

Creates a HTTP session using the given socket. The session takes ownership of the socket and closes it when it's no longer used.

◆ HTTPSession() [4/4]

Poco::Net::HTTPSession::HTTPSession ( const HTTPSession & )
private

Member Function Documentation

◆ abort()

virtual void Poco::Net::HTTPSession::abort ( )
virtual

Returns true if the underlying socket is connected.

Reimplemented in Poco::Net::HTTPSClientSession.

◆ attachSessionData()

void Poco::Net::HTTPSession::attachSessionData ( const Poco::Any & data)

If sending or receiving data over the underlying socket connection resulted in an exception, a pointer to this exception is returned.

Otherwise, NULL is returned.

◆ attachSocket()

void Poco::Net::HTTPSession::attachSocket ( const StreamSocket & socket)
protected

Connects the underlying socket to the given address and sets the socket's receive timeout.

◆ buffered()

int Poco::Net::HTTPSession::buffered ( ) const
inlineprotected

Reads up to length bytes.

Definition at line 236 of file HTTPSession.h.

◆ clearException()

void Poco::Net::HTTPSession::clearException ( )
protected

Stores a clone of the exception.

◆ close()

void Poco::Net::HTTPSession::close ( )
protected

Attaches a socket to the session, replacing the previously attached socket.

◆ connect()

virtual void Poco::Net::HTTPSession::connect ( const SocketAddress & address)
protectedvirtual

Refills the internal buffer.

Reimplemented in Poco::Net::HTTPSClientSession.

◆ connected()

bool Poco::Net::HTTPSession::connected ( ) const

Returns the timeout for the HTTP session.

◆ detachSocket()

StreamSocket Poco::Net::HTTPSession::detachSocket ( )

◆ drainBuffer()

void Poco::Net::HTTPSession::drainBuffer ( Poco::Buffer< char > & buffer)

Returns a reference to the underlying socket.

◆ get()

int Poco::Net::HTTPSession::get ( )
protected

Destroys the HTTPSession and closes the underlying socket.

◆ getKeepAlive()

bool Poco::Net::HTTPSession::getKeepAlive ( ) const
inline

Sets the keep-alive flag for this session.

If the keep-alive flag is enabled, persistent HTTP/1.1 connections are supported.

Definition at line 212 of file HTTPSession.h.

◆ getTimeout()

Poco::Timespan Poco::Net::HTTPSession::getTimeout ( ) const
inline

Sets different timeouts for the HTTP session.

Definition at line 218 of file HTTPSession.h.

◆ networkException()

const Poco::Exception * Poco::Net::HTTPSession::networkException ( ) const
inline

Aborts a session in progress by shutting down and closing the underlying socket.

Definition at line 230 of file HTTPSession.h.

◆ operator=()

HTTPSession & Poco::Net::HTTPSession::operator= ( const HTTPSession & )
private

◆ peek()

int Poco::Net::HTTPSession::peek ( )
protected

Returns the next byte in the buffer. Reads more data from the socket if there are no bytes left in the buffer.

◆ read()

virtual int Poco::Net::HTTPSession::read ( char * buffer,
std::streamsize length )
protectedvirtual

Peeks at the next character in the buffer. Reads more data from the socket if there are no bytes left in the buffer.

Reimplemented in Poco::Net::HTTPSClientSession.

◆ receive()

int Poco::Net::HTTPSession::receive ( char * buffer,
int length )
protected

Writes data to the socket.

◆ refill()

void Poco::Net::HTTPSession::refill ( )
protected

Returns the number of bytes in the buffer.

◆ sessionData()

const Poco::Any & Poco::Net::HTTPSession::sessionData ( ) const
inline

Allows to attach an application-specific data item to the session.

On the server side, this can be used to manage data that must be maintained over the entire lifetime of a persistent connection (that is, multiple requests sent over the same connection).

Definition at line 242 of file HTTPSession.h.

◆ setException()

void Poco::Net::HTTPSession::setException ( const Poco::Exception & exc)
protected

Closes the underlying socket.

◆ setKeepAlive()

void Poco::Net::HTTPSession::setKeepAlive ( bool keepAlive)

◆ setTimeout() [1/2]

void Poco::Net::HTTPSession::setTimeout ( const Poco::Timespan & connectionTimeout,
const Poco::Timespan & sendTimeout,
const Poco::Timespan & receiveTimeout )

Sets the timeout for the HTTP session.

◆ setTimeout() [2/2]

void Poco::Net::HTTPSession::setTimeout ( const Poco::Timespan & timeout)

Returns the value of the keep-alive flag for this session.

◆ socket()

StreamSocket & Poco::Net::HTTPSession::socket ( )
inline

Detaches the socket from the session.

The socket is returned, and a new, uninitialized socket is attached to the session.

Definition at line 224 of file HTTPSession.h.

◆ write()

virtual int Poco::Net::HTTPSession::write ( const char * buffer,
std::streamsize length )
protectedvirtual

Reads up to length bytes.

If there is data in the buffer, this data is returned. Otherwise, data is read from the socket to avoid unnecessary buffering.

Reimplemented in Poco::Net::HTTPClientSession.

Friends And Related Symbol Documentation

◆ HTTPChunkedStreamBuf

friend class HTTPChunkedStreamBuf
friend

Definition at line 205 of file HTTPSession.h.

◆ HTTPFixedLengthStreamBuf

friend class HTTPFixedLengthStreamBuf
friend

Definition at line 204 of file HTTPSession.h.

◆ HTTPHeaderStreamBuf

friend class HTTPHeaderStreamBuf
friend

Definition at line 203 of file HTTPSession.h.

◆ HTTPStreamBuf

friend class HTTPStreamBuf
friend

Definition at line 202 of file HTTPSession.h.

Member Data Documentation

◆ _connectionTimeout

Poco::Timespan Poco::Net::HTTPSession::_connectionTimeout
private

Definition at line 196 of file HTTPSession.h.

◆ _data

Poco::Any Poco::Net::HTTPSession::_data
private

Definition at line 200 of file HTTPSession.h.

◆ _keepAlive

bool Poco::Net::HTTPSession::_keepAlive
private

Definition at line 195 of file HTTPSession.h.

◆ _pBuffer

char* Poco::Net::HTTPSession::_pBuffer
private

Definition at line 192 of file HTTPSession.h.

◆ _pCurrent

char* Poco::Net::HTTPSession::_pCurrent
private

Definition at line 193 of file HTTPSession.h.

◆ _pEnd

char* Poco::Net::HTTPSession::_pEnd
private

Definition at line 194 of file HTTPSession.h.

◆ _pException

Poco::Exception* Poco::Net::HTTPSession::_pException
private

Definition at line 199 of file HTTPSession.h.

◆ _receiveTimeout

Poco::Timespan Poco::Net::HTTPSession::_receiveTimeout
private

Definition at line 197 of file HTTPSession.h.

◆ _sendTimeout

Poco::Timespan Poco::Net::HTTPSession::_sendTimeout
private

Definition at line 198 of file HTTPSession.h.

◆ _socket

StreamSocket Poco::Net::HTTPSession::_socket
private

Definition at line 191 of file HTTPSession.h.


The documentation for this class was generated from the following file: