Closed terrarier2111 closed 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?
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
You shouldn't be locking any of those things, just move them into the task that's using them.
I have my connections stored in a global struct and as i need mutable refs to the Datagrams struct i need locking
Do not store Datagrams
indefinitely in shared state. Move it into the task which uses it.
Is there any benefit to storing it exclusively in the task that's using it and not having it globally available?
Yes, in addition to the usual benefits of avoiding global state, it allows you to use it without extraneous synchronization.
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)