Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 12 additions & 7 deletions src/posix/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,20 @@ pub(crate) fn get_termios(fd: RawFd) -> Result<Termios> {
}

#[cfg(any(target_os = "ios", target_os = "macos",))]
pub(crate) fn set_termios(fd: RawFd, termios: &libc::termios, baud_rate: u32) -> Result<()> {
let res = unsafe { libc::tcsetattr(fd, libc::TCSANOW, termios) };
nix::errno::Errno::result(res)?;

// Note: attempting to set the baud rate on a pseudo terminal via this ioctl call will fail
// with the `ENOTTY` error.
pub(crate) fn set_termios(fd: RawFd, termios: &mut libc::termios, baud_rate: u32) -> Result<()> {
let mut ispeed_res = 0;
let mut ospeed_res = 0;
if baud_rate > 0 {
crate::posix::ioctl::iossiospeed(fd, &(baud_rate as libc::speed_t))?;
unsafe {
ispeed_res = libc::cfsetispeed(&mut *termios, baud_rate as libc::speed_t);
ospeed_res = libc::cfsetospeed(&mut *termios, baud_rate as libc::speed_t);
}
}
nix::errno::Errno::result(ispeed_res)?;
nix::errno::Errno::result(ospeed_res)?;

let res = unsafe { libc::tcsetattr(fd, libc::TCSANOW, termios) };
nix::errno::Errno::result(res)?;

Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions src/posix/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl TTYPort {
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
termios::set_baud_rate(&mut termios, builder.baud_rate);
#[cfg(any(target_os = "ios", target_os = "macos"))]
termios::set_termios(fd.0, &termios, builder.baud_rate)?;
termios::set_termios(fd.0, &mut termios, builder.baud_rate)?;
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
termios::set_termios(fd.0, &termios)?;

Expand Down Expand Up @@ -646,7 +646,7 @@ impl SerialPort for TTYPort {
let mut termios = termios::get_termios(self.fd)?;
termios::set_flow_control(&mut termios, flow_control);
#[cfg(any(target_os = "ios", target_os = "macos"))]
return termios::set_termios(self.fd, &termios, self.baud_rate);
return termios::set_termios(self.fd, &mut termios, self.baud_rate);
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
return termios::set_termios(self.fd, &termios);
}
Expand All @@ -655,7 +655,7 @@ impl SerialPort for TTYPort {
let mut termios = termios::get_termios(self.fd)?;
termios::set_parity(&mut termios, parity);
#[cfg(any(target_os = "ios", target_os = "macos"))]
return termios::set_termios(self.fd, &termios, self.baud_rate);
return termios::set_termios(self.fd, &mut termios, self.baud_rate);
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
return termios::set_termios(self.fd, &termios);
}
Expand All @@ -664,7 +664,7 @@ impl SerialPort for TTYPort {
let mut termios = termios::get_termios(self.fd)?;
termios::set_data_bits(&mut termios, data_bits);
#[cfg(any(target_os = "ios", target_os = "macos"))]
return termios::set_termios(self.fd, &termios, self.baud_rate);
return termios::set_termios(self.fd, &mut termios, self.baud_rate);
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
return termios::set_termios(self.fd, &termios);
}
Expand All @@ -673,7 +673,7 @@ impl SerialPort for TTYPort {
let mut termios = termios::get_termios(self.fd)?;
termios::set_stop_bits(&mut termios, stop_bits);
#[cfg(any(target_os = "ios", target_os = "macos"))]
return termios::set_termios(self.fd, &termios, self.baud_rate);
return termios::set_termios(self.fd, &mut termios, self.baud_rate);
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
return termios::set_termios(self.fd, &termios);
}
Expand Down