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

Refactor the server module #1013

Merged
merged 1 commit into from
Jan 18, 2017
Merged

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.
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