Closed Joannis closed 1 year ago
@Lukasa
In hindsight, I do think it's valuable to also add a common implementation for listener channels, and add that to UDP right away as well. Give me a bit more time.
EDIT: It'll be a second PR.
Updated now! I removed the lock from addressCache
and moved it back into the getters and setters accessing the cache
Updated @Lukasa , thanks for the quick reviews thus far. And have a nice weekend for now :)
Ping @Lukasa
@swift-server-bot add to allowlist
To try to get this landed I took the liberty of just fixing the soundness violation myself.
Extract the NWConnection code into StateManagedNWConnectionChannel
Motivation:
When implementing #68, a lot of code ended up being identical between TCP and UDP. This PR paves the way to adding UDP, with very little overhead code. It moves the code that is used to represent NWConnection as a Channel into its own protocol, that can then be applied to both TCP and UDP implementations.
Modifications:
StateManagedNWConnectionChannel
that has all the logic for handling a NWConnection as a NIO.Channel.NWOptionsProtocol
that can read and write socket options. This is applied toNWProtocolTCP.Option
StateManagedNWConnectionChannel
handles the common denominators between TCP and the future UDP implementaitonNWConnectionSubstate
that can handle changes in the ChannelState.Result:
This makes implementing UDP much simpler, and without redundant code.