mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
refactor: rewrite ext/net/ ops to op2 (#20471)
This commit is contained in:
parent
bdf1850679
commit
08d2a32060
3 changed files with 97 additions and 77 deletions
110
ext/net/ops.rs
110
ext/net/ops.rs
|
@ -9,6 +9,7 @@ use deno_core::error::custom_error;
|
|||
use deno_core::error::generic_error;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::op;
|
||||
use deno_core::op2;
|
||||
use deno_core::CancelFuture;
|
||||
|
||||
use deno_core::AsyncRefCell;
|
||||
|
@ -76,10 +77,11 @@ pub(crate) fn accept_err(e: std::io::Error) -> AnyError {
|
|||
}
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn op_net_accept_tcp(
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_net_accept_tcp(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(ResourceId, IpAddr, IpAddr), AnyError> {
|
||||
let resource = state
|
||||
.borrow()
|
||||
|
@ -105,11 +107,12 @@ async fn op_net_accept_tcp(
|
|||
Ok((rid, IpAddr::from(local_addr), IpAddr::from(remote_addr)))
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn op_net_recv_udp(
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_net_recv_udp(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
mut buf: JsBuffer,
|
||||
#[smi] rid: ResourceId,
|
||||
#[buffer] mut buf: JsBuffer,
|
||||
) -> Result<(usize, IpAddr), AnyError> {
|
||||
let resource = state
|
||||
.borrow_mut()
|
||||
|
@ -158,12 +161,12 @@ where
|
|||
Ok(nwritten)
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn op_net_join_multi_v4_udp(
|
||||
#[op2(async)]
|
||||
pub async fn op_net_join_multi_v4_udp(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
address: String,
|
||||
multi_interface: String,
|
||||
#[smi] rid: ResourceId,
|
||||
#[string] address: String,
|
||||
#[string] multi_interface: String,
|
||||
) -> Result<(), AnyError> {
|
||||
let resource = state
|
||||
.borrow_mut()
|
||||
|
@ -180,12 +183,12 @@ async fn op_net_join_multi_v4_udp(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn op_net_join_multi_v6_udp(
|
||||
#[op2(async)]
|
||||
pub async fn op_net_join_multi_v6_udp(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
address: String,
|
||||
multi_interface: u32,
|
||||
#[smi] rid: ResourceId,
|
||||
#[string] address: String,
|
||||
#[smi] multi_interface: u32,
|
||||
) -> Result<(), AnyError> {
|
||||
let resource = state
|
||||
.borrow_mut()
|
||||
|
@ -201,12 +204,12 @@ async fn op_net_join_multi_v6_udp(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn op_net_leave_multi_v4_udp(
|
||||
#[op2(async)]
|
||||
pub async fn op_net_leave_multi_v4_udp(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
address: String,
|
||||
multi_interface: String,
|
||||
#[smi] rid: ResourceId,
|
||||
#[string] address: String,
|
||||
#[string] multi_interface: String,
|
||||
) -> Result<(), AnyError> {
|
||||
let resource = state
|
||||
.borrow_mut()
|
||||
|
@ -223,12 +226,12 @@ async fn op_net_leave_multi_v4_udp(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn op_net_leave_multi_v6_udp(
|
||||
#[op2(async)]
|
||||
pub async fn op_net_leave_multi_v6_udp(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
address: String,
|
||||
multi_interface: u32,
|
||||
#[smi] rid: ResourceId,
|
||||
#[string] address: String,
|
||||
#[smi] multi_interface: u32,
|
||||
) -> Result<(), AnyError> {
|
||||
let resource = state
|
||||
.borrow_mut()
|
||||
|
@ -244,10 +247,10 @@ async fn op_net_leave_multi_v6_udp(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn op_net_set_multi_loopback_udp(
|
||||
#[op2(async)]
|
||||
pub async fn op_net_set_multi_loopback_udp(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
#[smi] rid: ResourceId,
|
||||
is_v4_membership: bool,
|
||||
loopback: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
|
@ -267,11 +270,11 @@ async fn op_net_set_multi_loopback_udp(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn op_net_set_multi_ttl_udp(
|
||||
#[op2(async)]
|
||||
pub async fn op_net_set_multi_ttl_udp(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
ttl: u32,
|
||||
#[smi] rid: ResourceId,
|
||||
#[smi] ttl: u32,
|
||||
) -> Result<(), AnyError> {
|
||||
let resource = state
|
||||
.borrow_mut()
|
||||
|
@ -285,10 +288,11 @@ async fn op_net_set_multi_ttl_udp(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_net_connect_tcp<NP>(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
addr: IpAddr,
|
||||
#[serde] addr: IpAddr,
|
||||
) -> Result<(ResourceId, IpAddr, IpAddr), AnyError>
|
||||
where
|
||||
NP: NetPermissions + 'static,
|
||||
|
@ -346,10 +350,11 @@ impl Resource for UdpSocketResource {
|
|||
}
|
||||
}
|
||||
|
||||
#[op]
|
||||
fn op_net_listen_tcp<NP>(
|
||||
#[op2]
|
||||
#[serde]
|
||||
pub fn op_net_listen_tcp<NP>(
|
||||
state: &mut OpState,
|
||||
addr: IpAddr,
|
||||
#[serde] addr: IpAddr,
|
||||
reuse_port: bool,
|
||||
) -> Result<(ResourceId, IpAddr), AnyError>
|
||||
where
|
||||
|
@ -455,10 +460,11 @@ where
|
|||
Ok((rid, IpAddr::from(local_addr)))
|
||||
}
|
||||
|
||||
#[op]
|
||||
fn op_net_listen_udp<NP>(
|
||||
#[op2]
|
||||
#[serde]
|
||||
pub fn op_net_listen_udp<NP>(
|
||||
state: &mut OpState,
|
||||
addr: IpAddr,
|
||||
#[serde] addr: IpAddr,
|
||||
reuse_address: bool,
|
||||
loopback: bool,
|
||||
) -> Result<(ResourceId, IpAddr), AnyError>
|
||||
|
@ -469,10 +475,11 @@ where
|
|||
net_listen_udp::<NP>(state, addr, reuse_address, loopback)
|
||||
}
|
||||
|
||||
#[op]
|
||||
fn op_node_unstable_net_listen_udp<NP>(
|
||||
#[op2]
|
||||
#[serde]
|
||||
pub fn op_node_unstable_net_listen_udp<NP>(
|
||||
state: &mut OpState,
|
||||
addr: IpAddr,
|
||||
#[serde] addr: IpAddr,
|
||||
reuse_address: bool,
|
||||
loopback: bool,
|
||||
) -> Result<(ResourceId, IpAddr), AnyError>
|
||||
|
@ -553,10 +560,11 @@ pub struct NameServer {
|
|||
port: u16,
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_dns_resolve<NP>(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: ResolveAddrArgs,
|
||||
#[serde] args: ResolveAddrArgs,
|
||||
) -> Result<Vec<DnsReturnRecord>, AnyError>
|
||||
where
|
||||
NP: NetPermissions + 'static,
|
||||
|
@ -640,10 +648,10 @@ where
|
|||
.collect::<Result<Vec<DnsReturnRecord>, AnyError>>()
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(fast)]
|
||||
pub fn op_set_nodelay(
|
||||
state: &mut OpState,
|
||||
rid: ResourceId,
|
||||
#[smi] rid: ResourceId,
|
||||
nodelay: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
let resource: Rc<TcpStreamResource> =
|
||||
|
@ -651,10 +659,10 @@ pub fn op_set_nodelay(
|
|||
resource.set_nodelay(nodelay)
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(fast)]
|
||||
pub fn op_set_keepalive(
|
||||
state: &mut OpState,
|
||||
rid: ResourceId,
|
||||
#[smi] rid: ResourceId,
|
||||
keepalive: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
let resource: Rc<TcpStreamResource> =
|
||||
|
|
|
@ -23,7 +23,7 @@ use deno_core::futures::task::Poll;
|
|||
use deno_core::futures::task::RawWaker;
|
||||
use deno_core::futures::task::RawWakerVTable;
|
||||
use deno_core::futures::task::Waker;
|
||||
use deno_core::op;
|
||||
use deno_core::op2;
|
||||
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::unsync::spawn;
|
||||
|
@ -779,10 +779,11 @@ pub struct StartTlsArgs {
|
|||
alpn_protocols: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_tls_start<NP>(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
args: StartTlsArgs,
|
||||
#[serde] args: StartTlsArgs,
|
||||
) -> Result<(ResourceId, IpAddr, IpAddr), AnyError>
|
||||
where
|
||||
NP: NetPermissions + 'static,
|
||||
|
@ -860,11 +861,12 @@ where
|
|||
Ok((rid, IpAddr::from(local_addr), IpAddr::from(remote_addr)))
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_net_connect_tls<NP>(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
addr: IpAddr,
|
||||
args: ConnectTlsArgs,
|
||||
#[serde] addr: IpAddr,
|
||||
#[serde] args: ConnectTlsArgs,
|
||||
) -> Result<(ResourceId, IpAddr, IpAddr), AnyError>
|
||||
where
|
||||
NP: NetPermissions + 'static,
|
||||
|
@ -1000,11 +1002,12 @@ pub struct ListenTlsArgs {
|
|||
reuse_port: bool,
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2]
|
||||
#[serde]
|
||||
pub fn op_net_listen_tls<NP>(
|
||||
state: &mut OpState,
|
||||
addr: IpAddr,
|
||||
args: ListenTlsArgs,
|
||||
#[serde] addr: IpAddr,
|
||||
#[serde] args: ListenTlsArgs,
|
||||
) -> Result<(ResourceId, IpAddr), AnyError>
|
||||
where
|
||||
NP: NetPermissions + 'static,
|
||||
|
@ -1101,10 +1104,11 @@ where
|
|||
Ok((rid, IpAddr::from(local_addr)))
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_net_accept_tls(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(ResourceId, IpAddr, IpAddr), AnyError> {
|
||||
let resource = state
|
||||
.borrow()
|
||||
|
@ -1142,10 +1146,11 @@ pub async fn op_net_accept_tls(
|
|||
Ok((rid, IpAddr::from(local_addr), IpAddr::from(remote_addr)))
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_tls_handshake(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<TlsHandshakeInfo, AnyError> {
|
||||
let resource = state
|
||||
.borrow()
|
||||
|
|
|
@ -6,6 +6,7 @@ use deno_core::error::bad_resource;
|
|||
use deno_core::error::custom_error;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::op;
|
||||
use deno_core::op2;
|
||||
use deno_core::AsyncRefCell;
|
||||
use deno_core::CancelHandle;
|
||||
use deno_core::CancelTryFuture;
|
||||
|
@ -72,10 +73,11 @@ pub struct UnixListenArgs {
|
|||
pub path: String,
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_net_accept_unix(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(ResourceId, Option<String>, Option<String>), AnyError> {
|
||||
let resource = state
|
||||
.borrow()
|
||||
|
@ -103,10 +105,11 @@ pub async fn op_net_accept_unix(
|
|||
Ok((rid, local_addr_path, remote_addr_path))
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_net_connect_unix<NP>(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
path: String,
|
||||
#[string] path: String,
|
||||
) -> Result<(ResourceId, Option<String>, Option<String>), AnyError>
|
||||
where
|
||||
NP: NetPermissions + 'static,
|
||||
|
@ -134,11 +137,12 @@ where
|
|||
Ok((rid, local_addr_path, remote_addr_path))
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[serde]
|
||||
pub async fn op_net_recv_unixpacket(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
rid: ResourceId,
|
||||
mut buf: JsBuffer,
|
||||
#[smi] rid: ResourceId,
|
||||
#[buffer] mut buf: JsBuffer,
|
||||
) -> Result<(usize, Option<String>), AnyError> {
|
||||
let resource = state
|
||||
.borrow()
|
||||
|
@ -185,10 +189,11 @@ where
|
|||
Ok(nwritten)
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2]
|
||||
#[serde]
|
||||
pub fn op_net_listen_unix<NP>(
|
||||
state: &mut OpState,
|
||||
path: String,
|
||||
#[string] path: String,
|
||||
) -> Result<(ResourceId, Option<String>), AnyError>
|
||||
where
|
||||
NP: NetPermissions + 'static,
|
||||
|
@ -231,10 +236,11 @@ where
|
|||
Ok((rid, pathname))
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2]
|
||||
#[serde]
|
||||
pub fn op_net_listen_unixpacket<NP>(
|
||||
state: &mut OpState,
|
||||
path: String,
|
||||
#[string] path: String,
|
||||
) -> Result<(ResourceId, Option<String>), AnyError>
|
||||
where
|
||||
NP: NetPermissions + 'static,
|
||||
|
@ -243,10 +249,11 @@ where
|
|||
net_listen_unixpacket::<NP>(state, path)
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2]
|
||||
#[serde]
|
||||
pub fn op_node_unstable_net_listen_unixpacket<NP>(
|
||||
state: &mut OpState,
|
||||
path: String,
|
||||
#[string] path: String,
|
||||
) -> Result<(ResourceId, Option<String>), AnyError>
|
||||
where
|
||||
NP: NetPermissions + 'static,
|
||||
|
|
Loading…
Reference in a new issue