#include <Stream.h>

Inheritance diagram for Http::Stream:
Collaboration diagram for Http::Stream:


class  DeferredParams

Public Member Functions

 Stream (const Comm::ConnectionPointer &aConn, ClientHttpRequest *aReq)
 construct with HTTP/1.x details More...
 ~Stream ()
void registerWithConn ()
 register this stream with the Server More...
bool connRegistered () const
 whether it is registered with a Server More...
bool startOfOutput () const
 whether the reply has started being sent More...
void writeComplete (size_t size)
 update stream state after a write, may initiate more I/O More...
void pullData ()
 get more data to send More...
bool multipartRangeRequest () const
int64_t getNextRangeOffset () const
bool canPackMoreRanges () const
size_t lengthToSend (Range< int64_t > const &available) const
clientStream_status_t socketState ()
 Adapt stream status to account for Range cases. More...
void sendStartOfMessage (HttpReply *, StoreIOBuffer bodyData)
 send an HTTP reply message headers and maybe some initial payload More...
void sendBody (StoreIOBuffer bodyData)
 send some HTTP reply message payload More...
void noteSentBodyBytes (size_t)
void buildRangeHeader (HttpReply *)
 add Range headers (if any) to the given HTTP reply message More...
clientStreamNodegetTail () const
clientStreamNodegetClientReplyContext () const
ConnStateDatagetConn () const
void noteIoError (const int xerrno)
 update state to reflect I/O error More...
void finished ()
 cleanup when the transaction has finished. may destroy 'this' More...
void initiateClose (const char *reason)
 terminate due to a send/write error (may continue reading) More...
void deferRecipientForLater (clientStreamNode *, HttpReply *, StoreIOBuffer receivedData)
bool mayUseConnection () const
void mayUseConnection (bool aBool)

Public Attributes

Comm::ConnectionPointer clientConnection
 details about the client connection socket More...
