Skip to content

Commit c308210

Browse files
committed
fix bind to device on linux
1 parent 9d1f281 commit c308210

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Sources/WebSocketKit/WebSocket+SocketOptions.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,17 @@ extension NIOBSDSocket.Option {
99
public static let so_bindtodevice = Self(rawValue: SO_BINDTODEVICE)
1010
#endif
1111
}
12+
13+
extension SocketOptionProvider {
14+
#if canImport(Glibc)
15+
/// Sets the socket option SO_BINDTODEVICE to `value`.
16+
///
17+
/// - parameters:
18+
/// - value: The value to set SO_BINDTODEVICE to.
19+
/// - returns: An `EventLoopFuture` that fires when the option has been set,
20+
/// or if an error has occurred.
21+
public func setBindToDevice(_ value: String) -> EventLoopFuture<Void> {
22+
self.unsafeSetSocketOption(level: .socket, name: .so_bindtodevice, value: value)
23+
}
24+
#endif
25+
}

Sources/WebSocketKit/WebSocketClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public final class WebSocketClient: Sendable {
182182
return channel.eventLoop.makeFailedFuture(WebSocketClient.Error.invalidAddress)
183183
}
184184
#elseif canImport(Glibc)
185-
return channel.setOption(.socketOption(.so_bindtodevice), value: device.interfaceIndex)
185+
return (channel as! SocketOptionProvider).setBindToDevice(device.name)
186186
#endif
187187
} else {
188188
return channel.eventLoop.makeSucceededVoidFuture()

0 commit comments

Comments
 (0)