Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NamedPipe::set_buffer_size #1608

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/sys/windows/named_pipe.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::OsStr;
use std::io::{self, Read, Write};
use std::os::windows::io::{AsRawHandle, FromRawHandle, RawHandle};
use std::sync::atomic::Ordering::{Relaxed, SeqCst};
use std::sync::atomic::Ordering::{Relaxed, Release, SeqCst};
use std::sync::atomic::{AtomicBool, AtomicUsize};
use std::sync::{Arc, Mutex};
use std::{fmt, mem, slice};
Expand Down Expand Up @@ -89,6 +89,7 @@ struct Inner {
connecting: AtomicBool,
io: Mutex<Io>,
pool: Mutex<BufferPool>,
default_buf_size: AtomicUsize,
}

impl Inner {
Expand Down Expand Up @@ -381,6 +382,13 @@ impl NamedPipe {
}
}

/// Set the buffer size.
///
/// The default is *currently* 4kB (4096 bytes).
pub fn set_buffer_size(&mut self, capacity: usize) {
self.inner.default_buf_size.store(capacity, Release)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You aren't using the atomic to synchronize memory.

Suggested change
self.inner.default_buf_size.store(capacity, Release)
self.inner.default_buf_size.store(capacity, Relaxed)

}

/// Attempts to call `ConnectNamedPipe`, if possible.
///
/// This function will attempt to connect this pipe to a client in an
Expand Down Expand Up @@ -486,6 +494,7 @@ impl FromRawHandle for NamedPipe {
connect_error: None,
}),
pool: Mutex::new(BufferPool::with_capacity(2)),
default_buf_size: AtomicUsize::new(4 * 1024),
}),
}
}
Expand Down Expand Up @@ -803,7 +812,10 @@ impl Inner {
}

fn get_buffer(&self) -> Vec<u8> {
self.pool.lock().unwrap().get(4 * 1024)
self.pool
.lock()
.unwrap()
.get(self.default_buf_size.load(Relaxed))
}

fn put_buffer(&self, buf: Vec<u8>) {
Expand Down