|
2 | 2 | //
|
3 | 3 | // This source file is part of the SwiftNIO open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors |
| 5 | +// Copyright (c) 2017-2021 Apple Inc. and the SwiftNIO project authors |
6 | 6 | // Licensed under Apache License v2.0
|
7 | 7 | //
|
8 | 8 | // See LICENSE.txt for license information
|
|
11 | 11 | // SPDX-License-Identifier: Apache-2.0
|
12 | 12 | //
|
13 | 13 | //===----------------------------------------------------------------------===//
|
| 14 | +#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) |
| 15 | +import Darwin |
| 16 | +#elseif os(Linux) || os(Android) |
| 17 | +import Glibc |
| 18 | +#endif |
14 | 19 |
|
15 | 20 | /// This protocol defines an object, most commonly a `Channel`, that supports
|
16 | 21 | /// setting and getting socket options (via `setsockopt`/`getsockopt` or similar).
|
@@ -276,54 +281,3 @@ extension SocketOptionProvider {
|
276 | 281 | }
|
277 | 282 | #endif
|
278 | 283 | }
|
279 |
| - |
280 |
| - |
281 |
| -extension BaseSocketChannel: SocketOptionProvider { |
282 |
| - #if !os(Windows) |
283 |
| - func unsafeSetSocketOption<Value>(level: SocketOptionLevel, name: SocketOptionName, value: Value) -> EventLoopFuture<Void> { |
284 |
| - return unsafeSetSocketOption(level: NIOBSDSocket.OptionLevel(rawValue: CInt(level)), name: NIOBSDSocket.Option(rawValue: CInt(name)), value: value) |
285 |
| - } |
286 |
| - #endif |
287 |
| - |
288 |
| - func unsafeSetSocketOption<Value>(level: NIOBSDSocket.OptionLevel, name: NIOBSDSocket.Option, value: Value) -> EventLoopFuture<Void> { |
289 |
| - if eventLoop.inEventLoop { |
290 |
| - let promise = eventLoop.makePromise(of: Void.self) |
291 |
| - executeAndComplete(promise) { |
292 |
| - try setSocketOption0(level: level, name: name, value: value) |
293 |
| - } |
294 |
| - return promise.futureResult |
295 |
| - } else { |
296 |
| - return eventLoop.submit { |
297 |
| - try self.setSocketOption0(level: level, name: name, value: value) |
298 |
| - } |
299 |
| - } |
300 |
| - } |
301 |
| - |
302 |
| - #if !os(Windows) |
303 |
| - func unsafeGetSocketOption<Value>(level: SocketOptionLevel, name: SocketOptionName) -> EventLoopFuture<Value> { |
304 |
| - return unsafeGetSocketOption(level: NIOBSDSocket.OptionLevel(rawValue: CInt(level)), name: NIOBSDSocket.Option(rawValue: CInt(name))) |
305 |
| - } |
306 |
| - #endif |
307 |
| - |
308 |
| - func unsafeGetSocketOption<Value>(level: NIOBSDSocket.OptionLevel, name: NIOBSDSocket.Option) -> EventLoopFuture<Value> { |
309 |
| - if eventLoop.inEventLoop { |
310 |
| - let promise = eventLoop.makePromise(of: Value.self) |
311 |
| - executeAndComplete(promise) { |
312 |
| - try getSocketOption0(level: level, name: name) |
313 |
| - } |
314 |
| - return promise.futureResult |
315 |
| - } else { |
316 |
| - return eventLoop.submit { |
317 |
| - try self.getSocketOption0(level: level, name: name) |
318 |
| - } |
319 |
| - } |
320 |
| - } |
321 |
| - |
322 |
| - func setSocketOption0<Value>(level: NIOBSDSocket.OptionLevel, name: NIOBSDSocket.Option, value: Value) throws { |
323 |
| - try self.socket.setOption(level: level, name: name, value: value) |
324 |
| - } |
325 |
| - |
326 |
| - func getSocketOption0<Value>(level: NIOBSDSocket.OptionLevel, name: NIOBSDSocket.Option) throws -> Value { |
327 |
| - return try self.socket.getOption(level: level, name: name) |
328 |
| - } |
329 |
| -} |
0 commit comments