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

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