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

Add support for splittings conns #64

Open
Adrian8115 opened this issue Apr 27, 2024 · 4 comments
Open

Add support for splittings conns #64

Adrian8115 opened this issue Apr 27, 2024 · 4 comments
Labels
2 weeks Projection of 2 week for this issue to be completed. API Break Breaks the API Enhancement New feature or request Minor This issue or PR contains minor changes

Comments

@Adrian8115
Copy link

Adrian8115 commented Apr 27, 2024

In an async server software you often have a loop which recv packets and some sort of client struct that contains a way to send packets.
This would mean we would either need to copy/clone the connection or split it.

Tokio's tcp stream has a nice way to split it into a recv half and write half.

use tokio::prelude::*;
use tokio::net::TcpStream;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut stream = TcpStream::connect("localhost:8080").await?;
    let (mut read, mut write) = tokio::io::split(stream);

    tokio::spawn(async move {
        loop {
            let mut buf = [0u8; 32];
            read.read(&mut buf).await.unwrap();
            println!("{:?}", std::str::from_utf8(&buf));
        }
    });

    Ok(())
}

this code is from stack overflow

Even though Raknet uses udp it would still be nice if an api for splitting the connection or copying/cloning it would be added.
This is very important for writing effiecient server software that utilise multi threading.

@john-bv john-bv added Enhancement New feature or request Future This issue or PR is something that will be added in the future. Unconfirmed This bug/issue has not been confirmed yet API Break Breaks the API and removed Future This issue or PR is something that will be added in the future. labels Apr 27, 2024
@john-bv
Copy link
Member

john-bv commented Apr 28, 2024

This is technically already supported internally, however this does add some refactoring and would require an API minor bump since this change would break the current API. I will look into this, but this change will target 0.4.0 rather than 0.3.0

@john-bv john-bv added 2 weeks Projection of 2 week for this issue to be completed. Minor This issue or PR contains minor changes and removed Unconfirmed This bug/issue has not been confirmed yet labels Apr 28, 2024
@Adrian8115
Copy link
Author

how is this looking?

@john-bv
Copy link
Member

john-bv commented Jun 13, 2024

I will work on this sometime in July, I'm currently way to busy figuring out IRL stuff, I apologize.

@Adrian8115
Copy link
Author

Adrian8115 commented Jun 29, 2024

After careful consideration, this change may not be needed. I looked into this further and one simple solution stuck out to me. One can simply create a new tokio task and return a clonable object full with channels to communicate with that task, to for example send packets, recieve packets or close the connection. This type of impl would not need any split cabability. I used this solution a lot and it works great.

It might be useful creating an example for that. I hope I can look into it, once I got the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 weeks Projection of 2 week for this issue to be completed. API Break Breaks the API Enhancement New feature or request Minor This issue or PR contains minor changes
Projects
None yet
Development

No branches or pull requests

2 participants