mod.rs 1.1 KB
Newer Older
B
Bartek Iwańczuk 已提交
1 2 3 4 5
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::state::ThreadSafeState;
use deno::*;

mod compiler;
R
Ryan Dahl 已提交
6 7
mod dispatch_flatbuffers;
mod dispatch_minimal;
B
Bartek Iwańczuk 已提交
8 9
mod errors;
mod fetch;
R
Ryan Dahl 已提交
10
mod files;
B
Bartek Iwańczuk 已提交
11
mod fs;
R
Ryan Dahl 已提交
12
mod io;
B
Bartek Iwańczuk 已提交
13 14 15 16 17 18 19 20 21 22
mod metrics;
mod net;
mod os;
mod performance;
mod permissions;
mod process;
mod random;
mod repl;
mod resources;
mod timers;
R
Ryan Dahl 已提交
23
mod utils;
B
Bartek Iwańczuk 已提交
24 25
mod workers;

R
Ryan Dahl 已提交
26 27 28
pub const OP_FLATBUFFER: OpId = 44;
pub const OP_READ: OpId = 1;
pub const OP_WRITE: OpId = 2;
B
Bartek Iwańczuk 已提交
29

R
Ryan Dahl 已提交
30
pub fn dispatch(
B
Bartek Iwańczuk 已提交
31 32 33 34 35 36 37 38
  state: &ThreadSafeState,
  op_id: OpId,
  control: &[u8],
  zero_copy: Option<PinnedBuf>,
) -> CoreOp {
  let bytes_sent_control = control.len();
  let bytes_sent_zero_copy = zero_copy.as_ref().map(|b| b.len()).unwrap_or(0);

R
Ryan Dahl 已提交
39 40 41
  let op = match op_id {
    OP_READ => {
      dispatch_minimal::dispatch(io::op_read, state, control, zero_copy)
B
Bartek Iwańczuk 已提交
42
    }
R
Ryan Dahl 已提交
43 44
    OP_WRITE => {
      dispatch_minimal::dispatch(io::op_write, state, control, zero_copy)
B
Bartek Iwańczuk 已提交
45
    }
R
Ryan Dahl 已提交
46 47 48
    OP_FLATBUFFER => dispatch_flatbuffers::dispatch(state, control, zero_copy),
    _ => panic!("bad op_id"),
  };
B
Bartek Iwańczuk 已提交
49

R
Ryan Dahl 已提交
50 51
  state.metrics_op_dispatched(bytes_sent_control, bytes_sent_zero_copy);
  op
B
Bartek Iwańczuk 已提交
52
}