Skip to content

Commit 89a9de1

Browse files
authored
Merge pull request #26 from wintercg/jasnell-patch-1
2 parents 91376ef + f23540b commit 89a9de1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Diff for: index.bs

+12-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ URL: https://sockets-api.proposal.wintercg.org/
88
Repository: https://github.com/wintercg/proposal-sockets-api
99
Editor: Dominik Picheta, Cloudflare https://cloudflare.com/, [email protected]
1010
Editor: Ethan Arrowood, Vercel https://vercel.com/, [email protected]
11+
Editor: James M Snell, Cloudflare https://cloudflare.com/, [email protected]
1112
Abstract: Sockets API for Non-Browser EcmaScript-based runtimes.
1213
Markup Shorthands: markdown yes
1314
Markup Shorthands: idl yes
@@ -42,12 +43,16 @@ A socket becomes <i>closed</i> when its {{close()}} method is called. A socket c
4243

4344
<h3 id="connect-concept-section">Connect</h3>
4445

46+
<p class="note">The [=connect=] method here is defined in a `sockets` module only for initial implementation purposes. It is imagined that in a finalized standard definition, the [=connect=] would be exposed as a global or within a [=binding object=]</p>
47+
4548
A socket can be constructed using a <dfn export id="connect-concept">connect</dfn> method defined in a `sockets` module (early implementations may use `vendor:sockets` for the module name), or defined on a [=binding object=].
4649

4750
The connect method is the primary mechanism for creating a [=socket=] instance. It instantiates a socket with a resource identifier and some configuration values. It should synchronously return a socket instance in a <i>pending</i> state (or an error should be thrown). The socket will asynchronously <i>connect</i> depending on the implementation.
4851

4952
<h3 id="binding-object-concept">Binding Object</h3>
5053

54+
<p class="note">A [=binding object=] in this context is essentially just an object that exposes a [=connect=] method conformant with this specification. It is anticipated that a runtime may have any number of such objects. This is an area where there is still active discussion on how this should be defined.</p>
55+
5156
The <dfn export>binding object</dfn> defines extra socket `connect` options. The options it contains can modify the
5257
behaviour of the `connect` invoked on it. Some of the options it can define:
5358

@@ -60,7 +65,7 @@ The binding object is the primary mechanism for runtimes to introduce unique beh
6065

6166
<pre highlight="js">
6267
const tls_socket = new TLSSocket({ key: '...', cert: '...' });
63-
tls_socket.connect();
68+
tls_socket.connect("example.com:1234");
6469
</pre>
6570

6671
Additionally, the binding object does not necessarily have to be an instance of a class, nor does it even have to be JavaScript. It can be any mechanism that exposes the {{connect()}} method. Cloudflare achieves this through [environment bindings](https://developers.cloudflare.com/workers/configuration/bindings/).
@@ -114,10 +119,6 @@ The terms {{ReadableStream}} and {{WritableStream}} are defined in [[WHATWG-STRE
114119

115120
<h3 id="attributes">Attributes</h3>
116121

117-
<h4 id="info-attribute">info</h4>
118-
119-
The {{info}} attribute is a {{SocketInfo}} which contains information about the state of the socket.
120-
121122
<h4 id="readable-attribute">readable</h4>
122123

123124
The {{readable}} attribute is a {{ReadableStream}} which receives data from the server the socket is connected to.
@@ -146,9 +147,7 @@ The {{readable}} attribute is a {{ReadableStream}} which receives data from the
146147
</pre>
147148
</div>
148149

149-
The ReadableStream operates in non-byte mode, that is the `type` parameter to the
150-
ReadableStream constructor is not set.
151-
This means the stream's controller is {{ReadableStreamDefaultController}}.
150+
<p class="note">The ReadableStream currently is defined to operate in non-byte mode, that is the `type` parameter to the ReadableStream constructor is not set. This means the stream's controller is {{ReadableStreamDefaultController}}. This, however, should be discussed and may be made configurable. It is reasonable, for instance, to assume that sockets used for most TCP cases would be byte-oriented, while sockets used for messages (e.g. UDP) would not.</p>
152151

153152
<h4 id="writable-attribute">writable</h4>
154153

@@ -254,6 +253,8 @@ The method must fail with an [=SocketError=] if:
254253

255254
<h3 id="socket-error">SocketError</h3>
256255

256+
<p class="note">Arguably, this should be a type of {{DOMException}} rather than {{TypeError}}. More discussion is necessary on the form and structure of socket-related errors.</p>
257+
257258
<dfn export>SocketError</dfn> is an instance of {{TypeError}}. The error message should start with `"SocketError: "`.
258259

259260
<div class="example">
@@ -300,11 +301,11 @@ The {{connect()}} method performs the following steps:
300301
<li>The created {{Socket}} instance is returned immediately in a <i>pending</i> state.</li>
301302
<li>A connection is established to the specified {{SocketAddress}} asynchronously.</li>
302303
<li>Once the connection is established, set |info| to a new {{SocketInfo}}, and [=Resolve=] |opened| with |info|. For a socket using secure transport, the connection is considered to be established once the secure handshake has been completed.</li>
303-
<li>If the connection fails for any reason, the socket's {{closed}} and {{opened}} promises are rejected with a [=SocketError=] describing why the connection failed.</li>
304-
<li>The instance's {{ReadableStream}} and {{WritableStream}} streams can be used immediately.</li>
304+
<li>If the connection fails for any reason, set |error| to a new [=SocketError=] and reject the socket's {{closed}} and {{opened}} promises with |error|. Also, the {{readable}} is canceled with |error| and the {{writable}} is aborted with |error|.</li>
305+
<li>The instance's {{ReadableStream}} and {{WritableStream}} streams can be used immediately but may not actually transmit or receive data until the socket is fully opened.</li>
305306
</ol>
306307

307-
At any point during the creation of the {{Socket}} instance, `connect` may throw a [=SocketError=]. One case where this can happen is if the input address is incorrectly formatted. Errors which occur asynchronously (after the socket instance has been returned) must reject the socket's {{closed}} promise.
308+
At any point during the creation of the {{Socket}} instance, `connect` may throw a [=SocketError=]. One case where this can happen is if the input address is incorrectly formatted.
308309

309310
<div class="note">
310311
The implementation may consider blocking connections to certain hostname/port combinations which can pose a threat of abuse or security vulnerability.

0 commit comments

Comments
 (0)