quinn-rs / quinn

Async-friendly QUIC implementation in Rust
Apache License 2.0
3.76k stars 380 forks source link

Receive and Write datagrams simultanously #1420

Closed terrarier2111 closed 1 year ago

terrarier2111 commented 1 year ago

Is there a way to have 2 separate tasks, 1 waiting for new datagrams to arrive and another one sending out new datagrams? (this question might be dumb and the issue might be resolved with the new Api but i didn't find a solution so far with quinn 0.8.5)

djc commented 1 year ago

I don't see why not? After connecting you get a NewConnection which contains both a Connection and a Datagrams. You can spawn one task with the Connection (which can send datagrams) and one with Datagrams (which can receive them). What's the problem?

terrarier2111 commented 1 year ago

I had to split the NewConnection struct into its pieces and put them all together into a new struct i created myself but with RwLocks around them to make locking more fine grained, because a big lock around NewConnection would only allow me to either read datagrams or write new ones

Ralith commented 1 year ago

You shouldn't be locking any of those things, just move them into the task that's using them.

terrarier2111 commented 1 year ago

I have my connections stored in a global struct and as i need mutable refs to the Datagrams struct i need locking

Ralith commented 1 year ago

Do not store Datagrams indefinitely in shared state. Move it into the task which uses it.

terrarier2111 commented 1 year ago

Is there any benefit to storing it exclusively in the task that's using it and not having it globally available?

Ralith commented 1 year ago

Yes, in addition to the usual benefits of avoiding global state, it allows you to use it without extraneous synchronization.