diff options
Diffstat (limited to 'ext/net/ops.rs')
-rw-r--r-- | ext/net/ops.rs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 682ba0acb..2c9129ebf 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -9,8 +9,8 @@ use deno_core::error::custom_error; use deno_core::error::generic_error; use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::op_async; -use deno_core::op_sync; +use deno_core::op; + use deno_core::AsyncRefCell; use deno_core::ByteString; use deno_core::CancelHandle; @@ -52,14 +52,14 @@ use std::path::Path; pub fn init<P: NetPermissions + 'static>() -> Vec<OpPair> { vec![ - ("op_net_accept", op_async(op_net_accept)), - ("op_net_connect", op_async(op_net_connect::<P>)), - ("op_net_listen", op_sync(op_net_listen::<P>)), - ("op_dgram_recv", op_async(op_dgram_recv)), - ("op_dgram_send", op_async(op_dgram_send::<P>)), - ("op_dns_resolve", op_async(op_dns_resolve::<P>)), - ("op_set_nodelay", op_sync(op_set_nodelay::<P>)), - ("op_set_keepalive", op_sync(op_set_keepalive::<P>)), + op_net_accept::decl(), + op_net_connect::decl::<P>(), + op_net_listen::decl::<P>(), + op_dgram_recv::decl(), + op_dgram_send::decl::<P>(), + op_dns_resolve::decl::<P>(), + op_set_nodelay::decl::<P>(), + op_set_keepalive::decl::<P>(), ] } @@ -158,6 +158,7 @@ async fn accept_tcp( }) } +#[op] async fn op_net_accept( state: Rc<RefCell<OpState>>, args: AcceptArgs, @@ -210,6 +211,7 @@ async fn receive_udp( }) } +#[op] async fn op_dgram_recv( state: Rc<RefCell<OpState>>, args: ReceiveArgs, @@ -231,6 +233,7 @@ struct SendArgs { transport_args: ArgsEnum, } +#[op] async fn op_dgram_send<NP>( state: Rc<RefCell<OpState>>, args: SendArgs, @@ -299,6 +302,7 @@ pub struct ConnectArgs { transport_args: ArgsEnum, } +#[op] pub async fn op_net_connect<NP>( state: Rc<RefCell<OpState>>, args: ConnectArgs, @@ -474,6 +478,7 @@ fn listen_udp( Ok((rid, local_addr)) } +#[op] fn op_net_listen<NP>( state: &mut OpState, args: ListenArgs, @@ -613,6 +618,7 @@ pub struct NameServer { port: u16, } +#[op] pub async fn op_dns_resolve<NP>( state: Rc<RefCell<OpState>>, args: ResolveAddrArgs, @@ -681,6 +687,7 @@ where Ok(results) } +#[op] pub fn op_set_nodelay<NP>( state: &mut OpState, rid: ResourceId, @@ -692,6 +699,7 @@ pub fn op_set_nodelay<NP>( resource.set_nodelay(nodelay) } +#[op] pub fn op_set_keepalive<NP>( state: &mut OpState, rid: ResourceId, @@ -877,7 +885,7 @@ mod tests { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn tcp_set_no_delay() { let set_nodelay = Box::new(|state: &mut OpState, rid| { - op_set_nodelay::<TestPermission>(state, rid, true).unwrap(); + op_set_nodelay::call::<TestPermission>(state, rid, true).unwrap(); }); let test_fn = Box::new(|socket: SockRef| { assert!(socket.nodelay().unwrap()); @@ -889,7 +897,7 @@ mod tests { #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn tcp_set_keepalive() { let set_keepalive = Box::new(|state: &mut OpState, rid| { - op_set_keepalive::<TestPermission>(state, rid, true).unwrap(); + op_set_keepalive::call::<TestPermission>(state, rid, true).unwrap(); }); let test_fn = Box::new(|socket: SockRef| { assert!(!socket.nodelay().unwrap()); @@ -934,7 +942,7 @@ mod tests { }; let connect_fut = - op_net_connect::<TestPermission>(conn_state, connect_args, ()); + op_net_connect::call::<TestPermission>(conn_state, connect_args, ()); let conn = connect_fut.await.unwrap(); let rid = conn.rid; |