You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.bs
+36-2Lines changed: 36 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -89,12 +89,18 @@ A basic example of using connect with an echo server.
89
89
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.
90
90
91
91
<pre class="idl">
92
+
[Exposed=*]
93
+
dictionary SocketInfo {
94
+
DOMString remoteAddress = null;
95
+
DOMString localAddress = null;
96
+
};
97
+
92
98
[Exposed=*]
93
99
interface Socket {
94
100
readonly attribute ReadableStream readable;
95
101
readonly attribute WritableStream writable;
96
102
97
-
readonly attribute Promise<undefined> opened;
103
+
readonly attribute Promise<SocketInfo> opened;
98
104
99
105
readonly attribute Promise<undefined> closed;
100
106
Promise<undefined> close(optional any reason);
@@ -162,6 +168,11 @@ The {{opened}} attribute is a promise that is resolved when the socket connectio
162
168
successfully established, or is rejected if the connection fails. For sockets use secure-transport,
163
169
the resolution of the {{opened}} promise indicates the completion of the secure handshake.
164
170
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
+
165
176
<h4 id="closed-attribute">closed</h4>
166
177
167
178
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 {
200
211
be canceled and aborted, respectively. If the {{reason}} argument is specified, the {{reason}}
201
212
will be passed on to both the {{ReadableStream}} and {{WritableStream}}.
202
213
214
+
If the {{opened}} promise is still pending, it will be rejected with the {{reason}}.
215
+
203
216
<h4 id="starttls-method">startTls()</h4>
204
217
205
218
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:
275
288
276
289
<ol>
277
290
<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.
278
293
<li>The created {{Socket}} instance is returned immediately in a <i>pending</i> state.</li>
279
294
<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>
281
297
<li>The instance's {{ReadableStream}} and {{WritableStream}} streams can be used immediately.</li>
282
298
</ol>
283
299
@@ -321,6 +337,24 @@ At any point during the creation of the {{Socket}} instance, `connect` may throw
0 commit comments