Git Product home page Git Product logo

Comments (6)

trezm avatar trezm commented on May 19, 2024 1

So after some noodling, I realized that hyper doesn't actually natively support unix sockets! I had to use hyperlocal in order to get all of the traits on the correct Unix streams.

With that in mind, I thought it easiest to add hyperlocal as an optional dependency and hide the whole thing behind a feature flag. This means that I actually went with the original solution you proposed @encendre, of implementing another server and ignoring the port. Not the most elegant solution, but will definitely work for now!

from thruster.

trezm avatar trezm commented on May 19, 2024

Yep, I very much like this functionality. I have a few thoughts about this. It looks to me like tokio models the incoming streams as separate structs. I don't have enough knowledge about why they're doing this, probably because of tcp vs unix data streams, but I bet they have good reasons.

With that in mind, I'd like to propose adding build_on_unix_socket to the HyperServer impl for now.

    async fn build_on_unix_socket(self, socket_addr: &str);

This could then be used just like start does with build internally, that is

        let server = HyperServer::new(app);
        tokio::runtime::Runtime::new()
            .unwrap()
            .block_on(server.build_on_unix_socket("/tmp/thruster.sock"))

Thoughts? This seems less invasive than adding it to a trait, and less work than maintaining a third set of ThrusterServer implementations.

from thruster.

encendre avatar encendre commented on May 19, 2024

I've been thinking about it.
I think a better solution would be to implement a method that allows the application to build on any hyper server configuration.

async fn build_on_hyper_builder(mut self, builder: hyper::server::Builder)

and then we just have to use this new method for writing the build method required by the ThrusterServer trait, like this

    async fn build(mut self, host: &str, port: u16) {
        let addr = (host, port).to_socket_addrs().unwrap().next().unwrap();
        let builder = Server::bind(&addr);
        self.build_on_hyper_builder(builder);
    }

This seems it covers more use cases, is still easy to build on unix socket for my use case

            let mut listener = tokio::net::UnixListener::bind("/tmp/thruster.sock").unwrap();
            let incoming = listener.incoming();
            let incoming = hyper::server::accept::from_stream(incoming);
            let builder = Server::builder(incoming);
            
            let server = HyperServer::new(app);
            tokio::runtime::Runtime::new()
                .unwrap()
                .block_on(server.build_on_hyper_builder(builder));

from thruster.

trezm avatar trezm commented on May 19, 2024

from thruster.

encendre avatar encendre commented on May 19, 2024

I tried to implement it but since I'm pretty new to rust I didn't succeed.
I have successfully compiled the crate adding the new method with and a few tricks that seem unnatural to me...
But the example I wrote doesn't work.

from thruster.

trezm avatar trezm commented on May 19, 2024

I can try this out today, not to worry! I'll post the PR here when it's done so you can compare with what you were doing and hopefully see where you were going astray :)

from thruster.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.