• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff --git a/Cargo.lock b/Cargo.lock
2index cc8a2b44..ff87fd88 100644
3--- a/Cargo.lock
4+++ b/Cargo.lock
5@@ -42,9 +42,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
6
7 [[package]]
8 name = "bitflags"
9-version = "2.6.0"
10+version = "2.8.0"
11 source = "registry+https://github.com/rust-lang/crates.io-index"
12-checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
13+checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
14
15 [[package]]
16 name = "byteorder"
17@@ -58,6 +58,12 @@ version = "1.0.0"
18 source = "registry+https://github.com/rust-lang/crates.io-index"
19 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
20
21+[[package]]
22+name = "cfg_aliases"
23+version = "0.1.1"
24+source = "registry+https://github.com/rust-lang/crates.io-index"
25+checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
26+
27 [[package]]
28 name = "clap"
29 version = "3.2.25"
30@@ -244,12 +250,13 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
31
32 [[package]]
33 name = "nix"
34-version = "0.26.4"
35+version = "0.28.0"
36 source = "registry+https://github.com/rust-lang/crates.io-index"
37-checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
38+checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4"
39 dependencies = [
40- "bitflags 1.3.2",
41+ "bitflags 2.8.0",
42  "cfg-if",
43+ "cfg_aliases",
44  "libc",
45 ]
46
47@@ -471,7 +478,7 @@ name = "serialport"
48 version = "4.7.0"
49 dependencies = [
50  "assert_hex",
51- "bitflags 2.6.0",
52+ "bitflags 2.8.0",
53  "cfg-if",
54  "clap",
55  "core-foundation",
56diff --git a/Cargo.toml b/Cargo.toml
57index 65e5e02e..45e7a634 100644
58--- a/Cargo.toml
59+++ b/Cargo.toml
60@@ -172,7 +172,7 @@ version = "0.4.1"
61 version = "2.4.0"
62
63 [target."cfg(unix)".dependencies.nix]
64-version = "0.26"
65+version = "0.28"
66 features = [
67     "fs",
68     "ioctl",
69diff --git a/src/posix/poll.rs b/src/posix/poll.rs
70index 36d05cb4..a4b695ad 100644
71--- a/src/posix/poll.rs
72+++ b/src/posix/poll.rs
73@@ -1,7 +1,7 @@
74 #![allow(non_camel_case_types, dead_code)]
75
76 use std::io;
77-use std::os::unix::io::RawFd;
78+use std::os::fd::AsFd;
79 use std::slice;
80 use std::time::Duration;
81
82@@ -12,18 +12,18 @@ use nix::sys::signal::SigSet;
83 #[cfg(any(target_os = "linux", test))]
84 use nix::sys::time::TimeSpec;
85
86-pub fn wait_read_fd(fd: RawFd, timeout: Duration) -> io::Result<()> {
87+pub fn wait_read_fd<F: AsFd>(fd: F, timeout: Duration) -> io::Result<()> {
88     wait_fd(fd, PollFlags::POLLIN, timeout)
89 }
90
91-pub fn wait_write_fd(fd: RawFd, timeout: Duration) -> io::Result<()> {
92+pub fn wait_write_fd<F: AsFd>(fd: F, timeout: Duration) -> io::Result<()> {
93     wait_fd(fd, PollFlags::POLLOUT, timeout)
94 }
95
96-fn wait_fd(fd: RawFd, events: PollFlags, timeout: Duration) -> io::Result<()> {
97+fn wait_fd<F: AsFd>(fd: F, events: PollFlags, timeout: Duration) -> io::Result<()> {
98     use nix::errno::Errno::{EIO, EPIPE};
99
100-    let mut fd = PollFd::new(fd, events);
101+    let mut fd = PollFd::new(fd.as_fd(), events);
102
103     let wait = match poll_clamped(&mut fd, timeout) {
104         Ok(r) => r,
105@@ -87,7 +87,8 @@ fn clamped_time_spec(duration: Duration) -> TimeSpec {
106 #[cfg(not(target_os = "linux"))]
107 fn poll_clamped(fd: &mut PollFd, timeout: Duration) -> nix::Result<c_int> {
108     let millis = clamped_millis_c_int(timeout);
109-    nix::poll::poll(slice::from_mut(fd), millis)
110+    let poll_timeout = nix::poll::PollTimeout::try_from(millis).unwrap();
111+    nix::poll::poll(slice::from_mut(fd), poll_timeout)
112 }
113
114 #[cfg(any(not(target_os = "linux"), test))]
115diff --git a/src/posix/tty.rs b/src/posix/tty.rs
116index 8e6caea3..ca977d50 100644
117--- a/src/posix/tty.rs
118+++ b/src/posix/tty.rs
119@@ -59,7 +59,7 @@ fn close(fd: RawFd) {
120 /// ```
121 #[derive(Debug)]
122 pub struct TTYPort {
123-    fd: RawFd,
124+    fd: OwnedFd,
125     timeout: Duration,
126     exclusive: bool,
127     port_name: Option<String>,
128@@ -76,26 +76,6 @@ pub enum BreakDuration {
129     Arbitrary(std::num::NonZeroI32),
130 }
131
132-/// Wrapper for RawFd to assure that it's properly closed,
133-/// even if the enclosing function exits early.
134-///
135-/// This is similar to the (nightly-only) std::os::unix::io::OwnedFd.
136-struct OwnedFd(RawFd);
137-
138-impl Drop for OwnedFd {
139-    fn drop(&mut self) {
140-        close(self.0);
141-    }
142-}
143-
144-impl OwnedFd {
145-    fn into_raw(self) -> RawFd {
146-        let fd = self.0;
147-        mem::forget(self);
148-        fd
149-    }
150-}
151-
152 impl TTYPort {
153     /// Opens a TTY device as a serial port.
154     ///
155@@ -119,19 +99,20 @@ impl TTYPort {
156         use nix::libc::{cfmakeraw, tcgetattr, tcsetattr};
157
158         let path = Path::new(&builder.path);
159-        let fd = OwnedFd(nix::fcntl::open(
160+        let raw_fd = nix::fcntl::open(
161             path,
162             OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK | OFlag::O_CLOEXEC,
163             nix::sys::stat::Mode::empty(),
164-        )?);
165+        )?;
166+        let fd = unsafe { OwnedFd::from_raw_fd(raw_fd) };
167
168         // Try to claim exclusive access to the port. This is performed even
169         // if the port will later be set as non-exclusive, in order to respect
170         // other applications that may have an exclusive port lock.
171-        ioctl::tiocexcl(fd.0)?;
172+        ioctl::tiocexcl(fd.as_raw_fd())?;
173
174         let mut termios = MaybeUninit::uninit();
175-        nix::errno::Errno::result(unsafe { tcgetattr(fd.0, termios.as_mut_ptr()) })?;
176+        nix::errno::Errno::result(unsafe { tcgetattr(fd.as_raw_fd(), termios.as_mut_ptr()) })?;
177         let mut termios = unsafe { termios.assume_init() };
178
179         // setup TTY for binary serial port access
180@@ -143,11 +124,11 @@ impl TTYPort {
181         unsafe { cfmakeraw(&mut termios) };
182
183         // write settings to TTY
184-        unsafe { tcsetattr(fd.0, libc::TCSANOW, &termios) };
185+        unsafe { tcsetattr(fd.as_raw_fd(), libc::TCSANOW, &termios) };
186
187         // Read back settings from port and confirm they were applied correctly
188         let mut actual_termios = MaybeUninit::uninit();
189-        unsafe { tcgetattr(fd.0, actual_termios.as_mut_ptr()) };
190+        unsafe { tcgetattr(fd.as_raw_fd(), actual_termios.as_mut_ptr()) };
191         let actual_termios = unsafe { actual_termios.assume_init() };
192
193         if actual_termios.c_iflag != termios.c_iflag
194@@ -163,14 +144,14 @@ impl TTYPort {
195
196         #[cfg(any(target_os = "ios", target_os = "macos"))]
197         if builder.baud_rate > 0 {
198-            unsafe { libc::tcflush(fd.0, libc::TCIOFLUSH) };
199+            unsafe { libc::tcflush(fd.as_raw_fd(), libc::TCIOFLUSH) };
200         }
201
202         // clear O_NONBLOCK flag
203-        fcntl(fd.0, F_SETFL(nix::fcntl::OFlag::empty()))?;
204+        fcntl(fd.as_raw_fd(), F_SETFL(nix::fcntl::OFlag::empty()))?;
205
206         // Configure the low-level port settings
207-        let mut termios = termios::get_termios(fd.0)?;
208+        let mut termios = termios::get_termios(fd.as_raw_fd())?;
209         termios::set_parity(&mut termios, builder.parity);
210         termios::set_flow_control(&mut termios, builder.flow_control);
211         termios::set_data_bits(&mut termios, builder.data_bits);
212@@ -178,13 +159,13 @@ impl TTYPort {
213         #[cfg(not(any(target_os = "ios", target_os = "macos")))]
214         termios::set_baud_rate(&mut termios, builder.baud_rate)?;
215         #[cfg(any(target_os = "ios", target_os = "macos"))]
216-        termios::set_termios(fd.0, &termios, builder.baud_rate)?;
217+        termios::set_termios(fd.as_raw_fd(), &termios, builder.baud_rate)?;
218         #[cfg(not(any(target_os = "ios", target_os = "macos")))]
219-        termios::set_termios(fd.0, &termios)?;
220+        termios::set_termios(fd.as_raw_fd(), &termios)?;
221
222         // Return the final port object
223         let mut port = TTYPort {
224-            fd: fd.into_raw(),
225+            fd: fd,
226             timeout: builder.timeout,
227             exclusive: true,
228             port_name: Some(builder.path.clone()),
229@@ -222,9 +203,9 @@ impl TTYPort {
230     /// * `Io` for any error while setting exclusivity for the port.
231     pub fn set_exclusive(&mut self, exclusive: bool) -> Result<()> {
232         let setting_result = if exclusive {
233-            ioctl::tiocexcl(self.fd)
234+            ioctl::tiocexcl(self.fd.as_raw_fd())
235         } else {
236-            ioctl::tiocnxcl(self.fd)
237+            ioctl::tiocnxcl(self.fd.as_raw_fd())
238         };
239
240         setting_result?;
241@@ -234,14 +215,14 @@ impl TTYPort {
242
243     fn set_pin(&mut self, pin: ioctl::SerialLines, level: bool) -> Result<()> {
244         if level {
245-            ioctl::tiocmbis(self.fd, pin)
246+            ioctl::tiocmbis(self.fd.as_raw_fd(), pin)
247         } else {
248-            ioctl::tiocmbic(self.fd, pin)
249+            ioctl::tiocmbic(self.fd.as_raw_fd(), pin)
250         }
251     }
252
253     fn read_pin(&mut self, pin: ioctl::SerialLines) -> Result<bool> {
254-        ioctl::tiocmget(self.fd).map(|pins| pins.contains(pin))
255+        ioctl::tiocmget(self.fd.as_raw_fd()).map(|pins| pins.contains(pin))
256     }
257
258     /// Create a pair of pseudo serial terminals
259@@ -317,6 +298,7 @@ impl TTYPort {
260             fd,
261             nix::fcntl::FcntlArg::F_SETFL(nix::fcntl::OFlag::empty()),
262         )?;
263+        let fd = unsafe { OwnedFd::from_raw_fd(fd) };
264
265         let slave_tty = TTYPort {
266             fd,
267@@ -331,7 +313,7 @@ impl TTYPort {
268         // `tcgetattr()` doesn't work on Mac, Solaris, and maybe other
269         // BSDs when used on the master port.
270         let master_tty = TTYPort {
271-            fd: next_pty_fd.into_raw_fd(),
272+            fd: unsafe { OwnedFd::from_raw_fd(next_pty_fd.into_raw_fd()) },
273             timeout: Duration::from_millis(100),
274             exclusive: true,
275             port_name: None,
276@@ -345,8 +327,8 @@ impl TTYPort {
277     /// Sends 0-valued bits over the port for a set duration
278     pub fn send_break(&self, duration: BreakDuration) -> Result<()> {
279         match duration {
280-            BreakDuration::Short => nix::sys::termios::tcsendbreak(self.fd, 0),
281-            BreakDuration::Arbitrary(n) => nix::sys::termios::tcsendbreak(self.fd, n.get()),
282+            BreakDuration::Short => nix::sys::termios::tcsendbreak(self.fd.as_fd(), 0),
283+            BreakDuration::Arbitrary(n) => nix::sys::termios::tcsendbreak(self.fd.as_fd(), n.get()),
284         }
285         .map_err(|e| e.into())
286     }
287@@ -366,9 +348,12 @@ impl TTYPort {
288     ///
289     /// This function returns an error if the serial port couldn't be cloned.
290     pub fn try_clone_native(&self) -> Result<TTYPort> {
291-        let fd_cloned: i32 = fcntl(self.fd, nix::fcntl::F_DUPFD_CLOEXEC(self.fd))?;
292+        let fd_cloned: i32 = fcntl(
293+            self.fd.as_raw_fd(),
294+            nix::fcntl::F_DUPFD_CLOEXEC(self.fd.as_raw_fd()),
295+        )?;
296         Ok(TTYPort {
297-            fd: fd_cloned,
298+            fd: unsafe { OwnedFd::from_raw_fd(fd_cloned) },
299             exclusive: self.exclusive,
300             port_name: self.port_name.clone(),
301             timeout: self.timeout,
302@@ -378,15 +363,9 @@ impl TTYPort {
303     }
304 }
305
306-impl Drop for TTYPort {
307-    fn drop(&mut self) {
308-        close(self.fd);
309-    }
310-}
311-
312 impl AsRawFd for TTYPort {
313     fn as_raw_fd(&self) -> RawFd {
314-        self.fd
315+        self.fd.as_raw_fd()
316     }
317 }
318
319@@ -395,7 +374,7 @@ impl IntoRawFd for TTYPort {
320         // Pull just the file descriptor out. We also prevent the destructor
321         // from being run by calling `mem::forget`. If we didn't do this, the
322         // port would be closed, which would make `into_raw_fd` unusable.
323-        let TTYPort { fd, .. } = self;
324+        let fd = self.fd.as_raw_fd();
325         mem::forget(self);
326         fd
327     }
328@@ -415,7 +394,7 @@ fn get_termios_speed(fd: RawFd) -> u32 {
329 impl FromRawFd for TTYPort {
330     unsafe fn from_raw_fd(fd: RawFd) -> Self {
331         TTYPort {
332-            fd,
333+            fd: unsafe { OwnedFd::from_raw_fd(fd) },
334             timeout: Duration::from_millis(100),
335             exclusive: ioctl::tiocexcl(fd).is_ok(),
336             // It is not trivial to get the file path corresponding to a file descriptor.
337@@ -432,27 +411,27 @@ impl FromRawFd for TTYPort {
338
339 impl io::Read for TTYPort {
340     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
341-        if let Err(e) = super::poll::wait_read_fd(self.fd, self.timeout) {
342+        if let Err(e) = super::poll::wait_read_fd(self.fd.as_fd(), self.timeout) {
343             return Err(io::Error::from(Error::from(e)));
344         }
345
346-        nix::unistd::read(self.fd, buf).map_err(|e| io::Error::from(Error::from(e)))
347+        nix::unistd::read(self.fd.as_raw_fd(), buf).map_err(|e| io::Error::from(Error::from(e)))
348     }
349 }
350
351 impl io::Write for TTYPort {
352     fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
353-        if let Err(e) = super::poll::wait_write_fd(self.fd, self.timeout) {
354+        if let Err(e) = super::poll::wait_write_fd(self.fd.as_fd(), self.timeout) {
355             return Err(io::Error::from(Error::from(e)));
356         }
357
358-        nix::unistd::write(self.fd, buf).map_err(|e| io::Error::from(Error::from(e)))
359+        nix::unistd::write(self.fd.as_fd(), buf).map_err(|e| io::Error::from(Error::from(e)))
360     }
361
362     fn flush(&mut self) -> io::Result<()> {
363         let timeout = Instant::now() + self.timeout;
364         loop {
365-            return match nix::sys::termios::tcdrain(self.fd) {
366+            return match nix::sys::termios::tcdrain(self.fd.as_fd()) {
367                 Ok(_) => Ok(()),
368                 Err(nix::errno::Errno::EINTR) => {
369                     // Retry flushing. But only up to the ports timeout for not retrying
370@@ -493,7 +472,7 @@ impl SerialPort for TTYPort {
371         )
372     ))]
373     fn baud_rate(&self) -> Result<u32> {
374-        let termios2 = ioctl::tcgets2(self.fd)?;
375+        let termios2 = ioctl::tcgets2(self.fd.as_raw_fd())?;
376
377         assert!(termios2.c_ospeed == termios2.c_ispeed);
378
379@@ -511,7 +490,7 @@ impl SerialPort for TTYPort {
380         target_os = "openbsd"
381     ))]
382     fn baud_rate(&self) -> Result<u32> {
383-        let termios = termios::get_termios(self.fd)?;
384+        let termios = termios::get_termios(self.fd.as_raw_fd())?;
385
386         let ospeed = unsafe { libc::cfgetospeed(&termios) };
387         let ispeed = unsafe { libc::cfgetispeed(&termios) };
388@@ -552,7 +531,7 @@ impl SerialPort for TTYPort {
389             B4800, B50, B57600, B600, B75, B9600,
390         };
391
392-        let termios = termios::get_termios(self.fd)?;
393+        let termios = termios::get_termios(self.fd.as_raw_fd())?;
394         let ospeed = unsafe { libc::cfgetospeed(&termios) };
395         let ispeed = unsafe { libc::cfgetispeed(&termios) };
396
397@@ -596,7 +575,7 @@ impl SerialPort for TTYPort {
398     }
399
400     fn data_bits(&self) -> Result<DataBits> {
401-        let termios = termios::get_termios(self.fd)?;
402+        let termios = termios::get_termios(self.fd.as_raw_fd())?;
403         match termios.c_cflag & libc::CSIZE {
404             libc::CS8 => Ok(DataBits::Eight),
405             libc::CS7 => Ok(DataBits::Seven),
406@@ -610,7 +589,7 @@ impl SerialPort for TTYPort {
407     }
408
409     fn flow_control(&self) -> Result<FlowControl> {
410-        let termios = termios::get_termios(self.fd)?;
411+        let termios = termios::get_termios(self.fd.as_raw_fd())?;
412         if termios.c_cflag & libc::CRTSCTS == libc::CRTSCTS {
413             Ok(FlowControl::Hardware)
414         } else if termios.c_iflag & (libc::IXON | libc::IXOFF) == (libc::IXON | libc::IXOFF) {
415@@ -621,7 +600,7 @@ impl SerialPort for TTYPort {
416     }
417
418     fn parity(&self) -> Result<Parity> {
419-        let termios = termios::get_termios(self.fd)?;
420+        let termios = termios::get_termios(self.fd.as_raw_fd())?;
421         if termios.c_cflag & libc::PARENB == libc::PARENB {
422             if termios.c_cflag & libc::PARODD == libc::PARODD {
423                 Ok(Parity::Odd)
424@@ -634,7 +613,7 @@ impl SerialPort for TTYPort {
425     }
426
427     fn stop_bits(&self) -> Result<StopBits> {
428-        let termios = termios::get_termios(self.fd)?;
429+        let termios = termios::get_termios(self.fd.as_raw_fd())?;
430         if termios.c_cflag & libc::CSTOPB == libc::CSTOPB {
431             Ok(StopBits::Two)
432         } else {
433@@ -655,53 +634,53 @@ impl SerialPort for TTYPort {
434         target_os = "linux"
435     ))]
436     fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()> {
437-        let mut termios = termios::get_termios(self.fd)?;
438+        let mut termios = termios::get_termios(self.fd.as_raw_fd())?;
439         termios::set_baud_rate(&mut termios, baud_rate)?;
440-        termios::set_termios(self.fd, &termios)
441+        termios::set_termios(self.fd.as_raw_fd(), &termios)
442     }
443
444     // Mac OS needs special logic for setting arbitrary baud rates.
445     #[cfg(any(target_os = "ios", target_os = "macos"))]
446     fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()> {
447-        ioctl::iossiospeed(self.fd, &(baud_rate as libc::speed_t))?;
448+        ioctl::iossiospeed(self.fd.as_raw_fd(), &(baud_rate as libc::speed_t))?;
449         self.baud_rate = baud_rate;
450         Ok(())
451     }
452
453     fn set_flow_control(&mut self, flow_control: FlowControl) -> Result<()> {
454-        let mut termios = termios::get_termios(self.fd)?;
455+        let mut termios = termios::get_termios(self.fd.as_raw_fd())?;
456         termios::set_flow_control(&mut termios, flow_control);
457         #[cfg(any(target_os = "ios", target_os = "macos"))]
458-        return termios::set_termios(self.fd, &termios, self.baud_rate);
459+        return termios::set_termios(self.fd.as_raw_fd(), &termios, self.baud_rate);
460         #[cfg(not(any(target_os = "ios", target_os = "macos")))]
461-        return termios::set_termios(self.fd, &termios);
462+        return termios::set_termios(self.fd.as_raw_fd(), &termios);
463     }
464
465     fn set_parity(&mut self, parity: Parity) -> Result<()> {
466-        let mut termios = termios::get_termios(self.fd)?;
467+        let mut termios = termios::get_termios(self.fd.as_raw_fd())?;
468         termios::set_parity(&mut termios, parity);
469         #[cfg(any(target_os = "ios", target_os = "macos"))]
470-        return termios::set_termios(self.fd, &termios, self.baud_rate);
471+        return termios::set_termios(self.fd.as_raw_fd(), &termios, self.baud_rate);
472         #[cfg(not(any(target_os = "ios", target_os = "macos")))]
473-        return termios::set_termios(self.fd, &termios);
474+        return termios::set_termios(self.fd.as_raw_fd(), &termios);
475     }
476
477     fn set_data_bits(&mut self, data_bits: DataBits) -> Result<()> {
478-        let mut termios = termios::get_termios(self.fd)?;
479+        let mut termios = termios::get_termios(self.fd.as_raw_fd())?;
480         termios::set_data_bits(&mut termios, data_bits);
481         #[cfg(any(target_os = "ios", target_os = "macos"))]
482-        return termios::set_termios(self.fd, &termios, self.baud_rate);
483+        return termios::set_termios(self.fd.as_raw_fd(), &termios, self.baud_rate);
484         #[cfg(not(any(target_os = "ios", target_os = "macos")))]
485-        return termios::set_termios(self.fd, &termios);
486+        return termios::set_termios(self.fd.as_raw_fd(), &termios);
487     }
488
489     fn set_stop_bits(&mut self, stop_bits: StopBits) -> Result<()> {
490-        let mut termios = termios::get_termios(self.fd)?;
491+        let mut termios = termios::get_termios(self.fd.as_raw_fd())?;
492         termios::set_stop_bits(&mut termios, stop_bits);
493         #[cfg(any(target_os = "ios", target_os = "macos"))]
494-        return termios::set_termios(self.fd, &termios, self.baud_rate);
495+        return termios::set_termios(self.fd.as_raw_fd(), &termios, self.baud_rate);
496         #[cfg(not(any(target_os = "ios", target_os = "macos")))]
497-        return termios::set_termios(self.fd, &termios);
498+        return termios::set_termios(self.fd.as_raw_fd(), &termios);
499     }
500
501     fn set_timeout(&mut self, timeout: Duration) -> Result<()> {
502@@ -734,11 +713,11 @@ impl SerialPort for TTYPort {
503     }
504
505     fn bytes_to_read(&self) -> Result<u32> {
506-        ioctl::fionread(self.fd)
507+        ioctl::fionread(self.fd.as_raw_fd())
508     }
509
510     fn bytes_to_write(&self) -> Result<u32> {
511-        ioctl::tiocoutq(self.fd)
512+        ioctl::tiocoutq(self.fd.as_raw_fd())
513     }
514
515     fn clear(&self, buffer_to_clear: ClearBuffer) -> Result<()> {
516@@ -748,7 +727,7 @@ impl SerialPort for TTYPort {
517             ClearBuffer::All => libc::TCIOFLUSH,
518         };
519
520-        let res = unsafe { nix::libc::tcflush(self.fd, buffer_id) };
521+        let res = unsafe { nix::libc::tcflush(self.fd.as_raw_fd(), buffer_id) };
522
523         nix::errno::Errno::result(res)
524             .map(|_| ())
525@@ -763,11 +742,11 @@ impl SerialPort for TTYPort {
526     }
527
528     fn set_break(&self) -> Result<()> {
529-        ioctl::tiocsbrk(self.fd)
530+        ioctl::tiocsbrk(self.fd.as_raw_fd())
531     }
532
533     fn clear_break(&self) -> Result<()> {
534-        ioctl::tioccbrk(self.fd)
535+        ioctl::tioccbrk(self.fd.as_raw_fd())
536     }
537 }
538
539