apple / swift-nio-transport-services

Extensions for SwiftNIO to support Apple platforms as first-class citizens.
https://swiftpackageindex.com/apple/swift-nio-transport-services/main/documentation/niotransportservices
Apache License 2.0
282 stars 71 forks source link

Extract the NWConnection code into StateManagedNWConnectionChannel #174

Closed Joannis closed 1 year ago

Joannis commented 1 year ago

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:

Result:

This makes implementing UDP much simpler, and without redundant code.

Joannis commented 1 year ago

@Lukasa

Joannis commented 1 year ago

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.

Joannis commented 1 year ago

Updated now! I removed the lock from addressCache and moved it back into the getters and setters accessing the cache

Joannis commented 1 year ago

Updated @Lukasa , thanks for the quick reviews thus far. And have a nice weekend for now :)

Joannis commented 1 year ago

Ping @Lukasa

Lukasa commented 1 year ago

@swift-server-bot add to allowlist

Lukasa commented 1 year ago

To try to get this landed I took the liberty of just fixing the soundness violation myself.