[whatwg] WebSocket bufferedAmount includes overhead or not

Jonas Sicking jonas at sicking.cc
Tue Mar 30 23:38:21 PDT 2010


On Tue, Mar 30, 2010 at 9:56 PM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
> On 3/30/10 10:22 AM, Jonas Sicking wrote:
>>
>> Making it implementation dependent is likely to lead to website
>> incompatibilities. Such as:
>>
>> ws = new WebSocket(...);
>> ws.onopen = function() {
>>   ws.send(someString);
>>   if (ws.bufferedAmount>  X) {
>>     doStuff();
>
> Can bufferedAmount not change due to data actually hitting the network
> during the execution of this code?  As in, will all the someString data be
> buffered immediately after that send() call?

I would have expected bufferedAmount to only change as a result of an
event being posted to the main event loop. We generally try to avoid
"racy" variables since people don't expect them. Consider for example

if (ws.bufferedAmount > X) {
  setUpSomeState();
}

try {
  doOtherThings();
}
finally {
  if (ws.bufferedAmount > X) {
    cleanUpState();
  }
}

I'd imagine most JS developers to expect the cleanup to always happen
if the setup did.

/ Jonas



More information about the whatwg mailing list