From 08267e0d6c243bc19a5753f3475a4ad01c0eaa63 Mon Sep 17 00:00:00 2001 From: Simon Whitty Date: Sat, 23 Nov 2024 13:07:34 +1100 Subject: [PATCH] remove AnySocketAddress --- FlyingSocks/Sources/AsyncSocket.swift | 12 ++---------- FlyingSocks/Sources/Socket.swift | 6 +++--- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/FlyingSocks/Sources/AsyncSocket.swift b/FlyingSocks/Sources/AsyncSocket.swift index 76e5f55f..04325859 100644 --- a/FlyingSocks/Sources/AsyncSocket.swift +++ b/FlyingSocks/Sources/AsyncSocket.swift @@ -231,7 +231,7 @@ public struct AsyncSocket: Sendable { message: [UInt8], to peerAddress: some SocketAddress, interfaceIndex: UInt32? = nil, - from localAddress: (some SocketAddress)? = nil + from localAddress: (any SocketAddress)? = nil ) async throws { let sent = try await pool.loopUntilReady(for: .write, on: socket) { try socket.send(message: message, to: peerAddress, interfaceIndex: interfaceIndex, from: localAddress) @@ -251,19 +251,11 @@ public struct AsyncSocket: Sendable { } public func send(message: Message) async throws { - let localAddress: AnySocketAddress? - - if let unwrappedLocalAddress = message.localAddress { - localAddress = AnySocketAddress(unwrappedLocalAddress) - } else { - localAddress = nil - } - try await send( message: message.bytes, to: AnySocketAddress(message.peerAddress), interfaceIndex: message.interfaceIndex, - from: localAddress + from: message.localAddress ) } #endif diff --git a/FlyingSocks/Sources/Socket.swift b/FlyingSocks/Sources/Socket.swift index 58dbd473..7b6669d0 100644 --- a/FlyingSocks/Sources/Socket.swift +++ b/FlyingSocks/Sources/Socket.swift @@ -397,7 +397,7 @@ public struct Socket: Sendable, Hashable { message: [UInt8], to peerAddress: some SocketAddress, interfaceIndex: UInt32? = nil, - from localAddress: (some SocketAddress)? = nil + from localAddress: (any SocketAddress)? = nil ) throws -> Int { try message.withUnsafeBytes { buffer in try send( @@ -417,7 +417,7 @@ public struct Socket: Sendable, Hashable { flags: Int32, to peerAddress: some SocketAddress, interfaceIndex: UInt32? = nil, - from localAddress: (some SocketAddress)? = nil + from localAddress: (any SocketAddress)? = nil ) throws -> Int { var iov = iovec() var msg = msghdr() @@ -685,7 +685,7 @@ fileprivate extension Socket { static func withPacketInfoControl( family: sa_family_t, interfaceIndex: UInt32?, - address: (some SocketAddress)?, + address: (any SocketAddress)?, _ body: (UnsafePointer?, ControlMessageHeaderLengthType) -> T ) -> T { switch Int32(family) {