-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Server-side FFI bindings #3084
base: master
Are you sure you want to change the base?
Server-side FFI bindings #3084
Conversation
* Fix some compiler issues (signedness and pointer sizing) * Include What You Use * Sort the includes
Fix header handling for requests See merge request amc/hyper-ffi!2
Hi @seanmonstar! Hope all's going well. Investigations and implementation is continuing and they threw up an interesting problem that I wanted to flag with you. The basic problem is that when setting userdata on The original implementation of the C server code just magically "knew" that when a server connection task completed the IO userdata and service userdata that backed it were no longer needed and could be freed, and to achieve this those userdata pointers were duplicated in the task userdata. This design means that there are multiple references to the IO/service userdata alive at the same time and the code frees one set of them when it's "pretty sure" the other ones have been forgotten and won't be read again. This made our C developers rightly nervous 😨 so I've implemented a different strategy that's more similar to how Rust would manage the memory.
I'm raising this change specifically as it's the first breaking change to the existing client-facing bindings that this MR has introduced 😄 and hence I wanted to get your opinion on the approach. I will say that the related changes to the example server integration ( Additional Thoughts
|
Coming back to those additional thoughts, I've come to the conclusion that it's better to be consistent everywhere, so I've re-read your last comment (re: stability guarantees) and I may have misunderstood your question, are you proposing a I think the changes are now ready for review (the team that has been integrating with them has got their pre-existing test suite passing with these changes 😄 ). It would be great to try and get this in if possible (otherwise the branch will keep getting stale and needing catchup merges). |
Yes, that's probably the best way to do it. Whenever something does go stable, we just explicitly say which types/functions are stable in the changelog. |
Coming back to this, I've merged the latest master in to this branch and fixed up the discrepancies. Do you think you'll be able to review this soon to prevent it bit-rotting again? |
@bossmc and @seanmonstar What is the status of this PR? |
Agh, I forgot about this. Well, the main consumer that motivated my adding of FFI support initially no longer needs hyper (the client types existed for a backend in curl). That means I no longer have something pushing me to pay attention, and my current clients aren't asking for it, but rather other things that take my attention. So, any further progress on either would be entirely on other contributors. I don't want to be a blocker here, I'm fine with this part of hyper being reviewed/maintained by anyone else. Especially while it's "unstable". If Andy and/or anyone else wants to take that on, I can get out of the way. |
Continues the work started in #2278 by adding bindings to allow using hyper's server stack from a C runtime. The patterns are based on the model used on the client side, and the two can be used simultaneously (e.g. using the client bindings to make down-stream HTTP calls as part of serving an upstream request).
I understand that the project is currently focussed on the 1.0 stabilization (woo!) and I realise that this MR isn't part of that process, but there's various teams across my area of Microsoft who would really like to start using hyper in our C/C++ projects to take advantage of the benefits that hyper is already providing to our Rust codebases elsewhere. Thus it would be really great to get a first-pass review of the approach soon to try and head off any churn down the line, if possible?
I've added an example C integration (
capi/examples/server.c
) that simply logs information about the request then responds with a 404 to everything.Implementation details of note:
epoll_wait
's timeout argument though there is alsoepoll_pwait2
which goes down to nanoseconds so maybe the FFI should expose them?ffi
feature depend on all the other related features for now, mostly as a QoL for people using the FFI bindings (since the FFI code isn't feature aware yet)AutoConnection
layer that restores the behaviour of "trying HTTP/1.x and, if it sees the HTTP/2 prelude rewinds and switches to HTTP/2 mode". I've tried to make this generic so it is possibly in a fit state to be lifted to hyper-utils rather than being in the FFI code?Other smaller notes:
cargo expand
's ability to show a single module from a crate (so we no longer need to build a fake crate to be able to run bindgen)Sleep
auto-impl for things that look likeSleep
again as a QoL thingI've tested the server example code under
valgrind
and-fsanitize=memory
to ensure there's no use-after-free/double-free/etc.