pub struct UnixStream(pub(super) Socket);windows_unix_domain_sockets #150487)Expand description
A Unix stream socket.
Under Windows, it will only work starting from Windows 10 17063.
§Examples
#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::UnixStream;
use std::io::prelude::*;
fn main() -> std::io::Result<()> {
let mut stream = UnixStream::connect("/path/to/my/socket")?;
stream.write_all(b"hello world")?;
let mut response = String::new();
stream.read_to_string(&mut response)?;
println!("{response}");
Ok(())
}Tuple Fields§
§0: Socketwindows_unix_domain_sockets #150487)Implementations§
Source§impl UnixStream
impl UnixStream
Sourcepub fn connect<P: AsRef<Path>>(path: P) -> Result<UnixStream>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn connect<P: AsRef<Path>>(path: P) -> Result<UnixStream>
windows_unix_domain_sockets #150487)Connects to the socket named by path.
§Examples
Sourcepub fn connect_addr(socket_addr: &SocketAddr) -> Result<UnixStream>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn connect_addr(socket_addr: &SocketAddr) -> Result<UnixStream>
windows_unix_domain_sockets #150487)Connects to the socket specified by address.
§Examples
#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::{UnixListener, UnixStream};
fn main() -> std::io::Result<()> {
let listener = UnixListener::bind("/path/to/the/socket")?;
let addr = listener.local_addr()?;
let sock = match UnixStream::connect_addr(&addr) {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't connect: {e:?}");
return Err(e)
}
};
Ok(())
}Sourcepub fn local_addr(&self) -> Result<SocketAddr>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn local_addr(&self) -> Result<SocketAddr>
windows_unix_domain_sockets #150487)Returns the socket address of the local half of this connection.
§Examples
Sourcepub fn peer_addr(&self) -> Result<SocketAddr>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn peer_addr(&self) -> Result<SocketAddr>
windows_unix_domain_sockets #150487)Returns the socket address of the remote half of this connection.
§Examples
Sourcepub fn read_timeout(&self) -> Result<Option<Duration>>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn read_timeout(&self) -> Result<Option<Duration>>
windows_unix_domain_sockets #150487)Returns the read timeout of this socket.
§Examples
#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::UnixStream;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let socket = UnixStream::connect("/tmp/sock")?;
socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout");
assert_eq!(socket.read_timeout()?, Some(Duration::new(1, 0)));
Ok(())
}Sourcepub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
windows_unix_domain_sockets #150487)Moves the socket into or out of nonblocking mode.
§Examples
Sourcepub fn set_read_timeout(&self, dur: Option<Duration>) -> Result<()>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn set_read_timeout(&self, dur: Option<Duration>) -> Result<()>
windows_unix_domain_sockets #150487)Sets the read timeout for the socket.
If the provided value is None, then read calls will block
indefinitely. An Err is returned if the zero Duration is passed to this
method.
§Examples
#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::UnixStream;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let socket = UnixStream::connect("/tmp/sock")?;
socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout");
Ok(())
}An Err is returned if the zero Duration is passed to this
method:
#![feature(windows_unix_domain_sockets)]
use std::io;
use std::os::windows::net::UnixStream;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let socket = UnixStream::connect("/tmp/sock")?;
let result = socket.set_read_timeout(Some(Duration::new(0, 0)));
let err = result.unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
Ok(())
}Sourcepub fn set_write_timeout(&self, dur: Option<Duration>) -> Result<()>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn set_write_timeout(&self, dur: Option<Duration>) -> Result<()>
windows_unix_domain_sockets #150487)Sets the write timeout for the socket.
If the provided value is None, then write calls will block
indefinitely. An Err is returned if the zero Duration is
passed to this method.
§Examples
#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::UnixStream;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let socket = UnixStream::connect("/tmp/sock")?;
socket.set_write_timeout(Some(Duration::new(1, 0)))
.expect("Couldn't set write timeout");
Ok(())
}An Err is returned if the zero Duration is passed to this
method:
#![feature(windows_unix_domain_sockets)]
use std::io;
use std::os::windows::net::UnixStream;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let socket = UnixStream::connect("/tmp/sock")?;
let result = socket.set_write_timeout(Some(Duration::new(0, 0)));
let err = result.unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
Ok(())
}Sourcepub fn shutdown(&self, how: Shutdown) -> Result<()>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn shutdown(&self, how: Shutdown) -> Result<()>
windows_unix_domain_sockets #150487)Sourcepub fn take_error(&self) -> Result<Option<Error>>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn take_error(&self) -> Result<Option<Error>>
windows_unix_domain_sockets #150487)Returns the value of the SO_ERROR option.
§Examples
Sourcepub fn try_clone(&self) -> Result<UnixStream>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn try_clone(&self) -> Result<UnixStream>
windows_unix_domain_sockets #150487)Creates a new independently owned handle to the underlying socket.
The returned UnixStream is a reference to the same stream that this
object references. Both handles will read and write the same stream of
data, and options set on one stream will be propagated to the other
stream.
§Examples
Sourcepub fn write_timeout(&self) -> Result<Option<Duration>>
🔬This is a nightly-only experimental API. (windows_unix_domain_sockets #150487)
pub fn write_timeout(&self) -> Result<Option<Duration>>
windows_unix_domain_sockets #150487)Returns the write timeout of this socket.
§Examples
#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::UnixStream;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let socket = UnixStream::connect("/tmp/sock")?;
socket.set_write_timeout(Some(Duration::new(1, 0)))
.expect("Couldn't set write timeout");
assert_eq!(socket.write_timeout()?, Some(Duration::new(1, 0)));
Ok(())
}Trait Implementations§
Source§impl AsRawSocket for UnixStream
impl AsRawSocket for UnixStream
Source§fn as_raw_socket(&self) -> RawSocket
fn as_raw_socket(&self) -> RawSocket
Source§impl AsSocket for UnixStream
impl AsSocket for UnixStream
Source§fn as_socket(&self) -> BorrowedSocket<'_>
fn as_socket(&self) -> BorrowedSocket<'_>
Source§impl Debug for UnixStream
impl Debug for UnixStream
Source§impl FromRawSocket for UnixStream
impl FromRawSocket for UnixStream
Source§unsafe fn from_raw_socket(sock: RawSocket) -> Self
unsafe fn from_raw_socket(sock: RawSocket) -> Self
Source§impl IntoRawSocket for UnixStream
impl IntoRawSocket for UnixStream
Source§fn into_raw_socket(self) -> RawSocket
fn into_raw_socket(self) -> RawSocket
Source§impl<'a> Read for &'a UnixStream
impl<'a> Read for &'a UnixStream
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector #69941)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<()>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<()>
read_buf #78485)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<()>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<()>
read_buf #78485)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R: Read>(self, next: R) -> Chain<Self, R> ⓘwhere
Self: Sized,
fn chain<R: Read>(self, next: R) -> Chain<Self, R> ⓘwhere
Self: Sized,
Source§impl Read for UnixStream
impl Read for UnixStream
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector #69941)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<()>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<()>
read_buf #78485)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<()>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<()>
read_buf #78485)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R: Read>(self, next: R) -> Chain<Self, R> ⓘwhere
Self: Sized,
fn chain<R: Read>(self, next: R) -> Chain<Self, R> ⓘwhere
Self: Sized,
Source§impl<'a> Write for &'a UnixStream
impl<'a> Write for &'a UnixStream
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector #69941)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
write_all_vectored #70436)Source§impl Write for UnixStream
impl Write for UnixStream
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector #69941)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
write_all_vectored #70436)Auto Trait Implementations§
impl Freeze for UnixStream
impl RefUnwindSafe for UnixStream
impl Send for UnixStream
impl Sync for UnixStream
impl Unpin for UnixStream
impl UnsafeUnpin for UnixStream
impl UnwindSafe for UnixStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type #102070)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more