diff --git a/index.bs b/index.bs index 660e172..8a39b2d 100644 --- a/index.bs +++ b/index.bs @@ -63,7 +63,7 @@ const tls_socket = new TLSSocket({ key: '...', cert: '...' }); tls_socket.connect(); -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/). +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/).

Socket

@@ -94,8 +94,10 @@ interface Socket { readonly attribute ReadableStream readable; readonly attribute WritableStream writable; + readonly attribute Promise<undefined> opened; + readonly attribute Promise<undefined> closed; - Promise<undefined> close(); + Promise<undefined> close(optional any reason); [NewObject] Socket startTls(); }; @@ -154,6 +156,12 @@ The {{writable}} attribute is a {{WritableStream}} which sends data to the serve +

opened

+ +The {{opened}} attribute is a promise that is resolved when the socket connection has been +successfully established, or is rejected if the connection fails. For sockets use secure-transport, +the resolution of the {{opened}} promise indicates the completion of the secure handshake. +

closed

The {{closed}} attribute is a promise which can be used to keep track of the socket state. It gets resolved under the @@ -165,7 +173,7 @@ following circumstances:
- The current Cloudflare Workers implementation behaves as described above, specifically the + The current Cloudflare Workers implementation behaves as described above, specifically the ReadableStream needs to be read until completion for the `closed` promise to resolve, if the ReadableStream is not read then even if the server closes the connection the `closed` promise will not resolve. @@ -184,10 +192,14 @@ Cancelling the socket's ReadableStream and closing the socket's WritableStream d

Methods

-

close()

+

close(optional any reason)

The {{close()}} method closes the socket and its underlying connection. It returns the same promise as the {{closed}} attribute. +When called, the {{ReadableStream}} and {{WritableStream}} associated with the {{Socket}} will +be canceled and aborted, respectively. If the {{reason}} argument is specified, the {{reason}} +will be passed on to both the {{ReadableStream}} and {{WritableStream}}. +

startTls()

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). @@ -284,7 +296,7 @@ At any point during the creation of the {{Socket}} instance, `connect` may throw {{secureTransport}} member
- The secure transport mode to use. + The secure transport mode to use.
{{off}}
A connection is established in plain text.