Skip to content

Commit

Permalink
Replace flush errors with no-ops
Browse files Browse the repository at this point in the history
Fixes #58.
  • Loading branch information
kotauskas committed Apr 8, 2024
1 parent ffbf7c6 commit 91d03f1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 36 deletions.
16 changes: 0 additions & 16 deletions src/local_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,3 @@ pub mod tokio {

mod concurrency_detector;
pub(crate) use concurrency_detector::*;

use std::io;

#[cold]
pub(crate) fn flush_unsupported() -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
"local sockets cannot be flushed",
))
}

#[cfg(feature = "tokio")]
#[cold]
pub(crate) fn async_flush_unsupported() -> std::task::Poll<io::Result<()>> {
flush_unsupported().into()
}
11 changes: 4 additions & 7 deletions src/local_socket/stream/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use super::r#trait;
use crate::os::unix::uds_local_socket as uds_impl;
#[cfg(windows)]
use crate::os::windows::named_pipe::local_socket as np_impl;
use crate::{
local_socket::{flush_unsupported, Name},
TryClone,
};
use crate::{local_socket::Name, TryClone};
use std::io::{self, prelude::*, IoSlice, IoSliceMut};

impmod! {local_socket::dispatch_sync}
Expand Down Expand Up @@ -39,19 +36,19 @@ macro_rules! dispatch_write {
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
flush_unsupported()
Ok(())
}
#[inline]
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
dispatch!($ty: x in self => x.write_vectored(bufs))
}
};
($ty:ident) => {
/// Flushing fails with [`Unsupported`](io::ErrorKind::Unsupported).
/// Flushing is an always successful no-op.
impl Write for &$ty {
dispatch_write!(@iw $ty);
}
/// Flushing fails with [`Unsupported`](io::ErrorKind::Unsupported).
/// Flushing is an always successful no-op.
impl Write for $ty {
dispatch_write!(@iw $ty);
}
Expand Down
6 changes: 4 additions & 2 deletions src/local_socket/tokio/stream/enum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::r#trait;
use crate::local_socket::{async_flush_unsupported, Name};
use crate::local_socket::Name;
#[cfg(unix)]
use crate::os::unix::uds_local_socket::tokio as uds_impl;
#[cfg(windows)]
Expand Down Expand Up @@ -37,17 +37,19 @@ macro_rules! dispatch_write {
}
#[inline]
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
async_flush_unsupported()
Poll::Ready(Ok(()))
}
#[inline]
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
dispatch!($ty: x in self.get_mut() => Pin::new(x).poll_shutdown(cx))
}
};
($ty:ident) => {
/// Flushing is an always successful no-op.
impl AsyncWrite for &$ty {
dispatch_write!(@iw $ty);
}
/// Flushing is an always successful no-op.
impl AsyncWrite for $ty {
dispatch_write!(@iw $ty);
}
Expand Down
3 changes: 1 addition & 2 deletions src/os/unix/uds_local_socket/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::name_to_addr;
use crate::{
error::ReuniteError,
local_socket::{
flush_unsupported,
traits::{self, ReuniteResult},
ConcurrencyDetector, LocalSocketSite, Name,
},
Expand Down Expand Up @@ -69,7 +68,7 @@ impl Write for &Stream {
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
flush_unsupported()
Ok(())
}
// FUTURE is_write_vectored
}
Expand Down
6 changes: 3 additions & 3 deletions src/os/unix/uds_local_socket/tokio/stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::super::name_to_addr;
use crate::{
error::ReuniteError,
local_socket::{async_flush_unsupported, traits::tokio as traits, Name},
local_socket::{traits::tokio as traits, Name},
os::unix::c_wrappers,
Sealed,
};
Expand Down Expand Up @@ -132,7 +132,7 @@ impl AsyncWrite for &Stream {
}
#[inline]
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
async_flush_unsupported()
Ok(())
}
#[inline]
fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
Expand Down Expand Up @@ -229,7 +229,7 @@ impl AsyncWrite for &SendHalf {
}
#[inline]
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
async_flush_unsupported()
Ok(())
}
#[inline]
fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
Expand Down
5 changes: 2 additions & 3 deletions src/os/windows/named_pipe/local_socket/stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
error::{FromHandleError, ReuniteError},
local_socket::{
flush_unsupported,
traits::{self, ReuniteResult},
Name,
},
Expand Down Expand Up @@ -68,7 +67,7 @@ impl Write for &Stream {

#[inline]
fn flush(&mut self) -> io::Result<()> {
flush_unsupported()
Ok(())
}
// FUTURE is_write_vectored
}
Expand Down Expand Up @@ -145,7 +144,7 @@ impl Write for &SendHalf {

#[inline]
fn flush(&mut self) -> io::Result<()> {
flush_unsupported()
Ok(())
}
// FUTURE is_write_vectored
}
Expand Down
5 changes: 2 additions & 3 deletions src/os/windows/named_pipe/local_socket/tokio/stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
error::{FromHandleError, ReuniteError},
local_socket::{
async_flush_unsupported,
traits::tokio::{self as traits, ReuniteResult},
Name,
},
Expand Down Expand Up @@ -65,7 +64,7 @@ impl AsyncWrite for &Stream {
}
#[inline]
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
async_flush_unsupported()
Poll::Ready(Ok(()))
}
#[inline]
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Expand Down Expand Up @@ -132,7 +131,7 @@ impl AsyncWrite for &SendHalf {
}
#[inline]
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
async_flush_unsupported()
Poll::Ready(Ok(()))
}
#[inline]
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Expand Down

0 comments on commit 91d03f1

Please sign in to comment.