mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
net: fix named pipe connect (#5208)
This commit is contained in:
parent
808d52563e
commit
2682c505e8
@ -192,17 +192,15 @@ impl NamedPipeServer {
|
|||||||
/// # Ok(()) }
|
/// # Ok(()) }
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn connect(&self) -> io::Result<()> {
|
pub async fn connect(&self) -> io::Result<()> {
|
||||||
loop {
|
match self.io.connect() {
|
||||||
match self.io.connect() {
|
Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||||
Ok(()) => break,
|
self.io
|
||||||
Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
|
.registration()
|
||||||
self.io.registration().readiness(Interest::WRITABLE).await?;
|
.async_io(Interest::WRITABLE, || self.io.connect())
|
||||||
}
|
.await
|
||||||
Err(e) => return Err(e),
|
|
||||||
}
|
}
|
||||||
|
x => x,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disconnects the server end of a named pipe instance from a client
|
/// Disconnects the server end of a named pipe instance from a client
|
||||||
|
@ -341,6 +341,33 @@ async fn test_named_pipe_mode_message() -> io::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This tests `NamedPipeServer::connect` with various access settings.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_named_pipe_access() -> io::Result<()> {
|
||||||
|
const PIPE_NAME: &str = r"\\.\pipe\test-named-pipe-access";
|
||||||
|
|
||||||
|
for (inb, outb) in [(true, true), (true, false), (false, true)] {
|
||||||
|
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||||
|
let server = tokio::spawn(async move {
|
||||||
|
let s = ServerOptions::new()
|
||||||
|
.access_inbound(inb)
|
||||||
|
.access_outbound(outb)
|
||||||
|
.create(PIPE_NAME)?;
|
||||||
|
let mut connect_fut = tokio_test::task::spawn(s.connect());
|
||||||
|
assert!(connect_fut.poll().is_pending());
|
||||||
|
tx.send(()).unwrap();
|
||||||
|
connect_fut.await
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for the server to call connect.
|
||||||
|
rx.await.unwrap();
|
||||||
|
let _ = ClientOptions::new().read(outb).write(inb).open(PIPE_NAME)?;
|
||||||
|
|
||||||
|
server.await??;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn num_instances(pipe_name: impl AsRef<str>) -> io::Result<u32> {
|
fn num_instances(pipe_name: impl AsRef<str>) -> io::Result<u32> {
|
||||||
use ntapi::ntioapi;
|
use ntapi::ntioapi;
|
||||||
use winapi::shared::ntdef;
|
use winapi::shared::ntdef;
|
Loading…
x
Reference in New Issue
Block a user