Skip to content

Conversation

alexcrichton
Copy link
Contributor

This commit refactors the server module as we discussed a bit offline.
The main changes are:

  • The entry point is how Http, the implementation of ServerProto.
    This type has a new constructor as well as builder methods to
    configure it.

  • A high-level entry point of Http::bind was added which returns a
    Server. Binding a protocol to a port requires a socket address
    (where to bind) as well as the instance of NewService. Internally
    this creates a core and a TCP listener.

  • The returned Server has a few methods to learn about itself, e.g.
    local_addr and handle, but mainly has two methods: run and
    run_until.

  • The Server::run entry point will execute a server infinitely, never
    having it exit.

  • The Server::run_until method is intended as a graceful shutdown
    mechanism. When the provided future resolves the server stops
    accepting connections immediately and then waits for a fixed period of
    time for all active connections to get torn down, after which the
    whole server is torn down anyway.

  • Finally a Http::bind_connection method exists as a low-level entry
    point to spawning a server connection. This is used by Server::run
    as is intended for external use in other event loops if necessary or
    otherwise low-level needs.

This commit refactors the `server` module as we discussed a bit offline.
The main changes are:

* The entry point is how `Http`, the implementation of `ServerProto`.
  This type has a `new` constructor as well as builder methods to
  configure it.

* A high-level entry point of `Http::bind` was added which returns a
  `Server`. Binding a protocol to a port requires a socket address
  (where to bind) as well as the instance of `NewService`. Internally
  this creates a core and a TCP listener.

* The returned `Server` has a few methods to learn about itself, e.g.
  `local_addr` and `handle`, but mainly has two methods: `run` and
  `run_until`.

* The `Server::run` entry point will execute a server infinitely, never
  having it exit.

* The `Server::run_until` method is intended as a graceful shutdown
  mechanism. When the provided future resolves the server stops
  accepting connections immediately and then waits for a fixed period of
  time for all active connections to get torn down, after which the
  whole server is torn down anyway.

* Finally a `Http::bind_connection` method exists as a low-level entry
  point to spawning a server connection. This is used by `Server::run`
  as is intended for external use in other event loops if necessary or
  otherwise low-level needs.
@seanmonstar seanmonstar changed the base branch from tokio to master January 17, 2017 23:40
@seanmonstar seanmonstar changed the base branch from master to tokio January 17, 2017 23:41
@seanmonstar
Copy link
Member

Er, I didn't realize deleting that branch would close this. I had finished merging the tokio branch into master, and it was now out of date. Also, noticed there is a compile error in the benches/end_to_end.rs.

@alexcrichton
Copy link
Contributor Author

Sure thing, I'll send the PR against master instead

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

Successfully merging this pull request may close these issues.

2 participants