Skip to content

Conversation

@abezukor
Copy link
Contributor

@abezukor abezukor commented Aug 4, 2025

Adds Linux L2Cap Support.

bluer uses tokio::io::{AsyncRead, AsyncWrite} instead of futires_io::{AsyncRead, AsyncWrite}, so to maintain cross-platform compatibility, I wrap the bluer stream inside an Compat.

@alexmoon
Copy link
Owner

alexmoon commented Aug 4, 2025

Instead of exposing the underlying platform-specific type, I think I'd rather have an optional implementation of the Tokio traits. I'm ok with an optional dependency on Tokio on other platforms.

This also modifies the public api to rely on `AsyncWrite::poll_close`
and `Drop` for closing the l2cap channels instead of having bespoke
functions for it
@abezukor
Copy link
Contributor Author

Instead of exposing the underlying platform-specific type, I think I'd rather have an optional implementation of the Tokio traits. I'm ok with an optional dependency on Tokio on other platforms.

I may want to add the feature in a future PR. For now, the function has been removed.

@abezukor abezukor marked this pull request as ready for review August 17, 2025 07:10
@abezukor
Copy link
Contributor Author

Android ci is blocked until #41 is merged.

@abezukor abezukor changed the title WIP: l2cap: Linux Support l2cap: Linux Support Aug 17, 2025
Comment on lines -32 to -41
/// Close the L2CAP channel.
///
/// This closes the entire channel, in both directions (reading and writing).
///
/// The channel is automatically closed when `L2capChannel` is dropped, so
/// you don't need to call this explicitly.
#[inline]
pub async fn close(&mut self) -> Result<()> {
self.writer.close().await
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep this function here and on the reader/writer halves. It's the only way to asynchronously wait for the close to complete and get any error related to closing the channel.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, I think it should be changed to return a std::io::Result like the rest of the l2cap functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep it on the writers? AsyncWriteExt::close exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with creating close functions for the reader is some platforms dont support that behavior. The OwnedReadHalf on linux does not seem to have a close function that closes the writer half.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's remove it from the non-writers on all platforms then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did. What do you think I missed.

src/lib.rs Outdated
pub mod error;

#[cfg(feature = "l2cap")]
#[macro_use]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer using pub(crate) ... instead of #[macro_use]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL you could use pub(crate) use macro_name to scope macro definitions instead of #[macro_use]. Thanks for letting me know about this. Now, I just wish you could use pub(crate) macro_rules!

```
warning: the following packages contain code that will be rejected by a
future version of Rust: bluer v0.16.1
note: to see what the problems were, use the option
`--future-incompat-report`, or run `cargo report
future-incompatibilities --id 1`
```
@abezukor
Copy link
Contributor Author

@alexmoon Is there anything I should be doing to get this merged? As far as I can tell, I have addressed all the comments.

@alexmoon
Copy link
Owner

Sorry for the delay. Looks good to me.

@alexmoon alexmoon merged commit 37e353d into alexmoon:main Sep 29, 2025
4 checks passed
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.

2 participants