- Notifications
You must be signed in to change notification settings - Fork81
add basic support for async-io#41
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
I noticed, after looking at the corresponding tokio code for a little while, that I don't actually need to reimplement the read logic at all.. I'll push an update this evening. |
- use blocking read/write methods instead of custom implementation- use macro for entire implementation
Rebased and cleaned up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We'll probably want to work on this one and the tokio one to make sure that have the same (or nearly) the same API, but this is a good start in that direction.
Oh, also, just FYI:
I realize you pulled this out from the PR, but in general, it's a standard practice in socket programming to zero out structs like socket addresses, an then just fill in the needed fields, knowing the rest are zero. But you are right that |
jreppnow commentedMay 11, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@fpagliughi Yeah, certainly true when you are the one filling the data, but when passing a buffer or a frame as on out parameter to a kernel method for it to write into, there is generally no need to initialise (if you only use the the data if you don't get an error an only until the length returned by the kernel method). If you look at the examples in the kernel docs, you will see that they also do not initialise out buffers/frames:https://docs.kernel.org/networking/can.html When filling my own struct in C (read: writing to a socket), I've personally moved away from memset(0) and just use always struct initialisation, as I consider it a lot safer (you can't forget about the memset): structmy_struct {size_tsize,void*ptr, }voidmain(void) {// Stack versionstructmy_structms= {.size=14};// Non-mentioned values are "static default initialised", which means zeroed for primitivesassert(!ms.ptr);// through pointerstructmy_struct*ptr=malloc(sizeof(*ptr));*ptr= (structmy_struct) {.ptr=ptr};assert(!ptr->size);} |
fpagliughi commentedMay 11, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
BTW... I'm a little unsure of keeping the macro from this PR in the long run:
|
Uh oh!
There was an error while loading.Please reload this page.
As discussed in#39, this adds basic support for async-io based async runtimes like async-std and smol. Couple of notes:
I did not add a direct constructor, instead relying on TryFrom<CanSocket/CanFdSocket>. This could be added easily though.as_sync_socket
methods.Instead of using the mem::zeroed-based approach when reading, I actually went with the MaybeUninit strategy, which I believe to be sound. However, I can go back to the zeroed version used for the synchronous read operations.Now just using the synchronous methods.Thanks for any feedback!