Fix an upcoming compiler warning on implicit raw pointer casts. (#2377)
setOption forms a raw pointer to a generic argument. The compiler will warn on this as of: [proposal] Constrain implicit raw pointer conversion... #1963 https://github.com/apple/swift-evolution/pull/1963 /Sources/NIOPosix/BaseSocket.swift:286:31: warning: forming 'UnsafeRawPointer' to a variable of type 'T'; this is likely incorrect because 'T' may contain an object reference. option_value: &val, ^ Ideally, this would be fixed by adding a BitwiseCopyable constraint to the 'value' parameter of 'BaseSocker.setOption'. That would not only eliminate the warning, but would make the API safer. But BitwiseCopyable isn't quite ready for public use. In the meantime, this is a reasonable workaround. Co-authored-by: Cory Benfield <lukasa@apple.com>
This commit is contained in:
parent
a296f30e45
commit
e63326aa50
|
@ -276,15 +276,15 @@ class BaseSocket: BaseSocketProtocol {
|
||||||
// most socket options settings so for the time being we'll just ignore this. Let's revisit for NIO 2.0.
|
// most socket options settings so for the time being we'll just ignore this. Let's revisit for NIO 2.0.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return try self.withUnsafeHandle {
|
return try withUnsafeBytes(of: value) { (valueBuffer: UnsafeRawBufferPointer) in
|
||||||
var val = value
|
try self.withUnsafeHandle {
|
||||||
|
|
||||||
try NIOBSDSocket.setsockopt(
|
try NIOBSDSocket.setsockopt(
|
||||||
socket: $0,
|
socket: $0,
|
||||||
level: level,
|
level: level,
|
||||||
option_name: name,
|
option_name: name,
|
||||||
option_value: &val,
|
option_value: valueBuffer.baseAddress!,
|
||||||
option_len: socklen_t(MemoryLayout.size(ofValue: val)))
|
option_len: socklen_t(valueBuffer.count))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue