Skip to content

Commit

Permalink
Merge pull request #36 from rkuris/no-vmin
Browse files Browse the repository at this point in the history
Setting VMIN on a non-cooked port has no effect
  • Loading branch information
estokes authored Dec 31, 2024
2 parents 5385318 + 5f26edc commit 5d15833
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@ pub struct SerialStream {
pipe: NamedPipe,
}

#[cfg(unix)]
fn map_nix_error(e: nix::Error) -> crate::Error {
crate::Error {
kind: crate::ErrorKind::Io(StdIoErrorKind::Other),
description: e.to_string(),
}
}

impl SerialStream {
/// Open a nonblocking serial port from the provided builder
///
Expand Down Expand Up @@ -536,22 +528,11 @@ impl TryFrom<NativeBlockingSerialPort> for SerialStream {
type Error = crate::Error;
#[cfg(unix)]
fn try_from(port: NativeBlockingSerialPort) -> std::result::Result<Self, Self::Error> {
// Set the O_NONBLOCK flag.
log::debug!(
"switching {} to asynchronous mode",
"setting O_NONBLOCK for {}",
port.name().unwrap_or_else(|| String::from("<UNKNOWN>"))
);
log::debug!("setting VMIN = 1");

use nix::sys::termios::{self, SetArg, SpecialCharacterIndices};
let fd = unsafe { BorrowedFd::borrow_raw(port.as_raw_fd()) };
let mut t = termios::tcgetattr(fd).map_err(map_nix_error)?;

// Set VMIN = 1 to block until at least one character is received.
t.control_chars[SpecialCharacterIndices::VMIN as usize] = 1;
termios::tcsetattr(fd, SetArg::TCSANOW, &t).map_err(map_nix_error)?;

// Set the O_NONBLOCK flag.
log::debug!("setting O_NONBLOCK flag");
let flags = unsafe { libc::fcntl(port.as_raw_fd(), libc::F_GETFL) };
if flags < 0 {
return Err(StdIoError::last_os_error().into());
Expand Down

0 comments on commit 5d15833

Please sign in to comment.