Skip to content

Conversation

@abezukor
Copy link
Contributor

@abezukor abezukor commented Jul 16, 2025

As discussed in my previous PR (#18) and (#33), it is a better interface to implement AsyncRead and AsyncWrite from futures-io, rather than use custom functions. This PR switches to that interface.

Open Questions

Should we remove the unstable feature? Are there any more changes expected for L2Cap?

Todos

  • After this gets merged, make another PR adding linux support.

@alexmoon
Copy link
Owner

That looks pretty good to me. @lulf can you review how the proposed L2CAP API would work for your use-case?

@lulf
Copy link
Contributor

lulf commented Jul 28, 2025

I'll give this a spin and a review, thanks @abezukor.

let stream = pin::pin!(&mut self.stream);
let ret = stream.poll_write(cx, buf);
ret
}
Copy link
Contributor

@lulf lulf Jul 29, 2025

Choose a reason for hiding this comment

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

Could we still expose the non-blocking try_write or is it available via some traits?

Choose a reason for hiding this comment

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

I've been using it as writer.write_all(&buf).await, from future-lite's pub trait AsyncWriteExt: AsyncWrite.
I think it does repeated poll_write(&whatevers_left_buf) until it returns Ok((0)) (written bytes) or Err.
Worked no prob for writing 100kb bytes buf

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but I need to be able to write to the output buffer in a non-async context, without blocking.

Copy link
Owner

Choose a reason for hiding this comment

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

You could use writer.write(...).now_or_never(). Or (equivalently) you could call writer.poll_write(Context::from_waker(Waker::noop()). They're not the most ergonomic options, but we could provide a try_write impl based on them if needed.

Copy link
Contributor

@lulf lulf Jul 29, 2025

Choose a reason for hiding this comment

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

Ah, thanks. now_or_never() was what I was looking for. It's not that easy to discover, but works for me.

Copy link
Contributor

@lulf lulf left a comment

Choose a reason for hiding this comment

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

Ok, so I confirm this works well on both android and ios for us

@alexmoon
Copy link
Owner

Thanks! @abezukor I think this should be ok to merge one the CI issues are resolved. I'd like to keep L2CAP unstable until we have the Linux implementation, just to be sure there's nothing we need to change.

@abezukor
Copy link
Contributor Author

abezukor commented Jul 30, 2025

Thanks! @abezukor I think this should be ok to merge one the CI issues are resolved. I'd like to keep L2CAP unstable until we have the Linux implementation, just to be sure there's nothing we need to change.

Thanks. I am on vacation without a laptop this week, but I should be able to fix the CI next week. I can also follow up with a Linux implementation.

@abezukor abezukor marked this pull request as ready for review July 30, 2025 17:56
@andrewzhurov
Copy link

andrewzhurov commented Jul 30, 2025

+1, kudos for the PR! I needed l2cap on android and linux, so been playing with it, adding linux l2cap via AsyncRead AsyncWrite traits as here (been of great help as reference). Could submit a PR once this gets merged, if that's of use?

(also added l2cap listener for android and linux, advertising, and extended scan fn with sercive-uuid filter)
Able to start listeners, advertise their PSM (on Android it's dynamic, assigned on listener creation), scan these ads to learn addresses + PSM of another device, open l2cap from Android to linux, send and read some bytes.
(for some reason opening l2cap from linux to Android time outs, investigating atm)
Anyhow, bunch of stuff, could start with that l2cap for linux PR.

@abezukor abezukor force-pushed the asyncrw_trait_for_l2cap branch from d5a6919 to 2655b5f Compare August 4, 2025 16:37
@alexmoon alexmoon merged commit bd21efa into alexmoon:main Aug 4, 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.

4 participants