Skip to content

Commit 34cb571

Browse files
authored
Add SocketInfo, update opened promise (#19)
* Add SocketInfo, update opened promise The `opened` promise resolves to a `SocketInfo`. `SocketInfo` provides `remoteAddress` and (optionally) `localAddress` * Update index.bs * Update index.bs * Update index.bs
1 parent 1d42a50 commit 34cb571

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

index.bs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,18 @@ A basic example of using connect with an echo server.
8989
The {{Socket}} class is an instance of the [=socket=] concept. It should not be instantiated directly (`new Socket()`), but instead created by calling {{connect()}}. A constructor for {{Socket}} is intentionally not specified, and is left to implementors to create.
9090

9191
<pre class="idl">
92+
[Exposed=*]
93+
dictionary SocketInfo {
94+
DOMString remoteAddress = null;
95+
DOMString localAddress = null;
96+
};
97+
9298
[Exposed=*]
9399
interface Socket {
94100
readonly attribute ReadableStream readable;
95101
readonly attribute WritableStream writable;
96102

97-
readonly attribute Promise&lt;undefined> opened;
103+
readonly attribute Promise&lt;SocketInfo> opened;
98104

99105
readonly attribute Promise&lt;undefined> closed;
100106
Promise&lt;undefined> close(optional any reason);
@@ -162,6 +168,11 @@ The {{opened}} attribute is a promise that is resolved when the socket connectio
162168
successfully established, or is rejected if the connection fails. For sockets use secure-transport,
163169
the resolution of the {{opened}} promise indicates the completion of the secure handshake.
164170

171+
The {{opened}} promise resolves a {{SocketInfo}} dictionary that optionally provides details
172+
about the connection that has been established.
173+
174+
By default, the {{opened}} promise is {{marked as handled}}.
175+
165176
<h4 id="closed-attribute">closed</h4>
166177

167178
The {{closed}} attribute is a promise which can be used to keep track of the socket state. It gets resolved under the
@@ -200,6 +211,8 @@ When called, the {{ReadableStream}} and {{WritableStream}} associated with the {
200211
be canceled and aborted, respectively. If the {{reason}} argument is specified, the {{reason}}
201212
will be passed on to both the {{ReadableStream}} and {{WritableStream}}.
202213

214+
If the {{opened}} promise is still pending, it will be rejected with the {{reason}}.
215+
203216
<h4 id="starttls-method">startTls()</h4>
204217

205218
The {{startTls()}} method enables opportunistic TLS (otherwise known as [StartTLS](https://en.wikipedia.org/wiki/Opportunistic_TLS)) which is a requirement for some protocols (primarily postgres/mysql and other DB protocols).
@@ -275,9 +288,12 @@ The {{connect()}} method performs the following steps:
275288

276289
<ol>
277290
<li>New {{Socket}} instance is created with each of its attributes initialised immediately.</li>
291+
<li>The socket's {{opened}} promise is set to [=a new promise=]. Set |opened|.\[[PromiseIsHandled]] to true.
292+
<li>The socket's {{closed}} promise is set to [=a new promise=]. Set |closed|.\[[PromiseIsHandled]] to true.
278293
<li>The created {{Socket}} instance is returned immediately in a <i>pending</i> state.</li>
279294
<li>A connection is established to the specified {{SocketAddress}} asynchronously.</li>
280-
<li>If the connection fails for any reason, the socket's {{closed}} promise is rejected with a [=SocketError=] describing why the connection failed.</li>
295+
<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>
296+
<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>
281297
<li>The instance's {{ReadableStream}} and {{WritableStream}} streams can be used immediately.</li>
282298
</ol>
283299

@@ -321,6 +337,24 @@ At any point during the creation of the {{Socket}} instance, `connect` may throw
321337
</dd>
322338
</dl>
323339

340+
<h3 id="socketinfo-dictionary">`SocketInfo` dictionary</h3>
341+
342+
<d1>
343+
<dt>
344+
{{remoteAddress}} member
345+
</dt>
346+
<dd>
347+
Provides the hostname/port combo of the remote peer the {{Socket}} is connected to, for example `"example.com:443"`.
348+
This value may or may not be the same as the address provided to the {{connect()}} method used to create the {{Socket}}.
349+
</dd>
350+
<dt>
351+
{{localAddress}} member
352+
</dt>
353+
<dd>
354+
Optionally provides the hostname/port combo of the local network endpoint, for example `"localhost:12345"`.
355+
</dd>
356+
</d1>
357+
324358
<h3 id="anysocketaddress-type">`AnySocketAddress` type</h3>
325359

326360
<dl>

0 commit comments

Comments
 (0)