Skip to content

feat(net): allow unix sockets on windows #10377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cli/tests/unit/net_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ unitTest(
);

unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
{ perms: { read: true, write: true } },
function netUnixListenClose(): void {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listen({
Expand Down Expand Up @@ -64,7 +64,7 @@ unitTest(
);

unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true } },
{ perms: { read: true } },
function netUnixListenWritePermission(): void {
assertThrows(() => {
const filePath = Deno.makeTempFileSync();
Expand Down Expand Up @@ -114,7 +114,7 @@ unitTest(
);

unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
{ perms: { read: true, write: true } },
async function netUnixCloseWhileAccept(): Promise<void> {
const filePath = await Deno.makeTempFile();
const listener = Deno.listen({
Expand Down Expand Up @@ -219,7 +219,7 @@ unitTest({ perms: { net: true } }, async function netTcpDialListen(): Promise<
});

unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
{ perms: { read: true, write: true } },
async function netUnixDialListen(): Promise<void> {
const filePath = await Deno.makeTempFile();
const listener = Deno.listen({ path: filePath, transport: "unix" });
Expand Down Expand Up @@ -448,7 +448,7 @@ unitTest(
);

unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
{ perms: { read: true, write: true } },
async function netUnixListenCloseWhileIterating(): Promise<void> {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listen({ path: filePath, transport: "unix" });
Expand Down
1 change: 0 additions & 1 deletion runtime/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub mod fs_events;
pub mod http;
pub mod io;
pub mod net;
#[cfg(unix)]
mod net_unix;
pub mod os;
pub mod permissions;
Expand Down
12 changes: 0 additions & 12 deletions runtime/ops/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ use trust_dns_resolver::config::ResolverOpts;
use trust_dns_resolver::system_conf;
use trust_dns_resolver::AsyncResolver;

#[cfg(unix)]
use super::net_unix;
#[cfg(unix)]
use crate::ops::io::UnixStreamResource;
#[cfg(unix)]
use std::path::Path;

pub fn init(rt: &mut deno_core::JsRuntime) {
Expand All @@ -64,9 +61,7 @@ pub struct OpConn {
pub enum OpAddr {
Tcp(IpAddr),
Udp(IpAddr),
#[cfg(unix)]
Unix(net_unix::UnixAddr),
#[cfg(unix)]
UnixPacket(net_unix::UnixAddr),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unixpacket is not supported on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I suspected that might not be the case. I don't think I've seen unixpacket used anywhere TBH (not just deno, but any software project)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably going to get a lot more common with QUIC / HTTP/3.

}

Expand Down Expand Up @@ -142,7 +137,6 @@ async fn op_accept(
) -> Result<OpConn, AnyError> {
match args.transport.as_str() {
"tcp" => accept_tcp(state, args, _buf).await,
#[cfg(unix)]
"unix" => net_unix::accept_unix(state, args, _buf).await,
other => Err(bad_transport(other)),
}
Expand Down Expand Up @@ -195,7 +189,6 @@ async fn op_datagram_receive(
) -> Result<OpPacket, AnyError> {
match args.transport.as_str() {
"udp" => receive_udp(state, args, zero_copy).await,
#[cfg(unix)]
"unixpacket" => net_unix::receive_unix_packet(state, args, zero_copy).await,
other => Err(bad_transport(other)),
}
Expand Down Expand Up @@ -243,7 +236,6 @@ async fn op_datagram_send(
let byte_length = socket.send_to(&zero_copy, &addr).await?;
Ok(byte_length)
}
#[cfg(unix)]
SendArgs {
rid,
transport,
Expand Down Expand Up @@ -319,7 +311,6 @@ async fn op_connect(
})),
})
}
#[cfg(unix)]
ConnectArgs {
transport,
transport_args: ArgsEnum::Unix(args),
Expand Down Expand Up @@ -399,7 +390,6 @@ struct IpListenArgs {
#[serde(untagged)]
enum ArgsEnum {
Ip(IpListenArgs),
#[cfg(unix)]
Unix(net_unix::UnixListenArgs),
}

Expand Down Expand Up @@ -492,7 +482,6 @@ fn op_listen(
remote_addr: None,
})
}
#[cfg(unix)]
ListenArgs {
transport,
transport_args: ArgsEnum::Unix(args),
Expand Down Expand Up @@ -533,7 +522,6 @@ fn op_listen(
remote_addr: None,
})
}
#[cfg(unix)]
_ => Err(type_error("Wrong argument format!")),
}
}
Expand Down