summaryrefslogtreecommitdiff
path: root/js/net.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/net.ts')
-rw-r--r--js/net.ts108
1 files changed, 54 insertions, 54 deletions
diff --git a/js/net.ts b/js/net.ts
index aecff1fde..0b56a4c30 100644
--- a/js/net.ts
+++ b/js/net.ts
@@ -27,46 +27,22 @@ export interface Listener {
addr(): Addr;
}
-class ListenerImpl implements Listener {
- constructor(readonly rid: number) {}
-
- async accept(): Promise<Conn> {
- const builder = flatbuffers.createBuilder();
- msg.Accept.startAccept(builder);
- msg.Accept.addRid(builder, this.rid);
- const inner = msg.Accept.endAccept(builder);
- const baseRes = await dispatch.sendAsync(builder, msg.Any.Accept, inner);
- assert(baseRes != null);
- assert(msg.Any.NewConn === baseRes!.innerType());
- const res = new msg.NewConn();
- assert(baseRes!.inner(res) != null);
- return new ConnImpl(res.rid(), res.remoteAddr()!, res.localAddr()!);
- }
-
- close(): void {
- close(this.rid);
- }
-
- addr(): Addr {
- return notImplemented();
- }
+enum ShutdownMode {
+ // See http://man7.org/linux/man-pages/man2/shutdown.2.html
+ // Corresponding to SHUT_RD, SHUT_WR, SHUT_RDWR
+ Read = 0,
+ Write,
+ ReadWrite // unused
}
-export interface Conn extends Reader, Writer, Closer {
- /** The local address of the connection. */
- localAddr: string;
- /** The remote address of the connection. */
- remoteAddr: string;
- /** The resource ID of the connection. */
- rid: number;
- /** Shuts down (`shutdown(2)`) the reading side of the TCP connection. Most
- * callers should just use `close()`.
- */
- closeRead(): void;
- /** Shuts down (`shutdown(2)`) the writing side of the TCP connection. Most
- * callers should just use `close()`.
- */
- closeWrite(): void;
+function shutdown(rid: number, how: ShutdownMode): void {
+ const builder = flatbuffers.createBuilder();
+ msg.Shutdown.startShutdown(builder);
+ msg.Shutdown.addRid(builder, rid);
+ msg.Shutdown.addHow(builder, how);
+ const inner = msg.Shutdown.endShutdown(builder);
+ const baseRes = dispatch.sendSync(builder, msg.Any.Shutdown, inner);
+ assert(baseRes == null);
}
class ConnImpl implements Conn {
@@ -103,22 +79,46 @@ class ConnImpl implements Conn {
}
}
-enum ShutdownMode {
- // See http://man7.org/linux/man-pages/man2/shutdown.2.html
- // Corresponding to SHUT_RD, SHUT_WR, SHUT_RDWR
- Read = 0,
- Write,
- ReadWrite // unused
+class ListenerImpl implements Listener {
+ constructor(readonly rid: number) {}
+
+ async accept(): Promise<Conn> {
+ const builder = flatbuffers.createBuilder();
+ msg.Accept.startAccept(builder);
+ msg.Accept.addRid(builder, this.rid);
+ const inner = msg.Accept.endAccept(builder);
+ const baseRes = await dispatch.sendAsync(builder, msg.Any.Accept, inner);
+ assert(baseRes != null);
+ assert(msg.Any.NewConn === baseRes!.innerType());
+ const res = new msg.NewConn();
+ assert(baseRes!.inner(res) != null);
+ return new ConnImpl(res.rid(), res.remoteAddr()!, res.localAddr()!);
+ }
+
+ close(): void {
+ close(this.rid);
+ }
+
+ addr(): Addr {
+ return notImplemented();
+ }
}
-function shutdown(rid: number, how: ShutdownMode) {
- const builder = flatbuffers.createBuilder();
- msg.Shutdown.startShutdown(builder);
- msg.Shutdown.addRid(builder, rid);
- msg.Shutdown.addHow(builder, how);
- const inner = msg.Shutdown.endShutdown(builder);
- const baseRes = dispatch.sendSync(builder, msg.Any.Shutdown, inner);
- assert(baseRes == null);
+export interface Conn extends Reader, Writer, Closer {
+ /** The local address of the connection. */
+ localAddr: string;
+ /** The remote address of the connection. */
+ remoteAddr: string;
+ /** The resource ID of the connection. */
+ rid: number;
+ /** Shuts down (`shutdown(2)`) the reading side of the TCP connection. Most
+ * callers should just use `close()`.
+ */
+ closeRead(): void;
+ /** Shuts down (`shutdown(2)`) the writing side of the TCP connection. Most
+ * callers should just use `close()`.
+ */
+ closeWrite(): void;
}
/** Listen announces on the local network address.
@@ -197,8 +197,8 @@ export async function dial(network: Network, address: string): Promise<Conn> {
/** **RESERVED** */
export async function connect(
- network: Network,
- address: string
+ _network: Network,
+ _address: string
): Promise<Conn> {
return notImplemented();
}