Skip to content

Commit

Permalink
port more ops to JSON (denoland#2809)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored and ry committed Aug 24, 2019
1 parent 79f82cf commit 137f337
Show file tree
Hide file tree
Showing 26 changed files with 648 additions and 1,155 deletions.
17 changes: 17 additions & 0 deletions cli/deno_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ impl GetErrorKind for ReadlineError {
}
}

impl GetErrorKind for serde_json::error::Error {
fn kind(&self) -> ErrorKind {
use serde_json::error::*;
match self.classify() {
Category::Io => ErrorKind::InvalidInput,
Category::Syntax => ErrorKind::InvalidInput,
Category::Data => ErrorKind::InvalidData,
Category::Eof => ErrorKind::UnexpectedEof,
}
}
}

#[cfg(unix)]
mod unix {
use super::{ErrorKind, GetErrorKind};
Expand Down Expand Up @@ -251,6 +263,11 @@ impl GetErrorKind for dyn AnyError {
.or_else(|| self.downcast_ref::<uri::InvalidUri>().map(Get::kind))
.or_else(|| self.downcast_ref::<url::ParseError>().map(Get::kind))
.or_else(|| self.downcast_ref::<ReadlineError>().map(Get::kind))
.or_else(|| {
self
.downcast_ref::<serde_json::error::Error>()
.map(Get::kind)
})
.or_else(|| unix_error_kind(self))
.unwrap_or_else(|| {
panic!("Can't get ErrorKind for {:?}", self);
Expand Down
223 changes: 0 additions & 223 deletions cli/msg.fbs
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
union Any {
Accept,
Chdir,
Chmod,
Chown,
CopyFile,
CreateWorker,
CreateWorkerRes,
Cwd,
CwdRes,
Dial,
GetRandomValues,
GlobalTimer,
GlobalTimerRes,
GlobalTimerStop,
HostGetMessage,
HostGetMessageRes,
HostGetWorkerClosed,
HostPostMessage,
Kill,
Link,
Listen,
ListenRes,
MakeTempDir,
MakeTempDirRes,
Metrics,
MetricsRes,
Mkdir,
NewConn,
Now,
NowRes,
PermissionRevoke,
Permissions,
PermissionsRes,
Read,
ReadDir,
ReadDirRes,
Expand All @@ -40,25 +17,11 @@ union Any {
ReadlinkRes,
Remove,
Rename,
ReplReadline,
ReplReadlineRes,
ReplStart,
ReplStartRes,
Resources,
ResourcesRes,
Run,
RunRes,
RunStatus,
RunStatusRes,
Seek,
Shutdown,
Stat,
StatRes,
Symlink,
Truncate,
WorkerGetMessage,
WorkerGetMessageRes,
WorkerPostMessage,
Write,
WriteRes,
}
Expand Down Expand Up @@ -159,83 +122,15 @@ table FormatErrorRes {
error: string;
}

// Create worker as host
table CreateWorker {
specifier: string;
include_deno_namespace: bool;
has_source_code: bool;
source_code: string;
}

table CreateWorkerRes {
rid: uint32;
}

table HostGetWorkerClosed {
rid: uint32;
}

// Get message from guest worker as host
table HostGetMessage {
rid: uint32;
}

table HostGetMessageRes {
data: [ubyte];
}

// Post message to guest worker as host
table HostPostMessage {
rid: uint32;
// data passed thru the zero-copy data parameter.
}

// Get message from host as guest worker
table WorkerGetMessage {
unused: int8;
}

table WorkerGetMessageRes {
data: [ubyte];
}

// Post message to host as guest worker
table WorkerPostMessage {
// data passed thru the zero-copy data parameter.
}

table Chdir {
directory: string;
}

table GlobalTimer {
timeout: int;
}

table GlobalTimerRes { }

table GlobalTimerStop { }

table KeyValue {
key: string;
value: string;
}

table Permissions {}

table PermissionRevoke {
permission: string;
}

table PermissionsRes {
run: bool;
read: bool;
write: bool;
net: bool;
env: bool;
hrtime: bool;
}

table MakeTempDir {
dir: string;
prefix: string;
Expand Down Expand Up @@ -294,35 +189,6 @@ table ReadlinkRes {
path: string;
}

table ReplStart {
history_file: string;
// TODO add config
}

table ReplStartRes {
rid: uint32;
}

table ReplReadline {
rid: uint32;
prompt: string;
}

table ReplReadlineRes {
line: string;
}

table Resources {}

table Resource {
rid: uint32;
repr: string;
}

table ResourcesRes {
resources: [Resource];
}

table Symlink {
oldname: string;
newname: string;
Expand Down Expand Up @@ -373,99 +239,10 @@ table WriteRes {
nbyte: uint;
}

table Kill {
pid: int32;
signo: int32;
}

table Shutdown {
rid: uint32;
how: uint;
}

table Listen {
network: string;
address: string;
}

table ListenRes {
rid: uint32;
}

table Accept {
rid: uint32;
}

table Dial {
network: string;
address: string;
}

// Response to Accept and Dial.
table NewConn {
rid: uint32;
remote_addr: string;
local_addr: string;
}

table Metrics {}

table MetricsRes {
ops_dispatched: uint64;
ops_completed: uint64;
bytes_sent_control: uint64;
bytes_sent_data: uint64;
bytes_received: uint64;
}

enum ProcessStdio: byte { Inherit, Piped, Null }

table Run {
args: [string];
cwd: string;
env: [KeyValue];
stdin: ProcessStdio;
stdout: ProcessStdio;
stderr: ProcessStdio;
stdin_rid: uint32;
stdout_rid: uint32;
stderr_rid: uint32;
}

table RunRes {
rid: uint32;
pid: uint32;
// The following stdio rids are only valid if "Piped" was specified for the
// corresponding stdio stream. The caller MUST issue a close op for all valid
// stdio streams.
stdin_rid: uint32;
stdout_rid: uint32;
stderr_rid: uint32;
}

table RunStatus {
rid: uint32;
}

table RunStatusRes {
got_signal: bool;
exit_code: int;
exit_signal: int;
}

table Now {}

table NowRes {
seconds: uint64;
subsec_nanos: uint32;
}

table Seek {
rid: uint32;
offset: int;
whence: uint;
}

table GetRandomValues {}

root_type Base;
14 changes: 0 additions & 14 deletions cli/msg.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
#![allow(dead_code)]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::all, clippy::pedantic))]
use crate::state;
use flatbuffers;
use std::sync::atomic::Ordering;

// GN_OUT_DIR is set either by build.rs (for the Cargo build), or by
// build_extra/rust/run.py (for the GN+Ninja build).
include!(concat!(env!("GN_OUT_DIR"), "/gen/cli/msg_generated.rs"));

impl<'a> From<&'a state::Metrics> for MetricsResArgs {
fn from(m: &'a state::Metrics) -> Self {
MetricsResArgs {
ops_dispatched: m.ops_dispatched.load(Ordering::SeqCst) as u64,
ops_completed: m.ops_completed.load(Ordering::SeqCst) as u64,
bytes_sent_control: m.bytes_sent_control.load(Ordering::SeqCst) as u64,
bytes_sent_data: m.bytes_sent_data.load(Ordering::SeqCst) as u64,
bytes_received: m.bytes_received.load(Ordering::SeqCst) as u64,
}
}
}
Loading

0 comments on commit 137f337

Please sign in to comment.