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 serve_with_listener fro tonic::transport::server::Router #1096

Closed
MaxKingPor opened this issue Oct 3, 2022 · 4 comments
Closed

Add serve_with_listener fro tonic::transport::server::Router #1096

MaxKingPor opened this issue Oct 3, 2022 · 4 comments

Comments

@MaxKingPor
Copy link

MaxKingPor commented Oct 3, 2022

Feature Request

Crates

Motivation

  • Create Server from Tokio TcpListener
    image

Proposal

    pub async fn serve_with_listener<ResBody>(self, listener: TcpListener) -> Result<(), super::Error>
    where
        L: Layer<Routes>,
        L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
        <<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send + 'static,
        <<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<crate::Error> + Send,
        ResBody: http_body::Body<Data = Bytes> + Send + 'static,
        ResBody::Error: Into<crate::Error>,
    {
        let incoming = TcpIncoming::from_listener(
            listener,
            self.server.tcp_nodelay,
            self.server.tcp_keepalive,
        )
        .map_err(super::Error::from_source)?;

        self.server
            .serve_with_shutdown::<_, _, future::Ready<()>, _, _, ResBody>(
                self.routes,
                incoming,
                None,
            )
            .await
    }

image

Alternatives

@w41ter
Copy link
Contributor

w41ter commented Oct 8, 2022

You should use server_with_incoming instead of server_with_listener.

Here is an example:

    let listener = TcpListener::bind(addr).await?;
    let incoming = TcpIncoming::from_listener(listener, true);

    let server = Server::builder()
        .accept_http1(true) // Support http1 for admin service.
        .add_service(NodeServer::new(server.clone()))
        .add_service(RaftServer::new(server.clone()))
        .add_service(RootServer::new(server.clone()))
        .add_service(make_admin_service(server.clone()))
        .add_optional_service(proxy_server.map(EngulaServer::new))
        .serve_with_incoming(incoming);

@MaxKingPor
Copy link
Author

You should use server_with_incoming instead of server_with_listener.

Here is an example:

    let listener = TcpListener::bind(addr).await?;
    let incoming = TcpIncoming::from_listener(listener, true);

    let server = Server::builder()
        .accept_http1(true) // Support http1 for admin service.
        .add_service(NodeServer::new(server.clone()))
        .add_service(RaftServer::new(server.clone()))
        .add_service(RootServer::new(server.clone()))
        .add_service(make_admin_service(server.clone()))
        .add_optional_service(proxy_server.map(EngulaServer::new))
        .serve_with_incoming(incoming);

0A32A476
I created a PR , I hope it will be adopted

@w41ter
Copy link
Contributor

w41ter commented Oct 11, 2022

@MaxKingPor Hi, here already exists a PR: #1093.

@MaxKingPor
Copy link
Author

I'm sorry. I didn't see it. It's been closed.

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

No branches or pull requests

3 participants