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

Add Async support #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add Async support #18

wants to merge 1 commit into from

Conversation

georgyo
Copy link

@georgyo georgyo commented Jul 23, 2023

This adds Async support, it has been tested by using these modules in the Churrua DHCP server, and works well.

Since Async depends on Core and ppx_jane already, I used that in the rawcap_async test binary. It could just as easily use Async.Deferred.run_in_async_wait instead of the Command module to start the process. If there is desire to keep rawcap_async as minimal as possible.

Copy link
Owner

@haesbaert haesbaert left a comment

Choose a reason for hiding this comment

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

I like this, thank you :)

I'm not keen on maintaining async stuff myself, so if you're ok with maintaining this async bits in the future I'd appreciate, otherwise it will end up rotting.

rawlink-async.opam Show resolved Hide resolved
let send_packet t buf =
let len = Cstruct.length buf in
let writer = Writer.create t.fd in
Writer.write_bytes ~pos:0 ~len writer (Cstruct.to_bytes ~len buf);
Copy link
Owner

Choose a reason for hiding this comment

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

I don't know async at all, but is this the only way to do a write ? does it guarantee this is one system call ? These are all datagram-like file descriptors, meaning one write = one packet.
I guess this is ok but maybe there is a single_write and whatnot.

Copy link
Author

Choose a reason for hiding this comment

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

I've looked it over and it does look like I need to use Writer.write_gen_whole to ensure we don't break up the write. Unfortunately that interface seems needlessly obtuse. I'll switch it to that function shortly.

Copy link
Author

Choose a reason for hiding this comment

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

schedule_write does the correct thing, and now much more closely matches what lwt and eio are doing.

@georgyo georgyo force-pushed the async branch 2 times, most recently from 0e54b9c to 230ee73 Compare July 27, 2023 10:41
@haesbaert
Copy link
Owner

That's great, I'll have a proper review in this and all the other PRs tomorrow, I'll test this during the weekend in my network home to see if nothing breaks

thanks again for your work

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.

None yet

2 participants