-
Notifications
You must be signed in to change notification settings - Fork 125
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 top-level function for starting a server with a provided Handle #95
Comments
Yes, that's possible. See #66 (comment) |
Great, thanks! I'll check that out. |
Hi @kierdavis you absolutely can and @ChristophWurst has pointed out one option for doing that which should work for However we've recently merged in #89 which may have broken this method if you're using Gotham master (which represents the 0.2 release, I'd actually recommend using this if you're embarking on a new application, there are a lot of bug fixes and new features coming in 0.2) What would be really useful, if you have the time, is a |
Thanks for the info! I'm currently running v0.1 as that the latest available on crates.io, but I'm all for switching to 0.2 when it becomes available. I'm happy to have a crack at implementing As my original question has been answered (@ChristophWurst's suggestion is working perfectly for me) I'll rename this issue to be more inline with the feature request side of things. |
So @smangelsdorf and I have just thrown this very discussion around ourselves. What Our thinking is that having That would mean it would be up to the implementing application to create a core per thread (assuming they wanted that) to mirror what Gotham would normally do in Thoughts on this approach? |
I like this approach. My only concern is that |
I suppose |
That seems reasonable for From the brief look at the Windows side I've just had it does seem like cc @smangelsdorf. |
Maybe under
Under the current implementation, yes, that's my belief too.
Not in its current form. It's currently platform-specific too, so it would be a difference in the per-platform API if it was |
@smangelsdorf see #121, in which the first half of this feature (decoupling core creation from
That's a good point. Perhaps this could be encapsulated in a platform-independent way as a public function that returns a set of top-level futures (i.e. the object returned by This approach does however leave the problem that the construction of each future requires a At this point I'd like to mention that now I've dug deeper into gotham's sources and learnt more about how both gotham and tokio work, my application would probably be better off if I just ran my other service in its own event loop in another thread, analogous to how gotham spawns instances of |
Brain dump: I think #121 has taken this in the right direction, though as I was alluding to earlier, I'd want us to prevent the divergence between the Obviously I'd like us to avoid as much standard boilerplate as possible for a correctly implemented Gotham app, but this especially applies to conditional compilation stuff. One concept I have in mind (which is thoroughly untested) for going forward with this is to change the fn serve<'a, G, NH>(
listener: G,
protocol: &'a Http,
new_handler: Arc<NH>,
handle: &'a Handle,
) -> Box<Future<Item = (), Error = io::Error> + 'a>
where
G: GothamListener,
NH: NewHandler + 'static,
{
// ...
}
trait GothamListener {
// Something which basically acts as a `Stream<Item = (TcpSocket, SocketAddr)>`. Also possible
// that we could just use the `Stream` trait directly instead of introducing our own, if we
// found a way to do it within the orphan rules.
} With that, we could add a new // os/unix.rs
/// Creates a server socket which can be cloned for `accept()` to be called in
/// each Tokio `Core`.
fn gotham_listener<A>(addr: A) -> (TcpListener, SocketAddr)
where
A: ToSocketAddrs,
{
// ...
}
impl GothamListener for (TcpListener, SocketAddr) {
// ...
} // os/windows.rs
/// Spins up a thread in the background which holds the sender side of the
/// `SocketQueue` which is returned here.
fn gotham_listener<A>(addr: A) -> SocketQueue
where
A: ToSocketAddrs,
{
// ...
}
impl GothamListener for SocketQueue {
// ...
} Errors and omissions aside, this should allow the same app code to compile and run on all supported platforms. Thoughts, improvements, etc. welcome of course 😁 |
#254 should resolve this, although it will ship with v0.3.0 which uses |
I would like to run two tokio-based servers in parallel in my application, one of which is a Gotham HTTP server. As far as my understanding of tokio goes, it ought to be possible to create one event loop and register both services onto it.
Is there a way to start a Gotham server using a provided tokio
Handle
, rather than letting it create its own event loop? If not, and you feel that its a reasonable feature to implement, I'm happy to work on adding this behaviour.The text was updated successfully, but these errors were encountered: