Skip to content

Commit 5987451

Browse files
committed
Leverage kernel copy for UnixStream
UDS can be a sendfile destination, just like TCP sockets.
1 parent eda4c63 commit 5987451

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

library/std/src/sys/unix/kernel_copy.rs

+29
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use crate::mem::ManuallyDrop;
5656
use crate::net::TcpStream;
5757
use crate::os::unix::fs::FileTypeExt;
5858
use crate::os::unix::io::{AsRawFd, FromRawFd, RawFd};
59+
use crate::os::unix::net::UnixStream;
5960
use crate::process::{ChildStderr, ChildStdin, ChildStdout};
6061
use crate::ptr;
6162
use crate::sync::atomic::{AtomicBool, Ordering};
@@ -320,6 +321,34 @@ impl CopyWrite for &TcpStream {
320321
}
321322
}
322323

324+
impl CopyRead for UnixStream {
325+
fn properties(&self) -> CopyParams {
326+
// avoid the stat syscall since we can be fairly sure it's a socket
327+
CopyParams(FdMeta::Socket, Some(self.as_raw_fd()))
328+
}
329+
}
330+
331+
impl CopyRead for &UnixStream {
332+
fn properties(&self) -> CopyParams {
333+
// avoid the stat syscall since we can be fairly sure it's a socket
334+
CopyParams(FdMeta::Socket, Some(self.as_raw_fd()))
335+
}
336+
}
337+
338+
impl CopyWrite for UnixStream {
339+
fn properties(&self) -> CopyParams {
340+
// avoid the stat syscall since we can be fairly sure it's a socket
341+
CopyParams(FdMeta::Socket, Some(self.as_raw_fd()))
342+
}
343+
}
344+
345+
impl CopyWrite for &UnixStream {
346+
fn properties(&self) -> CopyParams {
347+
// avoid the stat syscall since we can be fairly sure it's a socket
348+
CopyParams(FdMeta::Socket, Some(self.as_raw_fd()))
349+
}
350+
}
351+
323352
impl CopyWrite for ChildStdin {
324353
fn properties(&self) -> CopyParams {
325354
CopyParams(FdMeta::Pipe, Some(self.as_raw_fd()))

0 commit comments

Comments
 (0)