/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set sw=2 ts=8 et tw=80 : */ /* 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/. */
class nsIAsyncVerifyRedirectCallback; class nsIDashboardEventNotifier; class nsIEventTarget; class nsIHttpChannel; class nsIRandomGenerator; class nsISocketTransport; class nsIURI;
namespace mozilla { namespace net {
class OutboundMessage; class OutboundEnqueuer; class nsWSAdmissionManager; class PMCECompression; class CallOnMessageAvailable; class CallOnStop; class CallOnServerClose; class CallAcknowledge; class WebSocketEventService; class WebSocketConnectionBase;
// Used to enforce "1 connecting websocket per host" rule, and reconnect delays enum wsConnectingState {
NOT_CONNECTING = 0, // Not yet (or no longer) trying to open connection
CONNECTING_QUEUED, // Waiting for other ws to same host to finish opening
CONNECTING_DELAYED, // Delayed by "reconnect after failure" algorithm
CONNECTING_IN_PROGRESS // Started connection: waiting for result
};
class WebSocketChannel : public BaseWebSocketChannel, public nsIHttpUpgradeListener, public nsIStreamListener, public nsIInputStreamCallback, public nsIOutputStreamCallback, public nsITimerCallback, public nsIDNSListener, public nsIObserver, public nsIProtocolProxyCallback, public nsIInterfaceRequestor, public nsIChannelEventSink, public nsINamed, public WebSocketConnectionListener { friendclass WebSocketFrame;
inlinevoid ResetPingTimer() {
mPingOutstanding = 0; if (mPingTimer) { if (!mPingInterval) { // The timer was created by forced ping and regular pinging is disabled, // so cancel and null out mPingTimer.
mPingTimer->Cancel();
mPingTimer = nullptr;
} else {
mPingTimer->SetDelay(mPingInterval);
}
}
}
void NotifyOnStart();
nsCOMPtr<nsIEventTarget> mIOThread; // Set in AsyncOpenNative and AsyncOnChannelRedirect, modified in // DoStopSession on IO thread (.forget()). Probably ok...
nsCOMPtr<nsIHttpChannelInternal> mChannel;
nsCOMPtr<nsIHttpChannel> mHttpChannel;
nsCOMPtr<nsICancelable> mCancelable MOZ_GUARDED_BY(mMutex); // Mainthread only
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback; // Set on Mainthread during AsyncOpen, used on IO thread and Mainthread
nsCOMPtr<nsIRandomGenerator> mRandomGenerator;
nsCString mHashedSecret; // MainThread only
// Used as key for connection managment: Initially set to hostname from URI, // then to IP address (unless we're leaving DNS resolution to a proxy server) // MainThread only
nsCString mAddress;
nsCString mPath;
int32_t mPort; // WS server port // Secondary key for the connection queue. Used by nsWSAdmissionManager.
nsCString mOriginSuffix; // MainThread only
// Used for off main thread access to the URI string. // Set on MainThread in AsyncOpenNative, used on TargetThread and IO thread
nsCString mHost;
nsString mEffectiveURL;
// Set on MainThread before multithread use, used on IO thread, cleared on // IOThread
nsCOMPtr<nsISocketTransport> mTransport;
nsCOMPtr<nsIAsyncInputStream> mSocketIn;
nsCOMPtr<nsIAsyncOutputStream> mSocketOut;
RefPtr<WebSocketConnectionBase> mConnection;
// Only used on IO Thread (accessed when known-to-be-null in DoStopSession // on MainThread before mDataStarted)
nsCOMPtr<nsITimer> mCloseTimer; // set in AsyncOpenInternal on MainThread, used on IO thread. // No multithread use before it's set, no changes after that.
uint32_t mCloseTimeout; /* milliseconds */
nsCOMPtr<nsITimer> mOpenTimer; /* Mainthread only */
uint32_t mOpenTimeout; /* milliseconds, MainThread only */
wsConnectingState mConnecting; /* 0 if not connecting, MainThread only */ // Set on MainThread, deleted on MainThread, used on MainThread or // IO Thread (in DoStopSession). Mutex required to access off-main-thread.
nsCOMPtr<nsITimer> mReconnectDelayTimer MOZ_GUARDED_BY(mMutex);
// Only touched on IOThread (DoStopSession reads it on MainThread if // we haven't connected yet (mDataStarted==false), and it's always null // until mDataStarted=true)
nsCOMPtr<nsITimer> mPingTimer;
// Created in DoStopSession on IO thread (mDataStarted=true), accessed // only from IO Thread
nsCOMPtr<nsITimer> mLingeringCloseTimer; conststatic int32_t kLingeringCloseTimeout = 1000; conststatic int32_t kLingeringCloseThreshold = 50;
int32_t
mMaxConcurrentConnections; // only used in AsyncOpenNative on MainThread
// Set on MainThread in AsyncOpenNative; then used on IO thread
uint64_t mInnerWindowID;
// following members are accessed only on the main thread
uint32_t mGotUpgradeOK : 1;
uint32_t mRecvdHttpUpgradeTransport : 1;
uint32_t : 0; // ensure these aren't mixed with the next set
// following members are accessed only on the IO thread
uint32_t mPingOutstanding : 1;
uint32_t mReleaseOnTransmit : 1;
uint32_t : 0;
Atomic<bool> mDataStarted; // All changes to mRequestedClose happen under mutex, but since it's atomic, // it can be read anywhere without a lock
Atomic<bool> mRequestedClose; // mServer/ClientClosed are only modified on IOThread
Atomic<bool> mClientClosed;
Atomic<bool> mServerClosed; // All changes to mStopped happen under mutex, but since it's atomic, it // can be read anywhere without a lock
Atomic<bool> mStopped;
Atomic<bool> mCalledOnStop;
Atomic<bool> mTCPClosed;
Atomic<bool> mOpenedHttpChannel;
Atomic<bool> mIncrementedSessionCount;
Atomic<bool> mDecrementedSessionCount;
int32_t mMaxMessageSize; // set on MainThread in AsyncOpenNative, read on IO // thread // Set on IOThread, or on MainThread before mDataStarted. Used on IO Thread // (after mDataStarted)
nsresult mStopOnClose;
uint16_t mServerCloseCode; // only used on IO thread
nsCString mServerCloseReason; // only used on IO thread
uint16_t mScriptCloseCode MOZ_GUARDED_BY(mMutex);
nsCString mScriptCloseReason MOZ_GUARDED_BY(mMutex);
// These are for the read buffers conststatic uint32_t kIncomingBufferInitialSize = 16 * 1024; // We're ok with keeping a buffer this size or smaller around for the life of // the websocket. If a particular message needs bigger than this we'll // increase the buffer temporarily, then drop back down to this size. conststatic uint32_t kIncomingBufferStableSize = 128 * 1024;
// Set at creation, used/modified only on IO thread
uint8_t* mFramePtr;
uint8_t* mBuffer;
uint8_t mFragmentOpcode;
uint32_t mFragmentAccumulator;
uint32_t mBuffered;
uint32_t mBufferSize;
// These are for the send buffers conststatic int32_t kCopyBreak = 1000;
// Only used on IO thread
OutboundMessage* mCurrentOut;
uint32_t mCurrentOutSent;
nsDeque<OutboundMessage> mOutgoingMessages;
nsDeque<OutboundMessage> mOutgoingPingMessages;
nsDeque<OutboundMessage> mOutgoingPongMessages;
uint32_t mHdrOutToSend;
uint8_t* mHdrOut;
uint8_t mOutHeader[kCopyBreak + 16]{0};
// Set on MainThread in OnStartRequest (before mDataStarted), or in // HandleExtensions() or OnTransportAvailableInternal(),used on IO Thread // (after mDataStarted), cleared in DoStopSession on IOThread or on // MainThread (if mDataStarted == false).
Mutex mCompressorMutex;
UniquePtr<PMCECompression> mPMCECompressor MOZ_GUARDED_BY(mCompressorMutex);
// Used by EnsureHdrOut, which isn't called anywhere
uint32_t mDynamicOutputSize;
uint8_t* mDynamicOutput; // Set on creation and AsyncOpen, read on both threads
Atomic<bool> mPrivateBrowsing;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.