char reqbuf [HTTP_REQBUF_SZ]
struct {
   unsigned   deferred:1
 This is a pipelined request waiting for the current object to complete. More...
   unsigned   parsed_ok:1
 Was this parsed correctly? More...
DeferredParams deferredparams
int64_t writtenToSocket

Private Member Functions

void prepareReply (HttpReply *)
void packChunk (const StoreIOBuffer &bodyData, MemBuf &)
void packRange (StoreIOBuffer const &, MemBuf *)
void doClose ()

Private Attributes

bool mayUseConnection_
bool connRegistered_
MessageBucket::Pointer writeQuotaHandler
 response write limiter, if configured More...

Detailed Description

The processing context for a single HTTP transaction (stream).

A stream lifetime extends from directly after a request has been parsed off the client connection buffer, until the last byte of both request and reply payload (if any) have been written, or it is otherwise explicitly terminated.

Streams self-register with the Http::Server Pipeline being managed by the Server for the connection on which the request was received.

The socket level management and I/O is done by a Server which owns us. The scope of this objects control over a socket consists of the data buffer received from the Server with an initially unknown length. When that length is known it sets the end boundary of our access to the buffer.

The individual processing actions are done by other Jobs which we start.

When a stream is completed the finished() method needs to be called which will perform all cleanup and deregistration operations. If the reason for finishing is an error, then notifyIoError() needs to be called prior to the finished() method. The caller should follow finished() with a call to ConnStateData::kick() to resume processing of other transactions or I/O on the connection.

Alternatively the initiateClose() method can be called to terminate the whole client connection and all other pending streams.


When HTTP/1 pipeline is operating there may be multiple transactions using the client connection. Only the back() stream may read from the connection, and only the front() stream may write to it. A stream which needs to read or write to the connection but does not meet those criteria must be shifted to the deferred state.

XXX: If an async call ends the ClientHttpRequest job, Http::Stream (and ConnStateData) may not know about it, leading to segfaults and assertions. This is difficult to fix because ClientHttpRequest lacks a good way to communicate its ongoing destruction back to the Http::Stream which pretends to "own" *http.

Definition at line 69 of file Stream.h.

Constructor & Destructor Documentation

Http::Stream::Stream ( const Comm::ConnectionPointer aConn,
ClientHttpRequest aReq 
Http::Stream::~Stream ( )

Definition at line 39 of file Stream.cc.

References assert, and httpRequestFree().

Member Function Documentation

bool Http::Stream::canPackMoreRanges ( ) const

increments iterator "i" used by clientPackMoreRanges

Return values
truethere is still data available to pack more ranges

first update iterator "i" if needed

Definition at line 191 of file Stream.cc.

References assert, and debugs.

bool Http::Stream::connRegistered ( ) const

Definition at line 82 of file Stream.h.

References connRegistered_.

void Http::Stream::deferRecipientForLater ( clientStreamNode node,
HttpReply rep,
StoreIOBuffer  receivedData 

Definition at line 592 of file Stream.cc.

References assert, and debugs.

void Http::Stream::doClose ( )

Definition at line 693 of file Stream.cc.

void Http::Stream::finished ( )

Definition at line 571 of file Stream.cc.

References assert, clientStreamDetach(), conn, Server::pipeline, and Pipeline::popMe().

clientStreamNode * Http::Stream::getClientReplyContext ( ) const
ConnStateData * Http::Stream::getConn ( ) const

Definition at line 553 of file Stream.cc.

References assert.

int64_t Http::Stream::getNextRangeOffset ( ) const
FIXME: should use range_iter_pos on reply, as soon as reply->content_range becomes HttpHdrRange rather than HttpHdrRangeSpec.

Definition at line 135 of file Stream.cc.

References assert, and debugs.

clientStreamNode * Http::Stream::getTail ( ) const

Definition at line 538 of file Stream.cc.

void Http::Stream::initiateClose ( const char *  reason)

called when we encounter a response-related error

Definition at line 585 of file Stream.cc.

References debugs.

size_t Http::Stream::lengthToSend ( Range< int64_t > const &  available) const

Definition at line 339 of file Stream.cc.

References assert, min(), Range< C, S >::size(), and Range< C, S >::start.

bool Http::Stream::mayUseConnection ( ) const

Definition at line 140 of file Stream.h.

References mayUseConnection_.

Referenced by ConnStateData::buildFakeRequest(), and clientProcessRequest().

void Http::Stream::mayUseConnection ( bool  aBool)

Definition at line 142 of file Stream.h.

References debugs, and mayUseConnection_.

Http::Stream::MEMPROXY_CLASS ( Stream  )
bool Http::Stream::multipartRangeRequest ( ) const
true if the HTTP request is for multiple ranges

Definition at line 129 of file Stream.cc.

void Http::Stream::noteIoError ( const int  xerrno)

remembers the abnormal connection termination for logging purposes

Definition at line 561 of file Stream.cc.

void Http::Stream::noteSentBodyBytes ( size_t  bytes)

update stream state when N bytes are being sent. NP: Http1Server bytes actually not sent yet, just packed into a MemBuf ready

Definition at line 362 of file Stream.cc.

References assert, and debugs.

void Http::Stream::packChunk ( const StoreIOBuffer bodyData,
MemBuf mb 

Packs bodyData into mb using chunked encoding. Packs the last-chunk if bodyData is empty.

Definition at line 615 of file Stream.cc.

References MemBuf::append(), Packable::appendf(), StoreIOBuffer::data, PRIX64, and StoreIOBuffer::range().

void Http::Stream::packRange ( StoreIOBuffer const &  source,
MemBuf mb 
void Http::Stream::prepareReply ( HttpReply rep)

Definition at line 603 of file Stream.cc.

void Http::Stream::pullData ( )
void Http::Stream::registerWithConn ( )

Definition at line 52 of file Stream.cc.

References assert.

Referenced by ConnStateData::buildFakeRequest().

void Http::Stream::sendBody ( StoreIOBuffer  bodyData)
clientStream_status_t Http::Stream::socketState ( )
bool Http::Stream::startOfOutput ( ) const

Definition at line 61 of file Stream.cc.

Member Data Documentation

Comm::ConnectionPointer Http::Stream::clientConnection

Definition at line 131 of file Stream.h.

bool Http::Stream::connRegistered_

Definition at line 166 of file Stream.h.

Referenced by connRegistered().

unsigned Http::Stream::deferred

Definition at line 136 of file Stream.h.

DeferredParams Http::Stream::deferredparams

Definition at line 156 of file Stream.h.

Referenced by Stream().

struct { ... } Http::Stream::flags
bool Http::Stream::mayUseConnection_

Definition at line 165 of file Stream.h.

Referenced by mayUseConnection().

unsigned Http::Stream::parsed_ok
HttpReply* Http::Stream::reply

Definition at line 133 of file Stream.h.

char Http::Stream::reqbuf[HTTP_REQBUF_SZ]
MessageBucket::Pointer Http::Stream::writeQuotaHandler

Definition at line 168 of file Stream.h.

int64_t Http::Stream::writtenToSocket

Definition at line 157 of file Stream.h.

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






Web Site Translations