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

Expose curio-like tcp_server_socket / unix_server_socket API #40

Closed
standy66 opened this issue Feb 3, 2019 · 4 comments
Closed

Expose curio-like tcp_server_socket / unix_server_socket API #40

standy66 opened this issue Feb 3, 2019 · 4 comments
Labels
wontfix This will not be worked on

Comments

@standy66
Copy link
Contributor

standy66 commented Feb 3, 2019

Curio separates socket construction logic into separate *_server_socket synchronous functions. This gives ability to start listening in synchronous context, then do something with the socket, e.g. get actual bound port number when port=0 was passed to auto select, and only after that start accepting connections in asynchronous context.

This is the use case that may be beneficial in unit tests, for example, consider the following scenario:

  1. Create a socket without any specific port, bind it and listen (sync)
  2. Get bound port number
  3. Spin up client thread / process with the port number obtained in part 2 (sync)
  4. Start accepting incoming connections (async)

I think it would be a great addition and this is really easy to implement.

@agronholm
Copy link
Owner

How exactly does this differ from what anyio offers? In this test, for example, I do something just like that.

@standy66
Copy link
Contributor Author

standy66 commented Feb 6, 2019

The difference is in the context. In your example socket is created and bound is async context. From there the only way to pass it back to sync context is to use threads and thread synchronization primitives. You cannot "yield" from anyio.run. I think the approach where socket is created in plain old blocking way is more versatile. But I understand that this is debatable.

@agronholm
Copy link
Owner

Perhaps I do not understand the use case. Can you elaborate on that? With an (pseudocode if needed) example if possible.

@agronholm
Copy link
Owner

It's been over three months without any feedback, so I'm closing this.

@agronholm agronholm added the wontfix This will not be worked on label May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants