I am building a protocol (trying to emulate something, so I have to stick to the specs) that is UDP based but on top of UDP, they somehow emulate something like TCP with sequence numbers and the like.
For now everything is tokio and async await based (although I am open to suggestions here). I am trying to find an idiomatic pattern to have the listening loop working in the "background" (actually multiple listening loops on top of each other regarding the layers of the protocol).
Is this idiomatic? Is there any better way? I don't like how it forces me to lock the connection and timeout every now and then so others can have the chance to lock it and see if there is any packet available.
I am in the process of splitting this and the layer which orchestrates the UDP connection would need to have the ability to split UDPConnection layer into two as well, send and receive to keep things separate. Wow, this is becoming on one side more complicated because I need more classes, but also a lot better because there is no need for locks. But I am going to need locks because once the session is established, send and receive need to share some data.