File: no_client.rs

package info (click to toggle)
rust-interprocess 2.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,016 kB
  • sloc: makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Tests what happens when a server attempts to listen for clients that never come.

use {
    crate::{
        local_socket::{prelude::*, ListenerNonblockingMode, ListenerOptions, Stream},
        tests::util::*,
    },
    color_eyre::eyre::{bail, ensure},
    std::io,
};

pub fn run_and_verify_error(id: &str, path: bool) -> TestResult {
    use io::ErrorKind::*;
    let err = match server(id, path) {
        Err(e) => e,
        Ok(c) => bail!("server successfully listened for a nonexistent client: {c:?}"),
    };
    ensure!(
        matches!(err.kind(), WouldBlock),
        "expected error to be 'would block', received '{}'",
        err
    );
    Ok(())
}
fn server(id: &str, path: bool) -> io::Result<Stream> {
    let listener = listen_and_pick_name(&mut namegen_local_socket(id, path), |nm| {
        ListenerOptions::new()
            .name(nm.borrow())
            .nonblocking(ListenerNonblockingMode::Accept)
            .create_sync()
    })
    .map_err(|e| e.downcast::<io::Error>().unwrap_or_else(io::Error::other))?
    .1;
    listener.accept()
}