expression

Signal end of a request without closing the reply path

A write-side shutdown lets the peer read queued data and then EOF while the opposite direction remains usable. Here each request and response is bounded to three bytes; only the request side is half-closed. Expected stdout (not executed): yes Common mistake: Closing both directions before reading the reply. Run only in the isolated fixture runner, not a public code playground.

Formal Syntax & Structure

rust syntaxrust
stream.shutdown(Shutdown::Write)

Working Example

Example Snippetrust
use std::{io::{self,Read,Write},net::Shutdown,os::unix::net::UnixStream};fn main() -> io::Result<()> {    let (mut a,mut b)=UnixStream::pair()?;    a.write_all(b"ask")?; a.shutdown(Shutdown::Write)?;    let mut request=[0;3]; b.read_exact(&mut request)?;    assert_eq!(&request,b"ask"); assert_eq!(b.read(&mut [0;1])?,0);    b.write_all(b"yes")?;    let mut reply=[0;3]; a.read_exact(&mut reply)?;    println!("{}",std::str::from_utf8(&reply).unwrap()); Ok(())}
Rust Reference