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

More beginner-friendly TCP server example #102

Merged
merged 15 commits into from
Sep 16, 2020
Merged

Conversation

lbernick
Copy link
Contributor

I wanted to write an example to help guide people new to asynchronous programming, with fewer external dependencies (as some people requested in #66). The example starts with the single threaded TCP server from the Rust book and uses async functionality to add concurrency.
The example goes through:

  • some examples of blocking code and how to make them non blocking (should address Blocking thread::sleep inside an async fn #64 as well)
  • spawning tasks vs using combinators to run them concurrently on a single thread
  • testing code by creating mocks and implementing async read/write traits for the mocks

Happy to receive any feedback.

Copy link
Contributor

@betamos betamos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton Lee. Please reach out if any comments are unclear.

Copy link
Contributor

@betamos betamos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again, and sorry for the delayed response.

One strategy could be to refactor the code to be more modular,
and only test that the correct responses are returned for the respective inputs.

Another strategy is to connect to `localhost` on port 0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with the port you used, 7878?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7878 is fine, but I wrote this due to a preference that the test code should be able to run on any server, where other things might be using port 7878. I believe I also saw this used in the tests for smol. No strong preference here.

Copy link
Contributor

@betamos betamos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much Lee. Great to see this. Just a couple of minor nits left, but LGTM. There are also a couple of spellchecker quirks remaining.

Copy link
Member

@tmandry tmandry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left a few more nits and suggestions, otherwise I think this is ready to merge.

@tmandry tmandry merged commit 87015e2 into rust-lang:master Sep 16, 2020
@tmandry
Copy link
Member

tmandry commented Sep 16, 2020

Merged. Thank you!

@lbernick lbernick deleted the tcpserver branch September 23, 2020 12:05
huangjj27 pushed a commit to huangjj27/async-book that referenced this pull request Jan 1, 2021
I wanted to write an example to help guide people new to asynchronous programming, with fewer external dependencies (as some people requested in #66). The example starts with the [single threaded TCP server from the Rust book](https://doc.rust-lang.org/book/ch20-01-single-threaded.html) and uses async functionality to add concurrency.
The example goes through:
- some examples of blocking code and how to make them non blocking (should address #64 as well)
- spawning tasks vs using combinators to run them concurrently on a single thread
- testing code by creating mocks and implementing async read/write traits for the mocks
huangjj27 pushed a commit to huangjj27/async-book that referenced this pull request Jun 25, 2022
I wanted to write an example to help guide people new to asynchronous programming, with fewer external dependencies (as some people requested in #66). The example starts with the [single threaded TCP server from the Rust book](https://doc.rust-lang.org/book/ch20-01-single-threaded.html) and uses async functionality to add concurrency.
The example goes through:
- some examples of blocking code and how to make them non blocking (should address #64 as well)
- spawning tasks vs using combinators to run them concurrently on a single thread
- testing code by creating mocks and implementing async read/write traits for the mocks
huangjj27 pushed a commit to huangjj27/async-book that referenced this pull request Jul 9, 2022
I wanted to write an example to help guide people new to asynchronous programming, with fewer external dependencies (as some people requested in #66). The example starts with the [single threaded TCP server from the Rust book](https://doc.rust-lang.org/book/ch20-01-single-threaded.html) and uses async functionality to add concurrency.
The example goes through:
- some examples of blocking code and how to make them non blocking (should address #64 as well)
- spawning tasks vs using combinators to run them concurrently on a single thread
- testing code by creating mocks and implementing async read/write traits for the mocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants