Skip to content

Commit

Permalink
add support for musl platform
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnzhou committed Oct 2, 2024
1 parent c308210 commit fc2f843
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Sources/WebSocketKit/WebSocket+SocketOptions.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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
2 changes: 1 addition & 1 deletion Sources/WebSocketKit/WebSocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public final class WebSocketClient: Sendable {
default:
return channel.eventLoop.makeFailedFuture(WebSocketClient.Error.invalidAddress)
}
#elseif canImport(Glibc)
#elseif canImport(Glibc) || canImport(Musl)
return (channel as! SocketOptionProvider).setBindToDevice(device.name)
#endif
} else {
Expand Down

0 comments on commit fc2f843

Please sign in to comment.