Skip to content

Commit

Permalink
[giow] (0) WebSocket: Add support for close codes and reasons
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.whatwg.org/webapps@6154 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed May 27, 2011
1 parent 822491d commit 5227edb
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 132 deletions.
127 changes: 74 additions & 53 deletions complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -60437,7 +60437,7 @@ <h3 id=windows><span class=secno>6.1 </span>Browsing contexts</h3>
<code><a href=#about:blank>about:blank</a></code> <code><a href=#document>Document</a></code> to another, with
<a href=#replacement-enabled>replacement enabled</a>. Second, a <code><a href=#document>Document</a></code>
can end up being reused for several <code><a href=#window>Window</a></code> objects when
the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> methos is
the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> method is
used, such that the mapping is then 1-to-many.</p>

<p class=note>A <code><a href=#document>Document</a></code> does not necessarily have a
Expand Down Expand Up @@ -64367,12 +64367,15 @@ <h4 id=unloading-documents><span class=secno>6.5.10 </span>Unloading documents</
</ol><p>This specification defines the following <dfn id=unloading-document-cleanup-steps>unloading document
cleanup steps</dfn>. Other specifications can define more.</p>

<ol><li><p><span>Close the WebSocket connection</span> of any
<ol><li><p><span>Start the WebSocket closing handshake</span> of any
<code><a href=#websocket>WebSocket</a></code> objects that were created by the <code title=dom-WebSocket><a href=#dom-websocket>WebSocket()</a></code> constructor visible on the
<code><a href=#document>Document</a></code>'s <code><a href=#window>Window</a></code> object. If this
affected any <code><a href=#websocket>WebSocket</a></code> objects, the set
<code><a href=#document>Document</a></code>'s <var title=concept-document-salvageable>salvageable</var> state to
false.
<code><a href=#document>Document</a></code>'s <code><a href=#window>Window</a></code> object, with the status
code<!--CLOSE CODE--> set to 1001. If this affected any
<code><a href=#websocket>WebSocket</a></code> objects, the set <code><a href=#document>Document</a></code>'s
<var title=concept-document-salvageable>salvageable</var> state
to false.


</li>

<li><p>If the <code><a href=#document>Document</a></code>'s <var title=concept-document-salvageable>salvageable</var> state is
Expand Down Expand Up @@ -78836,7 +78839,7 @@ <h4 id=the-websocket-interface><span class=secno>11.3.2 </span>The <code><a href
attribute <a href=#function>Function</a> <a href=#handler-websocket-onerror title=handler-WebSocket-onerror>onerror</a>;
attribute <a href=#function>Function</a> <a href=#handler-websocket-onclose title=handler-WebSocket-onclose>onclose</a>;
readonly attribute DOMString <a href=#dom-websocket-protocol title=dom-WebSocket-protocol>protocol</a>;
void <a href=#dom-websocket-close title=dom-WebSocket-close>close</a>();
void <a href=#dom-websocket-close title=dom-WebSocket-close>close</a>(in optional unsigned short code, in optional DOMString reason);

// messaging
attribute <a href=#function>Function</a> <a href=#handler-websocket-onmessage title=handler-WebSocket-onmessage>onmessage</a>;
Expand Down Expand Up @@ -78982,74 +78985,91 @@ <h4 id=the-websocket-interface><span class=secno>11.3.2 </span>The <code><a href
to perform subprotocol negotiation.</p>

<p>The <dfn id=dom-websocket-close title=dom-WebSocket-close><code>close()</code></dfn>
method must run the first matching steps from the following list:</p>
method must run the following steps:</p>

<dl class=switch><dt>If the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code>
attribute is in the <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2) or <code title=dom-WebSocket-CLOSED><a href=#dom-websocket-closed>CLOSED</a></code> (3) state</dt>
<ol><li><p>If the method's first argument is present but is not an
integer equal to 1000 or in the range 3000 to 4999, throw an
<code><a href=#invalid_access_err>INVALID_ACCESS_ERR</a></code> exception and abort these
steps.</li>

