2012-05-25 14:37:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-30 09:23:05 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
#ifndef mozilla_net_SpdyStream3_h
|
|
|
|
#define mozilla_net_SpdyStream3_h
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
#include "nsAHttpTransaction.h"
|
2013-09-22 20:35:52 -07:00
|
|
|
#include "zlib.h"
|
|
|
|
|
|
|
|
class nsISocketTransport;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
namespace mozilla { namespace net {
|
|
|
|
|
2013-09-22 20:35:52 -07:00
|
|
|
class SpdySession3;
|
|
|
|
class SpdyPushedStream3;
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
class SpdyStream3 : public nsAHttpSegmentReader
|
|
|
|
, public nsAHttpSegmentWriter
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_NSAHTTPSEGMENTREADER
|
|
|
|
NS_DECL_NSAHTTPSEGMENTWRITER
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
SpdyStream3(nsAHttpTransaction *, SpdySession3 *, int32_t);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t StreamID() { return mStreamID; }
|
2013-05-28 21:07:03 -07:00
|
|
|
SpdyPushedStream3 *PushSource() { return mPushSource; }
|
|
|
|
|
|
|
|
virtual nsresult ReadSegments(nsAHttpSegmentReader *, uint32_t, uint32_t *);
|
|
|
|
virtual nsresult WriteSegments(nsAHttpSegmentWriter *, uint32_t, uint32_t *);
|
|
|
|
virtual bool DeferCleanupOnSuccess() { return false; }
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
const nsAFlatCString &Origin() const { return mOrigin; }
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
bool RequestBlockedOnRead()
|
|
|
|
{
|
|
|
|
return static_cast<bool>(mRequestBlockedOnRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns false if called more than once
|
|
|
|
bool GetFullyOpen() {return mFullyOpen;}
|
2013-05-16 06:30:42 -07:00
|
|
|
void SetFullyOpen()
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(!mFullyOpen);
|
2012-05-25 14:37:08 -07:00
|
|
|
mFullyOpen = 1;
|
|
|
|
}
|
|
|
|
|
2012-12-20 10:27:15 -08:00
|
|
|
bool HasRegisteredID() { return mStreamID != 0; }
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
nsAHttpTransaction *Transaction() { return mTransaction; }
|
|
|
|
virtual nsILoadGroupConnectionInfo *LoadGroupConnectionInfo()
|
2012-05-25 14:37:08 -07:00
|
|
|
{
|
2013-05-28 21:07:03 -07:00
|
|
|
return mTransaction ? mTransaction->LoadGroupConnectionInfo() : nullptr;
|
2012-05-25 14:37:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Close(nsresult reason);
|
|
|
|
|
|
|
|
void SetRecvdFin(bool aStatus) { mRecvdFin = aStatus ? 1 : 0; }
|
|
|
|
bool RecvdFin() { return mRecvdFin; }
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
void SetRecvdData(bool aStatus) { mReceivedData = aStatus ? 1 : 0; }
|
|
|
|
bool RecvdData() { return mReceivedData; }
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void UpdateTransportSendEvents(uint32_t count);
|
|
|
|
void UpdateTransportReadEvents(uint32_t count);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// The zlib header compression dictionary defined by SPDY,
|
|
|
|
// and hooks to the mozilla allocator for zlib to use.
|
2012-05-25 14:43:10 -07:00
|
|
|
static const unsigned char kDictionary[1423];
|
2012-05-25 14:37:08 -07:00
|
|
|
static void *zlib_allocator(void *, uInt, uInt);
|
|
|
|
static void zlib_destructor(void *, void *);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult Uncompress(z_stream *, char *, uint32_t);
|
2012-05-25 14:43:10 -07:00
|
|
|
nsresult ConvertHeaders(nsACString &);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void UpdateRemoteWindow(int32_t delta) { mRemoteWindow += delta; }
|
|
|
|
int64_t RemoteWindow() { return mRemoteWindow; }
|
2012-05-25 14:43:10 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void DecrementLocalWindow(uint32_t delta) {
|
2012-05-25 14:43:10 -07:00
|
|
|
mLocalWindow -= delta;
|
|
|
|
mLocalUnacked += delta;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void IncrementLocalWindow(uint32_t delta) {
|
2012-05-25 14:43:10 -07:00
|
|
|
mLocalWindow += delta;
|
|
|
|
mLocalUnacked -= delta;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t LocalUnAcked() { return mLocalUnacked; }
|
2013-05-28 21:07:03 -07:00
|
|
|
int64_t LocalWindow() { return mLocalWindow; }
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
bool BlockedOnRwin() { return mBlockedOnRwin; }
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
// A pull stream has an implicit sink, a pushed stream has a sink
|
|
|
|
// once it is matched to a pull stream.
|
|
|
|
virtual bool HasSink() { return true; }
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
virtual ~SpdyStream3();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsresult FindHeader(nsCString, nsDependentCSubstring &);
|
|
|
|
|
|
|
|
static void CreatePushHashKey(const nsCString &scheme,
|
|
|
|
const nsCString &hostHeader,
|
|
|
|
uint64_t serial,
|
|
|
|
const nsCSubstring &pathInfo,
|
|
|
|
nsCString &outOrigin,
|
|
|
|
nsCString &outKey);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
enum stateType {
|
|
|
|
GENERATING_SYN_STREAM,
|
|
|
|
GENERATING_REQUEST_BODY,
|
|
|
|
SENDING_REQUEST_BODY,
|
|
|
|
SENDING_FIN_STREAM,
|
|
|
|
UPSTREAM_COMPLETE
|
|
|
|
};
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
uint32_t mStreamID;
|
|
|
|
|
|
|
|
// The session that this stream is a subset of
|
|
|
|
SpdySession3 *mSession;
|
|
|
|
|
|
|
|
nsCString mOrigin;
|
|
|
|
|
|
|
|
// Each stream goes from syn_stream to upstream_complete, perhaps
|
|
|
|
// looping on multiple instances of generating_request_body and
|
|
|
|
// sending_request_body for each SPDY chunk in the upload.
|
|
|
|
enum stateType mUpstreamState;
|
|
|
|
|
|
|
|
// Flag is set when all http request headers have been read and ID is stable
|
|
|
|
uint32_t mSynFrameComplete : 1;
|
|
|
|
|
|
|
|
// Flag is set when a FIN has been placed on a data or syn packet
|
|
|
|
// (i.e after the client has closed)
|
|
|
|
uint32_t mSentFinOnData : 1;
|
|
|
|
|
|
|
|
void ChangeState(enum stateType);
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class nsAutoPtr<SpdyStream3>;
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
static PLDHashOperator hdrHashEnumerate(const nsACString &,
|
|
|
|
nsAutoPtr<nsCString> &,
|
|
|
|
void *);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult ParseHttpRequestHeaders(const char *, uint32_t, uint32_t *);
|
2013-05-28 21:07:03 -07:00
|
|
|
void AdjustInitialWindow();
|
2012-12-18 14:14:21 -08:00
|
|
|
nsresult TransmitFrame(const char *, uint32_t *, bool forceCommitment);
|
2012-08-22 08:56:38 -07:00
|
|
|
void GenerateDataFrameHeader(uint32_t, bool);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
void CompressToFrame(const nsACString &);
|
|
|
|
void CompressToFrame(const nsACString *);
|
2012-08-22 08:56:38 -07:00
|
|
|
void CompressToFrame(const char *, uint32_t);
|
|
|
|
void CompressToFrame(uint32_t);
|
2012-05-25 14:37:08 -07:00
|
|
|
void CompressFlushFrame();
|
2012-08-22 08:56:38 -07:00
|
|
|
void ExecuteCompress(uint32_t);
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// The underlying HTTP transaction. This pointer is used as the key
|
|
|
|
// in the SpdySession3 mStreamTransactionHash so it is important to
|
|
|
|
// keep a reference to it as long as this stream is a member of that hash.
|
|
|
|
// (i.e. don't change it or release it after it is set in the ctor).
|
|
|
|
nsRefPtr<nsAHttpTransaction> mTransaction;
|
|
|
|
|
|
|
|
// The underlying socket transport object is needed to propogate some events
|
|
|
|
nsISocketTransport *mSocketTransport;
|
|
|
|
|
|
|
|
// These are temporary state variables to hold the argument to
|
|
|
|
// Read/WriteSegments so it can be accessed by On(read/write)segment
|
|
|
|
// further up the stack.
|
|
|
|
nsAHttpSegmentReader *mSegmentReader;
|
|
|
|
nsAHttpSegmentWriter *mSegmentWriter;
|
|
|
|
|
|
|
|
// The quanta upstream data frames are chopped into
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mChunkSize;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// Flag is set when the HTTP processor has more data to send
|
|
|
|
// but has blocked in doing so.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mRequestBlockedOnRead : 1;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// Flag is set after the response frame bearing the fin bit has
|
|
|
|
// been processed. (i.e. after the server has closed).
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mRecvdFin : 1;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// Flag is set after syn reply received
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mFullyOpen : 1;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// Flag is set after the WAITING_FOR Transport event has been generated
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mSentWaitingFor : 1;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
// Flag is set after 1st DATA frame has been passed to stream, after
|
|
|
|
// which additional HEADERS data is invalid
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mReceivedData : 1;
|
2012-05-25 14:43:10 -07:00
|
|
|
|
2012-10-06 17:48:20 -07:00
|
|
|
// Flag is set after TCP send autotuning has been disabled
|
|
|
|
uint32_t mSetTCPSocketBuffer : 1;
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// The InlineFrame and associated data is used for composing control
|
|
|
|
// frames and data frame headers.
|
2013-01-16 15:25:03 -08:00
|
|
|
nsAutoArrayPtr<uint8_t> mTxInlineFrame;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mTxInlineFrameSize;
|
|
|
|
uint32_t mTxInlineFrameUsed;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// mTxStreamFrameSize tracks the progress of
|
|
|
|
// transmitting a request body data frame. The data frame itself
|
|
|
|
// is never copied into the spdy layer.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mTxStreamFrameSize;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// Compression context and buffer for request header compression.
|
|
|
|
// This is a copy of SpdySession3::mUpstreamZlib because it needs
|
|
|
|
// to remain the same in all streams of a session.
|
|
|
|
z_stream *mZlib;
|
|
|
|
nsCString mFlatHttpRequestHeaders;
|
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
// These are used for decompressing downstream spdy response headers
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mDecompressBufferSize;
|
|
|
|
uint32_t mDecompressBufferUsed;
|
|
|
|
uint32_t mDecompressedBytes;
|
2012-05-25 14:43:10 -07:00
|
|
|
nsAutoArrayPtr<char> mDecompressBuffer;
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// Track the content-length of a request body so that we can
|
|
|
|
// place the fin flag on the last data packet instead of waiting
|
|
|
|
// for a stream closed indication. Relying on stream close results
|
|
|
|
// in an extra 0-length runt packet and seems to have some interop
|
|
|
|
// problems with the google servers.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mRequestBodyLenRemaining;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// based on nsISupportsPriority definitions
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mPriority;
|
2012-05-25 14:37:08 -07:00
|
|
|
|
2012-05-25 14:43:10 -07:00
|
|
|
// mLocalWindow, mRemoteWindow, and mLocalUnacked are for flow control.
|
|
|
|
// *window are signed because they race conditions in asynchronous SETTINGS
|
|
|
|
// messages can force them temporarily negative.
|
|
|
|
|
|
|
|
// LocalWindow is how much data the server will send without getting a
|
|
|
|
// window update
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mLocalWindow;
|
2012-05-25 14:43:10 -07:00
|
|
|
|
|
|
|
// RemoteWindow is how much data the client is allowed to send without
|
|
|
|
// getting a window update
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mRemoteWindow;
|
2012-05-25 14:43:10 -07:00
|
|
|
|
|
|
|
// LocalUnacked is the number of bytes received by the client but not
|
|
|
|
// yet reflected in a window update. Sending that update will increment
|
|
|
|
// LocalWindow
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mLocalUnacked;
|
2012-05-25 14:43:10 -07:00
|
|
|
|
|
|
|
// True when sending is suspended becuase the remote flow control window is
|
|
|
|
// <= 0
|
|
|
|
bool mBlockedOnRwin;
|
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
// For Progress Events
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mTotalSent;
|
|
|
|
uint64_t mTotalRead;
|
2013-05-28 21:07:03 -07:00
|
|
|
|
|
|
|
// For SpdyPush
|
|
|
|
SpdyPushedStream3 *mPushSource;
|
2012-05-25 14:37:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}} // namespace mozilla::net
|
|
|
|
|
|
|
|
#endif // mozilla_net_SpdyStream3_h
|