[webkit-dev] Adding WebSocket closing handshake and CloseEvent

Yuta Kitamura yutak at chromium.org
Wed May 11 06:35:25 PDT 2011

Hi WebKit folks,

I would like to propose adding the following features to WebCore:
- https://bugs.webkit.org/show_bug.cgi?id=35573 WebSocket CloseEvent
- https://bugs.webkit.org/show_bug.cgi?id=35721 WebSocket closing handshake

Actually, these patches were originally posted almost a half year ago, but
by some misfortune they were left unreviewed for a long time. Now I'm trying
to resurrect ancient patches and put these features in WebCore.

Patches are ready for review. Comments and reviews are highly appreciated.


Background and details:

Hixie's WebSocket protocol draft 76 (*1) and WebSocket API (*2) was
published almost a year ago, and our current WebSocket implementation is
supposed to be on this version. These two patches are the remaining pieces
that are not implemeneted yet.

(*1) http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
(*2) http://dev.w3.org/html5/websockets/ (Note: this has been updated
recently and a couple of attributes have been added to CloseEvent in
response to recent updates in protocol draft which we do not support yet.
Thus the above patch does not contain these new attributes (yet).)

* https://bugs.webkit.org/show_bug.cgi?id=35573 CloseEvent

This patch defines a new event called "CloseEvent" and replaces existing use
of "Event" with it. The new CloseEvent has the "wasClean" attribute, which
indicates whether the connection was closed cleanly.

* https://bugs.webkit.org/show_bug.cgi?id=35721 Closing handshake

This introduces a new closing procedure called "closing handshake". In
brief, it works like the following: if a peer (a client or a server) wants
to close the connection, it sends a "close frame" (two-byte sequence "0xFF
0x00"). If a peer receives such a frame, it must send the same frame back to
the other side. When it has completed this exchange, the closing handshake
has done and it can close the underlying socket.

More details:

The main benefit of the closing handshake is that we can avoid so-called
"RST hazard". When an endpoint tries to close the connection with unread
data in its kernel buffer, the TCP stack may send a TCP RST packet which may
cause some problems. We can avoid this by explicitly sending a close frame
as an "end of stream" marker.

Firefox and Opera already have both features. I think they do no harm if we
add these now.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20110511/531bb062/attachment.html>

More information about the webkit-dev mailing list