<dd>
<li><p>Run the first matching steps from the following list:</p>

<p>Do nothing.</p>
<dl class=switch><dt>If the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code>
attribute is in the <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2) or <code title=dom-WebSocket-CLOSED><a href=#dom-websocket-closed>CLOSED</a></code> (3) state</dt>

<p class=note>The connection is already closing or is already
closed. If it has not already, a <code title=event-close>close</code> event will eventually fire <a href=#closeWebSocket>as described below</a>.</p>
<dd>

</dd>
<p>Do nothing.</p>

<p class=note>The connection is already closing or is already
closed. If it has not already, a <code title=event-close>close</code> event will eventually fire <a href=#closeWebSocket>as described below</a>.</p>

<dt>If the WebSocket connection is not yet <span title="WebSocket
connection is established">established</span> <a href=#refsWSP>[WSP]</a></dt>
</dd>

<dd>

<p><span>Fail the WebSocket connection</span> and set the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's
value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2).
<a href=#refsWSP>[WSP]</a></p>
<dt>If the WebSocket connection is not yet <span title="WebSocket
connection is established">established</span> <a href=#refsWSP>[WSP]</a></dt>

<p class=note>The "<span>fail the WebSocket connection</span>"
algorithm invokes the "<span>close the WebSocket
connection</span>" algorithm, which then establishes that the
"<span>WebSocket connection is closed</span>", which fires the
<code title=event-close>close</code> event <a href=#closeWebSocket>as described below</a>.</p>
<dd>

</dd>
<p><span>Fail the WebSocket connection</span> and set the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's
value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2).
<a href=#refsWSP>[WSP]</a></p>

<p class=note>The "<span>fail the WebSocket connection</span>"
algorithm invokes the "<span>close the WebSocket
connection</span>" algorithm, which then establishes that the
"<span>WebSocket connection is closed</span>", which fires the
<code title=event-close>close</code> event <a href=#closeWebSocket>as described below</a>.</p>

<dt>If the WebSocket closing handshake has not yet been <span title="the WebSocket closing handshake has
started">started</span> <a href=#refsWSP>[WSP]</a></dt>
</dd>

<dd>

<p><span>Start the WebSocket closing handshake</span> and set the
<code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code>
attribute's value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2). <a href=#refsWSP>[WSP]</a></p>
<dt>If the WebSocket closing handshake has not yet been <span title="the WebSocket closing handshake has
started">started</span> <a href=#refsWSP>[WSP]</a></dt>

<p class=note>The "<span>start the WebSocket closing
handshake</span>" algorithm eventually invokes the "<span>close
the WebSocket connection</span>" algorithm, which then establishes
that the "<span>WebSocket connection is closed</span>", which
fires the <code title=event-close>close</code> event <a href=#closeWebSocket>as described below</a>.</p>
<dd>

</dd>
<p><span>Start the WebSocket closing handshake</span> and set the
<code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code>
attribute's value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2). <a href=#refsWSP>[WSP]</a></p>

<p>If the first argument is present, then the status
code<!--CLOSE CODE--> to use in the WebSocket Close message must
be the integer given by the first argument. <a href=#refsWSP>[WSP]</a></p>

<dt>Otherwise</dt>
<p>If the second argument is also present, then it must be
encoded as UTF-8 and provided in the Close message after the
status code<!--CLOSE CODE-->. <a href=#refsWSP>[WSP]</a></p>

<dd>
<p class=note>The "<span>start the WebSocket closing
handshake</span>" algorithm eventually invokes the "<span>close
the WebSocket connection</span>" algorithm, which then establishes
that the "<span>WebSocket connection is closed</span>", which
fires the <code title=event-close>close</code> event <a href=#closeWebSocket>as described below</a>.</p>

<p>Set the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's
value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code>
(2).</p>
</dd>

<p class=note><span>The WebSocket closing handshake has
started</span>, and will eventually invokethe "<span>close the
WebSocket connection</span>" algorithm, which will establish that
the "<span>WebSocket connection is closed</span>", and thus the
<code title=event-close>close</code> event will fire, <a href=#closeWebSocket>as described below</a>.</p>

