From 2235dd795d3cc6c24ff1bdd1bbdcd110b4b0bdfc Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 24 Aug 2019 13:20:48 -0700 Subject: Revert json ops (#2814) * Revert "port more ops to JSON (#2809)" This reverts commit 137f33733d365026903d40e7cde6e34ac6c36dcf. * Revert "port ops to JSON: compiler, errors, fetch, files (#2804)" This reverts commit 79f82cf10ed1dbf91346994250d7311a4d74377a. * Revert "Port rest of os ops to JSON (#2802)" This reverts commit 5b2baa5c990fbeae747e952c5dcd7a5369e950b1. --- js/net.ts | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'js/net.ts') diff --git a/js/net.ts b/js/net.ts index b478ae613..9c3bfbba5 100644 --- a/js/net.ts +++ b/js/net.ts @@ -1,9 +1,8 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { EOF, Reader, Writer, Closer } from "./io"; -import { notImplemented } from "./util"; +import { assert, notImplemented } from "./util"; +import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers"; import { read, write, close } from "./files"; -import * as dispatch from "./dispatch"; -import { sendSync, sendAsync } from "./dispatch_json"; export type Network = "tcp"; // TODO support other types: @@ -37,7 +36,10 @@ enum ShutdownMode { } function shutdown(rid: number, how: ShutdownMode): void { - sendSync(dispatch.OP_SHUTDOWN, { rid, how }); + const builder = flatbuffers.createBuilder(); + const inner = msg.Shutdown.createShutdown(builder, rid, how); + const baseRes = sendSync(builder, msg.Any.Shutdown, inner); + assert(baseRes == null); } class ConnImpl implements Conn { @@ -78,9 +80,14 @@ class ListenerImpl implements Listener { constructor(readonly rid: number) {} async accept(): Promise { - const res = await sendAsync(dispatch.OP_ACCEPT, { rid: this.rid }); - // TODO(bartlomieju): add remoteAddr and localAddr on Rust side - return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!); + const builder = flatbuffers.createBuilder(); + const inner = msg.Accept.createAccept(builder, this.rid); + const baseRes = await 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 { @@ -136,8 +143,16 @@ export interface Conn extends Reader, Writer, Closer { * See `dial()` for a description of the network and address parameters. */ export function listen(network: Network, address: string): Listener { - const rid = sendSync(dispatch.OP_LISTEN, { network, address }); - return new ListenerImpl(rid); + const builder = flatbuffers.createBuilder(); + const network_ = builder.createString(network); + const address_ = builder.createString(address); + const inner = msg.Listen.createListen(builder, network_, address_); + const baseRes = sendSync(builder, msg.Any.Listen, inner); + assert(baseRes != null); + assert(msg.Any.ListenRes === baseRes!.innerType()); + const res = new msg.ListenRes(); + assert(baseRes!.inner(res) != null); + return new ListenerImpl(res.rid()); } /** Dial connects to the address on the named network. @@ -168,9 +183,16 @@ export function listen(network: Network, address: string): Listener { * dial("tcp", ":80") */ export async function dial(network: Network, address: string): Promise { - const res = await sendAsync(dispatch.OP_DIAL, { network, address }); - // TODO(bartlomieju): add remoteAddr and localAddr on Rust side - return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!); + const builder = flatbuffers.createBuilder(); + const network_ = builder.createString(network); + const address_ = builder.createString(address); + const inner = msg.Dial.createDial(builder, network_, address_); + const baseRes = await sendAsync(builder, msg.Any.Dial, 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()!); } /** **RESERVED** */ -- cgit v1.2.3