Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make device object immutable; support Musl platform #13

Merged
merged 11 commits into from
Oct 2, 2024
2 changes: 1 addition & 1 deletion Sources/LCLPing/HTTP/HTTPPingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ extension HTTPPingClient {
public let resolvedAddress: SocketAddress

/// The outgoing device associated with the given interface name
public var device: NIONetworkDevice?
public private(set) var device: NIONetworkDevice?

/// Initialize a HTTP Ping Client `Configuration`.
///
Expand Down
2 changes: 1 addition & 1 deletion Sources/LCLPing/HTTP/NIOHTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ final class NIOHTTPClient: Pingable {
default:
()
}
#elseif canImport(Glibc)
#elseif canImport(Glibc) || canImport(Musl)
return (channel as! SocketOptionProvider).setBindToDevice(device.name)
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/LCLPing/ICMP/ICMPPingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public final class ICMPPingClient: Pingable {
default:
()
}
#elseif canImport(Glibc)
#elseif canImport(Glibc) || canImport(Musl)
return (channel as! SocketOptionProvider).setBindToDevice(device.name)
#endif
}
Expand Down Expand Up @@ -235,7 +235,7 @@ extension ICMPPingClient {
public let resolvedAddress: SocketAddress

/// The outgoing device associated with the given interface name
public var device: NIONetworkDevice?
public private(set) var device: NIONetworkDevice?

public init(endpoint: EndpointTarget,
count: Int = 10,
Expand Down
12 changes: 10 additions & 2 deletions Sources/LCLPing/Utilities/LCLPing+SocketOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@

import Foundation
import NIOCore
#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#endif

extension NIOBSDSocket.Option {
#if canImport(Darwin)
public static let ip_bound_if: NIOBSDSocket.Option = Self(rawValue: IP_BOUND_IF)
public static let ipv6_bound_if: NIOBSDSocket.Option = Self(rawValue: IPV6_BOUND_IF)
#elseif canImport(Glibc)
#elseif canImport(Glibc) || canImport(Musl)
public static let so_bindtodevice = Self(rawValue: SO_BINDTODEVICE)
#endif
}

extension SocketOptionProvider {
#if canImport(Glibc)
#if canImport(Glibc) || canImport(Musl)

/// Sets the socket option SO_BINDTODEVICE to `value`.
///
/// - parameters:
Expand Down