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

Iot.Device.SocketCan -> TryReadFrame() offer nonblocking mode? #2385

Open
tkoetting75q opened this issue Feb 24, 2025 · 3 comments
Open

Iot.Device.SocketCan -> TryReadFrame() offer nonblocking mode? #2385

tkoetting75q opened this issue Feb 24, 2025 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation Priority:2 Work that is important, but not critical for the release

Comments

@tkoetting75q
Copy link

From what I understand, Linux socket devices can be opened in a blocking or non-blocking mode for reading. Standard is blocking-mode.

=> Flags O_NONBLOCK, MSG_DONTWAIT in the C world

Would it be possible to implement this choice for Iot.Device.SocketCan.CanRaw?

many thanks!

@tkoetting75q tkoetting75q added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Feb 24, 2025
@krwq
Copy link
Member

krwq commented Feb 27, 2025

[Triage] @tkoetting75q when I wrote this class it wasn't exactly possible to use Socket + NetworkStream for this - right now it might be possible because we support AddressFamily.ControllerAreaNetwork which means we could rewrite native layer and replace it with NetworkStream where we should get Async for free.

So basically we should replace https://github.com/dotnet/iot/blob/main/src/devices/SocketCan/Interop.cs#L86 with Socket constructor with:

  • AddressFamily.ControllerAreaNetwork
  • SocketType.Raw
  • (ProtocolType)1 // CAN

and wrap that with NetworkStream - it's possible we would be able to get rid of native layer completely but I can't remember.

I probably won't have time to this anytime soon but I can help you with PR if you're interested.

@krwq krwq added Priority:2 Work that is important, but not critical for the release and removed untriaged labels Feb 27, 2025
@tkoetting75q
Copy link
Author

@krwq thanks for the hints. Since I'm still fairly new to c# I have a hard time following your suggestion. So a very quick and dirty example would be extremely helpful for me at this point.

@krwq
Copy link
Member

krwq commented Mar 6, 2025

I believe @pgrawehr might be interested in this work as well. I'm not sure how to write example without actually doing this but I don't have a setup anymore for CAN handy...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation Priority:2 Work that is important, but not critical for the release
Projects
None yet
Development

No branches or pull requests

2 participants