</dd>
<dt>Otherwise</dt>

<dd>

<p>Set the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's
value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code>
(2).</p>

<p class=note><span>The WebSocket closing handshake has
started</span>, and will eventually invokethe "<span>close the
WebSocket connection</span>" algorithm, which will establish that
the "<span>WebSocket connection is closed</span>", and thus the
<code title=event-close>close</code> event will fire, <a href=#closeWebSocket>as described below</a>.</p>

</dd>

</dl></li>

</dl><hr><p>The <dfn id=dom-websocket-bufferedamount title=dom-WebSocket-bufferedAmount><code>bufferedAmount</code></dfn>
</ol><hr><p>The <dfn id=dom-websocket-bufferedamount title=dom-WebSocket-bufferedAmount><code>bufferedAmount</code></dfn>
attribute must return the number of bytes of UTF-8 text that have
been queued using <code title=dom-WebSocket-send><a href=#dom-websocket-send>send()</a></code> but
that, as of the last time the <a href=#event-loop>event loop</a> started
Expand Down Expand Up @@ -79360,8 +79380,9 @@ <h5 id=garbage-collection-1><span class=secno>11.3.3.2 </span>Garbage collection
collected. <a href=#refsWSP>[WSP]</a></p>

<p>If a <code><a href=#websocket>WebSocket</a></code> object is garbage collected while its
connection is still open, the user agent must <span>close the
WebSocket connection</span>. <a href=#refsWSP>[WSP]</a></p>
connection is still open, the user agent must <span>start the
WebSocket closing handshake</span>, with no status code<!--CLOSE
CODE--> for the Close message. <a href=#refsWSP>[WSP]</a></p>



Expand Down
19 changes: 11 additions & 8 deletions index
Original file line number Diff line number Diff line change
Expand Up @@ -60457,7 +60457,7 @@ _:n2 hcard:adr%20street-address "Avenue Q" ;
<code><a href=#about:blank>about:blank</a></code> <code><a href=#document>Document</a></code> to another, with
<a href=#replacement-enabled>replacement enabled</a>. Second, a <code><a href=#document>Document</a></code>
can end up being reused for several <code><a href=#window>Window</a></code> objects when
the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> methos is
the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> method is
used, such that the mapping is then 1-to-many.</p>

<p class=note>A <code><a href=#document>Document</a></code> does not necessarily have a
Expand Down Expand Up @@ -64387,15 +64387,18 @@ State: &lt;OUTPUT NAME=I&gt;1&lt;/OUTPUT&gt; &lt;INPUT VALUE="Increment" TYPE=BU
</ol><p>This specification defines the following <dfn id=unloading-document-cleanup-steps>unloading document
cleanup steps</dfn>. Other specifications can define more.</p>

<ol><li><p><span>Close the WebSocket connection</span> of any
<ol><li><p><span>Start the WebSocket closing handshake</span> of any
<code>WebSocket</code> objects that were created by the <code title=dom-WebSocket>WebSocket()</code> constructor visible on the
<code><a href=#document>Document</a></code>'s <code><a href=#window>Window</a></code> object. If this
affected any <code>WebSocket</code> objects, the set
<code><a href=#document>Document</a></code>'s <var title=concept-document-salvageable>salvageable</var> state to
false.

<code><a href=#document>Document</a></code>'s <code><a href=#window>Window</a></code> object, with the status
code<!--CLOSE CODE--> set to 1001. If this affected any
<code>WebSocket</code> objects, the set <code><a href=#document>Document</a></code>'s
<var title=concept-document-salvageable>salvageable</var> state
to false.


<a href=#refsWEBSOCKET>[WEBSOCKET]</a>



</li>

<li><p>If the <code><a href=#document>Document</a></code>'s <var title=concept-document-salvageable>salvageable</var> state is
Expand Down
Loading

0 comments on commit 5227edb

Please sign in to comment.