pub struct UnixStream(/* private fields */);windows_unix_domain_sockets #150487)Expand description
A Unix stream socket.
ยง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(())
}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)