W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2010

[whatwg] WebSockets: why boolean return value for send()?

From: Simon Pieters <simonp@opera.com>
Date: Thu, 15 Apr 2010 09:33:20 +0200
Message-ID: <op.va60luzzidj3kv@simon-pieterss-macbook.local>
WebSocket send():

[[
The send(data) method transmits data using the connection. ... If the  
connection is established, and the string has no unpaired surrogates, and  
the WebSocket closing handshake has not yet started, then the user agent  
must send data using the WebSocket. If the data cannot be sent, e.g.  
because it would need to be buffered but the buffer is full, the user  
agent must close the WebSocket connection. The method must then return  
true if the connection is still established (and the data was queued or  
sent successfully), or false if the connection is closing or closed (e.g.  
because the user agent just had a buffer overflow and failed to send the  
data, or because the WebSocket closing handshake has started).
]]

Why does send() have a boolean return value? What problem does it solve?

It seems to me that we don't want send() to wait with returning until data  
has been sent over the network, or until the connection has been closed.  
If the script wants to check if the connection is closing or closed, it  
can read readyState instead of reading the return value of send(). If a  
script wants to check if the data was sent, it can read bufferedAmount or  
let the server respond.

As I see it, the boolean return value of send() is imposing implementation  
complexity and slowness in script execution without solving any problem.  
If I've missed something, please explain. Otherwise, I think send() should  
just update bufferedAmount and have an early void return and do the  
sending or closing connection async.

-- 
Simon Pieters
Opera Software
Received on Thursday, 15 April 2010 00:33:20 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:22 UTC