@@ -211,77 +211,104 @@ class WebSocketChannel : public BaseWebSocketChannel,
211
211
}
212
212
213
213
nsCOMPtr<nsIEventTarget> mIOThread ;
214
+ // Set in AsyncOpenNative and AsyncOnChannelRedirect, modified in
215
+ // DoStopSession on IO thread (.forget()). Probably ok...
214
216
nsCOMPtr<nsIHttpChannelInternal> mChannel ;
215
217
nsCOMPtr<nsIHttpChannel> mHttpChannel ;
218
+
216
219
nsCOMPtr<nsICancelable> mCancelable ;
220
+ // Mainthread only
217
221
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback ;
222
+ // Set on Mainthread during AsyncOpen, used on IO thread and Mainthread
218
223
nsCOMPtr<nsIRandomGenerator> mRandomGenerator ;
219
224
220
- nsCString mHashedSecret ;
225
+ nsCString mHashedSecret ; // MainThread only
221
226
222
227
// Used as key for connection managment: Initially set to hostname from URI,
223
228
// then to IP address (unless we're leaving DNS resolution to a proxy server)
229
+ // MainThread only
224
230
nsCString mAddress ;
225
231
int32_t mPort ; // WS server port
226
232
// Secondary key for the connection queue. Used by nsWSAdmissionManager.
227
- nsCString mOriginSuffix ;
233
+ nsCString mOriginSuffix ; // MainThread only
228
234
229
235
// Used for off main thread access to the URI string.
236
+ // Set on MainThread in AsyncOpenNative, used on TargetThread and IO thread
230
237
nsCString mHost ;
231
238
nsString mEffectiveURL ;
232
239
240
+ // Set on MainThread before multithread use, used on IO thread, cleared on IOThread
233
241
nsCOMPtr<nsISocketTransport> mTransport ;
234
242
nsCOMPtr<nsIAsyncInputStream> mSocketIn ;
235
243
nsCOMPtr<nsIAsyncOutputStream> mSocketOut ;
236
244
RefPtr<WebSocketConnectionBase> mConnection ;
237
245
246
+ // Only used on IO Thread (accessed when known-to-be-null in DoStopSession
247
+ // on MainThread before mDataStarted)
238
248
nsCOMPtr<nsITimer> mCloseTimer ;
249
+ // set in AsyncOpenInternal on MainThread, used on IO thread.
250
+ // No multithread use before it's set, no changes after that.
239
251
uint32_t mCloseTimeout ; /* milliseconds */
240
252
241
- nsCOMPtr<nsITimer> mOpenTimer ;
242
- uint32_t mOpenTimeout ; /* milliseconds */
243
- wsConnectingState mConnecting ; /* 0 if not connecting */
253
+ nsCOMPtr<nsITimer> mOpenTimer ; /* Mainthread only */
254
+ uint32_t mOpenTimeout ; /* milliseconds, MainThread only */
255
+ wsConnectingState mConnecting ; /* 0 if not connecting, MainThread only */
256
+ // Set on MainThread, deleted on either MainThread mainthread, used on
257
+ // MainThread or IO Thread in DoStopSession
244
258
nsCOMPtr<nsITimer> mReconnectDelayTimer ;
245
259
260
+ // Only touched on IOThread (DoStopSession reads it on MainThread if
261
+ // we haven't connected yet (mDataStarted==false), and it's always null
262
+ // until mDataStarted=true)
246
263
nsCOMPtr<nsITimer> mPingTimer ;
247
264
265
+ // Created in DoStopSession on IO thread (mDataStarted=true), accessed
266
+ // only from IO Thread
248
267
nsCOMPtr<nsITimer> mLingeringCloseTimer ;
249
268
const static int32_t kLingeringCloseTimeout = 1000 ;
250
269
const static int32_t kLingeringCloseThreshold = 50 ;
251
270
252
- RefPtr<WebSocketEventService> mService ;
271
+ RefPtr<WebSocketEventService> mService ; // effectively const
253
272
254
- int32_t mMaxConcurrentConnections ;
273
+ int32_t
274
+ mMaxConcurrentConnections ; // only used in AsyncOpenNative on MainThread
255
275
276
+ // Set on MainThread in AsyncOpenNative; then used on IO thread
256
277
uint64_t mInnerWindowID ;
257
278
258
279
// following members are accessed only on the main thread
259
280
uint32_t mGotUpgradeOK : 1 ;
260
281
uint32_t mRecvdHttpUpgradeTransport : 1 ;
261
282
uint32_t mAutoFollowRedirects : 1 ;
262
283
uint32_t mAllowPMCE : 1 ;
263
- uint32_t : 0 ;
284
+ uint32_t : 0 ; // ensure these aren't mixed with the next set
264
285
265
- // following members are accessed only on the socket thread
286
+ // following members are accessed only on the IO thread
266
287
uint32_t mPingOutstanding : 1 ;
267
288
uint32_t mReleaseOnTransmit : 1 ;
268
289
uint32_t : 0 ;
269
290
270
291
Atomic<bool > mDataStarted ;
292
+ // All changes to mRequestedClose happen under mutex, but since it's atomic,
293
+ // it can be read anywhere without a lock
271
294
Atomic<bool > mRequestedClose ;
295
+ // mServer/ClientClosed are only modified on IOThread
272
296
Atomic<bool > mClientClosed ;
273
297
Atomic<bool > mServerClosed ;
298
+ // All changes to mStopped happen under mutex, but since it's atomic, it
299
+ // can be read anywhere without a lock
274
300
Atomic<bool > mStopped ;
275
301
Atomic<bool > mCalledOnStop ;
276
302
Atomic<bool > mTCPClosed ;
277
303
Atomic<bool > mOpenedHttpChannel ;
278
304
Atomic<bool > mIncrementedSessionCount ;
279
305
Atomic<bool > mDecrementedSessionCount ;
280
306
281
- int32_t mMaxMessageSize ;
307
+ int32_t mMaxMessageSize ; // set on MainThread in AsyncOpenNative, read on IO thread
308
+ // Set on IOThread, or on MainThread before mDataStarted. Used on IO Thread (after mDataStarted)
282
309
nsresult mStopOnClose ;
283
- uint16_t mServerCloseCode ;
284
- nsCString mServerCloseReason ;
310
+ uint16_t mServerCloseCode ; // only used on IO thread
311
+ nsCString mServerCloseReason ; // only used on IO thread
285
312
uint16_t mScriptCloseCode ;
286
313
nsCString mScriptCloseReason ;
287
314
@@ -292,6 +319,7 @@ class WebSocketChannel : public BaseWebSocketChannel,
292
319
// increase the buffer temporarily, then drop back down to this size.
293
320
const static uint32_t kIncomingBufferStableSize = 128 * 1024 ;
294
321
322
+ // Set at creation, used/modified only on IO thread
295
323
uint8_t * mFramePtr ;
296
324
uint8_t * mBuffer ;
297
325
uint8_t mFragmentOpcode ;
@@ -302,6 +330,7 @@ class WebSocketChannel : public BaseWebSocketChannel,
302
330
// These are for the send buffers
303
331
const static int32_t kCopyBreak = 1000 ;
304
332
333
+ // Only used on IO thread
305
334
OutboundMessage* mCurrentOut ;
306
335
uint32_t mCurrentOutSent ;
307
336
nsDeque<OutboundMessage> mOutgoingMessages ;
@@ -310,12 +339,20 @@ class WebSocketChannel : public BaseWebSocketChannel,
310
339
uint32_t mHdrOutToSend ;
311
340
uint8_t * mHdrOut ;
312
341
uint8_t mOutHeader [kCopyBreak + 16 ]{0 };
342
+
343
+ // Set on MainThread in OnStartRequest (before mDataStarted), used on IO
344
+ // Thread (after mDataStarted), cleared in DoStopSession on IOThread or
345
+ // on MainThread (if mDataStarted == false)
313
346
UniquePtr<PMCECompression> mPMCECompressor ;
347
+
348
+ // Used by EnsureHdrOut, which isn't called anywhere
314
349
uint32_t mDynamicOutputSize ;
315
350
uint8_t * mDynamicOutput ;
316
- bool mPrivateBrowsing ;
351
+ // Set on creation and AsyncOpen, read on both threads
352
+ Atomic<bool > mPrivateBrowsing ;
317
353
318
- nsCOMPtr<nsIDashboardEventNotifier> mConnectionLogService ;
354
+ nsCOMPtr<nsIDashboardEventNotifier>
355
+ mConnectionLogService ; // effectively const
319
356
320
357
mozilla::Mutex mMutex ;
321
358
};
0 commit comments