Skip to content

Commit

Permalink
Make device object immutable; support Musl platform (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnzhou authored Oct 2, 2024
1 parent 28f3728 commit 1492497
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
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

0 comments on commit 1492497

Please sign in to comment.