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

Lwt_io.establish_server (TCP servers): expose client socket to connection-handling callback #586

Merged
merged 4 commits into from
Jun 20, 2018

Conversation

aantron
Copy link
Collaborator

@aantron aantron commented Apr 29, 2018

This is a follow-on to #323/#346 (cc @rgrinberg). It adds a function like:

val establish_server_with_client_socket :
  Unix.sockaddr ->
  (Unix.sockaddr -> Lwt_unix.file_descr -> (input_channel * output_channel) -> unit Lwt.t) ->
    server Lwt.t

...whereas existing versions of this function didn't pass the Lwt_unix.file_descr to the client-handling function, and only passed the sockaddr and the two channels.

I'm still not sure if this is the right API, but starting with this.

The PR also includes a pretty thorough cleanup of the existing code, so it should be easier to keep working on.

This commit consists of whitespace edits and alpha-renaming.
- Avoid Lwt.wakeup (synchronous control flow transfer). Use
  Lwt.wakeup_later.
- Use Lwt.async instead of Lwt.ignore_result. This has the side effect
  that exceptions during server startup (bind, listen) now go into
  rejecting the promise that Lwt_io.establish_server returns. Before,
  they were raised up the stack. This behavior was not specified,
  however. Most users can be expected to be ready for both behaviors,
  and the old behavior was a bug.
@aantron
Copy link
Collaborator Author

aantron commented Jun 20, 2018

This was motivated by inhabitedtype/httpaf#54. inhabitedtype/httpaf#53 also anticipated the type signature of establish_server_with_client_socket, so merging.

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.

1 participant