Skip to content

Commit

Permalink
feat(server): add from_tcp method
Browse files Browse the repository at this point in the history
Adds the `from_tcp()` method as per
#1602.

fix clippy changes
  • Loading branch information
yoshuawuyts committed Aug 7, 2018
1 parent 4020a2f commit 10628d4
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,31 @@
//! ```

pub mod conn;
#[cfg(feature = "runtime")] mod tcp;
#[cfg(feature = "runtime")]
mod tcp;

use std::fmt;
#[cfg(feature = "runtime")] use std::net::SocketAddr;
#[cfg(feature = "runtime")] use std::time::Duration;
#[cfg(feature = "runtime")]
use std::net;
#[cfg(feature = "runtime")]
use std::net::SocketAddr;
#[cfg(feature = "runtime")]
use std::time::Duration;

use futures::{Future, Stream, Poll};
use futures::{Future, Poll, Stream};
use tokio_io::{AsyncRead, AsyncWrite};
#[cfg(feature = "runtime")]
use tokio_reactor;
#[cfg(feature = "runtime")]
use tokio_tcp;

use body::{Body, Payload};
use service::{NewService, Service};
// Renamed `Http` as `Http_` for now so that people upgrading don't see an
// error that `hyper::server::Http` is private...
use self::conn::{Http as Http_, SpawnAll};
#[cfg(feature = "runtime")] use self::tcp::{AddrIncoming};
#[cfg(feature = "runtime")]
use self::tcp::AddrIncoming;

/// A listening HTTP server that accepts connections in both HTTP1 and HTTP2 by default.
///
Expand Down Expand Up @@ -96,6 +106,19 @@ impl<I> Server<I, ()> {
}
}

impl Server<tokio_tcp::Incoming, ()> {
/// Create a new instance from a `std::net::TcpListener` instance.
#[cfg(feature = "runtime")]
pub fn from_tcp(
listener: net::TcpListener,
) -> Result<Builder<tokio_tcp::Incoming>, ::Error> {
let handle = tokio_reactor::Handle::current();
let listener = tokio_tcp::TcpListener::from_std(listener, &handle)
.map_err(|err| ::Error::new_listen(err))?;
Ok(Self::builder(listener.incoming()))
}
}

#[cfg(feature = "runtime")]
impl Server<AddrIncoming, ()> {
/// Binds to the provided address, and returns a [`Builder`](Builder).
Expand Down Expand Up @@ -275,4 +298,3 @@ impl Builder<AddrIncoming> {
self
}
}

0 comments on commit 10628d4

Please sign in to comment.