mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 748766 - Only count connected websockets toward max-websocket limit. r=mcmanus
This commit is contained in:
parent
6227c72e6a
commit
82550caf75
@ -694,6 +694,8 @@ WebSocketChannel::WebSocketChannel() :
|
||||
mOpenRunning(0),
|
||||
mChannelWasOpened(0),
|
||||
mDataStarted(0),
|
||||
mIncrementedSessionCount(0),
|
||||
mDecrementedSessionCount(0),
|
||||
mMaxMessageSize(PR_INT32_MAX),
|
||||
mStopOnClose(NS_OK),
|
||||
mServerCloseCode(CLOSE_ABNORMAL),
|
||||
@ -715,9 +717,6 @@ WebSocketChannel::WebSocketChannel() :
|
||||
if (!sWebSocketAdmissions)
|
||||
sWebSocketAdmissions = new nsWSAdmissionManager();
|
||||
|
||||
// The active session limit is enforced in AsyncOpen()
|
||||
sWebSocketAdmissions->IncrementSessionCount();
|
||||
|
||||
mFramePtr = mBuffer = static_cast<PRUint8 *>(moz_xmalloc(mBufferSize));
|
||||
}
|
||||
|
||||
@ -725,9 +724,6 @@ WebSocketChannel::~WebSocketChannel()
|
||||
{
|
||||
LOG(("WebSocketChannel::~WebSocketChannel() %p\n", this));
|
||||
|
||||
if (sWebSocketAdmissions)
|
||||
sWebSocketAdmissions->DecrementSessionCount();
|
||||
|
||||
// this stop is a nop if the normal connect/close is followed
|
||||
StopSession(NS_ERROR_UNEXPECTED);
|
||||
NS_ABORT_IF_FALSE(!mOpenRunning && !mOpenBlocked, "op");
|
||||
@ -1556,6 +1552,8 @@ WebSocketChannel::CleanupConnection()
|
||||
mTransport->Close(NS_BASE_STREAM_CLOSED);
|
||||
mTransport = nsnull;
|
||||
}
|
||||
|
||||
DecrementSessionCount();
|
||||
}
|
||||
|
||||
void
|
||||
@ -1711,6 +1709,28 @@ WebSocketChannel::ReleaseSession()
|
||||
StopSession(NS_OK);
|
||||
}
|
||||
|
||||
void
|
||||
WebSocketChannel::IncrementSessionCount()
|
||||
{
|
||||
if (!mIncrementedSessionCount) {
|
||||
sWebSocketAdmissions->IncrementSessionCount();
|
||||
mIncrementedSessionCount = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
WebSocketChannel::DecrementSessionCount()
|
||||
{
|
||||
// Make sure we decrement session count only once, and only if we incremented it.
|
||||
// This code is thread-safe: sWebSocketAdmissions->DecrementSessionCount is
|
||||
// atomic, and mIncrementedSessionCount/mDecrementedSessionCount are set at
|
||||
// times when they'll never be a race condition for checking/setting them.
|
||||
if (mIncrementedSessionCount && !mDecrementedSessionCount) {
|
||||
sWebSocketAdmissions->DecrementSessionCount();
|
||||
mDecrementedSessionCount = 1;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
WebSocketChannel::HandleExtensions()
|
||||
{
|
||||
@ -2308,7 +2328,14 @@ WebSocketChannel::AsyncOpen(nsIURI *aURI,
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return ApplyForAdmission();
|
||||
rv = ApplyForAdmission();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// Session setup OK, so count it.
|
||||
IncrementSessionCount();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -128,6 +128,8 @@ private:
|
||||
void AbortSession(nsresult reason);
|
||||
void ReleaseSession();
|
||||
void CleanupConnection();
|
||||
void IncrementSessionCount();
|
||||
void DecrementSessionCount();
|
||||
|
||||
void EnsureHdrOut(PRUint32 size);
|
||||
void ApplyMask(PRUint32 mask, PRUint8 *data, PRUint64 len);
|
||||
@ -185,6 +187,8 @@ private:
|
||||
PRUint32 mOpenRunning : 1;
|
||||
PRUint32 mChannelWasOpened : 1;
|
||||
PRUint32 mDataStarted : 1;
|
||||
PRUint32 mIncrementedSessionCount : 1;
|
||||
PRUint32 mDecrementedSessionCount : 1;
|
||||
|
||||
PRInt32 mMaxMessageSize;
|
||||
nsresult mStopOnClose;
|
||||
|
Loading…
Reference in New Issue
Block a user