NuriaProject Framework
0.1
The NuriaProject Framework
|
Abstract data transport for HttpClient. More...
#include <httptransport.hpp>
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 () | |
HttpBackend * | backend () |
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 |
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.
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.
anonymous enum |
Enumeration of different timeout timers. If one of these trigger, the connection is closed by the implementation.
|
explicit |
Constructor. server will be automatically the owner.
Nuria::HttpTransport::~HttpTransport | ( | ) |
Destructor.
|
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.
HttpBackend* Nuria::HttpTransport::backend | ( | ) |
Returns the HttpBackend associated with this transport.
|
protected |
Called by implementations after data sent by client after a call to sendToRemote() has been sent to the client.
|
protectedpure virtual |
Used by client to tell the implementation that it's done.
|
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.
|
virtualslot |
Instructs the underlying transport to send any pending data to the client now. The default implementation always returns true
.
|
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.
|
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.
|
pure virtual |
Returns true
if the transport is open.
|
virtual |
Returns true
if the connection is somehow protected against external eavesdropping, e.g. through encryption. The default implementation returns false
.
|
virtual |
Returns the local address to which the peer is connected. The default implementation returns QHostAddress::Null.
|
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 |
Returns the address of the connected peer. The default implementation returns QHostAddress::Null.
|
virtual |
Returns the port of the connected peer. The default implementation returns 0.
|
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.
|
protectedpure virtual |
Used by client to send data to the remote party.
|
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.
|
signal |
The value of timeout has been changed to msec.
|
virtual |
Returns the type of the transport. The default implementation returns Custom
.