NuriaProject Framework  0.1
The NuriaProject Framework
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Friends | List of all members
Nuria::HttpTransport Class Referenceabstract

Abstract data transport for HttpClient. More...

#include <httptransport.hpp>

Inheritance diagram for Nuria::HttpTransport:

Public Types

enum  { MaxRequestsDefault = 10, DefaultConnectTimeout = 2000, DefaultDataTimeout = 5000, DefaultKeepAliveTimeout = 30000 }
 
enum  Timeout { ConnectTimeout = 0, DataTimeout = 1, KeepAliveTimeout = 2 }
 
enum  Type {
  Unknown = 0, TCP = 1, SSL = 2, Memory = 3,
  Custom = 4
}
 

Public Slots

virtual bool flush (HttpClient *client)
 
virtual void forceClose ()=0
 
virtual void init ()
 

Signals

void connectionLost ()
 
void timeoutChanged (Timeout timeout, int msec)
 

Public Member Functions

 HttpTransport (HttpBackend *backend, HttpServer *server)
 
 ~HttpTransport ()
 
HttpBackendbackend ()
 
int currentRequestCount () const
 
virtual bool isOpen () const =0
 
virtual bool isSecure () const
 
virtual QHostAddress localAddress () const
 
virtual quint16 localPort () const
 
int maxRequests () const
 
virtual QHostAddress peerAddress () const
 
virtual quint16 peerPort () const
 
void setMaxRequests (int count)
 
void setTimeout (Timeout which, int msec)
 
int timeout (Timeout which)
 
virtual Type type () const
 

Protected Member Functions

bool addToServer ()
 
void bytesSent (HttpClient *client, qint64 bytes)
 
virtual void close (HttpClient *client)=0
 
void readFromRemote (HttpClient *client, QByteArray &data)
 
virtual bool sendToRemote (HttpClient *client, const QByteArray &data)=0
 
void setCurrentRequestCount (int count)
 

Friends

class HttpClient
 

Detailed Description

Abstract data transport for HttpClient.

A transport is responsible to receive data from and send data back to a HTTP client through a specific connection. The connection can be anything which can be represented as HttpTransport, e.g. TCP, SSL or a memory buffer.

Implementing a transport

To implement a transport, you first sub-class HttpTransport. When you receive a new request, you instantiate HttpClient and use readFromRemote() to push HTTP data into the client instance. The client will eventually write a response by calling sendToRemote() and later call close() when the response has been sent.

The transport is responsible for keeping track of its HttpClient instances.

Note
The HttpServer may choose to move a HttpTransport to another thread for parallel execution. This means that the HttpTransport must be able to be run in another thread than its HttpBackend.

Member Enumeration Documentation

anonymous enum
Enumerator
MaxRequestsDefault 

Maximum requests per transport in a keep-alive session.

DefaultConnectTimeout 

Default value for ConnectTimeout. In msec.

DefaultDataTimeout 

Default value for DataTimeout. In msec.

DefaultKeepAliveTimeout 

Default value for KeepAliveTimeout. In msec.

Enumeration of different timeout timers. If one of these trigger, the connection is closed by the implementation.

Enumerator
ConnectTimeout 

The client has connected, but hasn't sent anything yet.

DataTimeout 

Timeout for when the client has sent something, but not a complete request, and just does nothing afterwards.

KeepAliveTimeout 

Timeout for keep-alive connections, meaning, the client has made a request and we're now keeping the connection open waiting for further requests.

Transport types.

Enumerator
Unknown 

Unkown transport, possibly a dummy.

TCP 

Connection using TCP.

SSL 

Connection using SSL over TCP.

Memory 

Using a in-memory buffer.

Custom 

Some other custom transport.

Constructor & Destructor Documentation

Nuria::HttpTransport::HttpTransport ( HttpBackend backend,
HttpServer server 
)
explicit

Constructor. server will be automatically the owner.

Nuria::HttpTransport::~HttpTransport ( )

Destructor.

Member Function Documentation

bool Nuria::HttpTransport::addToServer ( )
protected

Called by implementations after their initialization routine to tell the HttpServer that the transport can now be moved to a processing thread. Returns true if the instance has been moved.

See also
init
HttpBackend* Nuria::HttpTransport::backend ( )

Returns the HttpBackend associated with this transport.

void Nuria::HttpTransport::bytesSent ( HttpClient client,
qint64  bytes 
)
protected

Called by implementations after data sent by client after a call to sendToRemote() has been sent to the client.

virtual void Nuria::HttpTransport::close ( HttpClient client)
protectedpure virtual

Used by client to tell the implementation that it's done.

void Nuria::HttpTransport::connectionLost ( )
signal

Emitted when the connection to the client has been lost.

int Nuria::HttpTransport::currentRequestCount ( ) const

Returns the count of requests this transport has started.

virtual bool Nuria::HttpTransport::flush ( HttpClient client)
virtualslot

Instructs the underlying transport to send any pending data to the client now. The default implementation always returns true.

virtual void Nuria::HttpTransport::forceClose ( )
pure virtualslot

Closes the underlying transport immediately, discarding any data in the send buffer (If one exists). This is used by clients if they encounter a fatal error which should result in disconnecting from the peer entirely.

virtual void Nuria::HttpTransport::init ( )
virtualslot

Called by the HttpServer when the HttpTransport was moved by addToServer(). If the server didn't move the transport, addToServer() will call this function. The default implementation does nothing.

virtual bool Nuria::HttpTransport::isOpen ( ) const
pure virtual

Returns true if the transport is open.

virtual bool Nuria::HttpTransport::isSecure ( ) const
virtual

Returns true if the connection is somehow protected against external eavesdropping, e.g. through encryption. The default implementation returns false.

virtual QHostAddress Nuria::HttpTransport::localAddress ( ) const
virtual

Returns the local address to which the peer is connected. The default implementation returns QHostAddress::Null.

virtual quint16 Nuria::HttpTransport::localPort ( ) const
virtual

Returns the local port to which the peer is connected. The default implementation returns 0.

int Nuria::HttpTransport::maxRequests ( ) const

Returns the maximum count of requests per transport. A value of -1 indicates that there's no limit.

virtual QHostAddress Nuria::HttpTransport::peerAddress ( ) const
virtual

Returns the address of the connected peer. The default implementation returns QHostAddress::Null.

virtual quint16 Nuria::HttpTransport::peerPort ( ) const
virtual

Returns the port of the connected peer. The default implementation returns 0.

void Nuria::HttpTransport::readFromRemote ( HttpClient client,
QByteArray &  data 
)
protected

Used by the implementation to write data into client to be processed. The client will remove the parts it read from data. If it didn't read everything, it means that the following data is probably meant to create another HTTP request by the remote peer.

virtual bool Nuria::HttpTransport::sendToRemote ( HttpClient client,
const QByteArray &  data 
)
protectedpure virtual

Used by client to send data to the remote party.

void Nuria::HttpTransport::setCurrentRequestCount ( int  count)
protected

Used by implementations to update the request count.

void Nuria::HttpTransport::setMaxRequests ( int  count)

Sets the maximum count of requests per transport.

void Nuria::HttpTransport::setTimeout ( Timeout  which,
int  msec 
)

Sets the timeout which to msec.

int Nuria::HttpTransport::timeout ( Timeout  which)

Returns the timeout time for which in msec. A value of -1 disables the timeout.

void Nuria::HttpTransport::timeoutChanged ( Timeout  timeout,
int  msec 
)
signal

The value of timeout has been changed to msec.

virtual Type Nuria::HttpTransport::type ( ) const
virtual

Returns the type of the transport. The default implementation returns Custom.


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