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

5.0.0 proposal #34

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

5.0.0 proposal #34

wants to merge 18 commits into from

Conversation

zstewar1
Copy link

Removes the SerialPort trait, and instead creates a struct SerialPort which wraps and hides platform-specific serial port implementions (crate::sys::SerialPort). This removes the distinction between serial port trait objects and platform specific serial port structs, and prevents the need for using Box<dyn SerialPort> to write platform-agnostic code, since the SerialPort struct just compiles to the platform specific type. Platform specific behaviors are exposed as extension traits which only appear on the appropriate platform.

This PR is mostly ready, but may still require some documentation updates. It also has not be tested thoroughly at this point, since I don't have access to a mac and haven't had time to do tests on windows or linux. If this proposal seems good, I can go ahead and test it a bit more thoroughly.

Change SerialPort to a struct, and move the implementation to a "sys"
module which selects between different possible "real" implementations.
Add a public posix module containing a posix-specific SerialPortExt
trait and the BreakDuration type.
Get the windows build working. Remove the windows-specific extensions
module because windows doesn't have any methods not available on posix.
One of the CI toolchains uses an older version of rustc, which doesn't
include as_deref, so we just do the same thing that as_deref does
internally.
Implementing the extension in the posix extension mod ensures it will
appear in documentation even if documentation is built on windows, since
that mod is cfg(doc).
Current timeouts are based on
[this comment from !78](https://gitlab.com/susurrus/serialport-rs/-/merge_requests/78#note_343695538),
copying the windows timeout settings needed to get posix-like timeout
behavior. That is, reads should return available data ASAP regardless of
timeouts, but stop early when there is a timeout.
EventCache will hold the HANDLE for a read/write when not in use or will
produce a new handle for each thread when multiple threads try to
read/write at the same time. The cache holds a single value and will
deallocate extra handles when there is already a handle stored. We have
one cache for a read_handle and one cache for a write_handle.

The expectation is that in the normal case, at most one thread will be
reading/writing at a time, and so at most one handle will be created for
each of read and write. But in abnormal cases, when multiple threads try
to read/write at the same time, we auto-create and auto-close extra
handles as needed.

Fix the into_raw_handle/into_raw_fd to drop other fields that were
previously leaked.
@jessebraham
Copy link
Member

Thanks for the PR, sorry for the late response.

Just to set your expectations, I likely won't be getting to this for awhile. I'm still working on getting all the details of the fork settled and would also like to release at least one more 4.x.x version first. I promise to come back to this at some point though!

@eldruin eldruin added this to the 5.0.0 milestone Mar 17, 2023
@sirhcel sirhcel mentioned this pull request Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants