-
Notifications
You must be signed in to change notification settings - Fork 25
Adding initial TCP server traits #30
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
Adding initial TCP server traits #30
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about the TCP side of things. Is it possible for a single socket to communicate with multiple clients at once? Or would you need multiple sockets listening on the same port? Or something else?
With a TCP server, you typically have a single socket listening on a given local port. It then receives connection requests from various remote clients and creates a new connection for each request. Each connection is assigned a unique socket for the communication stream, but the original listening socket remains operational to facilitate more connections. Thus, a single TCP server can serve any number of TCP clients that it wants to support simultaneously.
Based on my reading of
There is a single listening socket that creates new sockets for each accepted connection. |
That makes sense, thanks for explaining. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, once the stuff from @jonahd-g has been resolved 👍
Great work!
I have now written a small TCP echo server using the traits to verify that everything works as I would expect to - there was one modification to update If we'd like to add type-state control of the TCP listening socket, I would advocate we wait for another PR. There's some difficulties because of the |
I agree on this, as it seems like a super nice to have approach, but kind of out-of-reach at this point, unless one of you guys have the time to draft up such an API? So from my side of things, LGTM |
I'm willing to start working on a typestate solution, but I'd really like to see this current approach merged and released in the mean-time, considering the currently-released version does not support binding. |
LGTM. I think we can merge it the way it is and add type states in a new PR with a separate discussion. |
CC: @eldruin - this should now be ready for merge |
Thanks @ryan-summers! GitHub complains about conflicts, though. Could you rebase this? |
cb7d199
to
5adad7b
Compare
Alright, should now be fixed up after a rebase (there was indeed a conflict) |
Thanks everyone! |
This PR refactors the TCP traits to align with #21.
This PR fixes #27 by adding a new
TcpServer
trait.This PR fixes #16 by clarifying the life cycle of a TCP socket. (
socket()
->connect()
->close()
).This PR fixes #10 by updating
connect()
to return anb::Result
so that connect can be completed asynchronously.TODO:
std::net
for demonstration purposes.CC @MathiasKoch @chrysn