Skip to content

Commit 86f5051

Browse files
Fix compiler errors in socket types when building with glibc (#421)
* on glibc, swift expects that the msg_controllen is type Int * on glibc, socket shutdown options should be an Int32 Signed-off-by: Kathryn Baldauf <[email protected]>
1 parent 747ea99 commit 86f5051

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Sources/Containerization/UnixSocketRelay.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ extension SocketRelay {
397397
"dstFd": "\(destinationFd)",
398398
])
399399
source.cancel()
400-
if shutdown(destinationFd, SHUT_WR) != 0 {
400+
if shutdown(destinationFd, Int32(SHUT_WR)) != 0 {
401401
log?.warning(
402402
"failed to shut down reads",
403403
metadata: [
@@ -429,7 +429,7 @@ extension SocketRelay {
429429
log?.error("file descriptor copy failed \(error)")
430430
if !source.isCancelled {
431431
source.cancel()
432-
if shutdown(destinationFd, SHUT_RDWR) != 0 {
432+
if shutdown(destinationFd, Int32(SHUT_RDWR)) != 0 {
433433
log?.warning(
434434
"failed to shut down destination after I/O error",
435435
metadata: [

Sources/ContainerizationOS/Socket/Socket.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ extension Socket {
329329

330330
var cmsgBuf = [UInt8](repeating: 0, count: Int(CZ_CMSG_SPACE(Int(MemoryLayout<Int32>.size))))
331331
msg.msg_control = withUnsafeMutablePointer(to: &cmsgBuf[0]) { UnsafeMutableRawPointer($0) }
332+
333+
#if canImport(Glibc)
334+
msg.msg_controllen = size_t(cmsgBuf.count)
335+
#else
332336
msg.msg_controllen = socklen_t(cmsgBuf.count)
337+
#endif
333338

334339
let recvResult = withUnsafeMutablePointer(to: &msg) { msgPtr in
335340
sysRecvmsg(handle.fileDescriptor, msgPtr, 0)

0 commit comments

Comments
 (0)