Skip to content

Commit a79de6d

Browse files
committed
Getting started.
1 parent b8b1940 commit a79de6d

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

Sources/NIOPosix/PendingWritesManager.swift

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,43 @@ import Atomics
1616
import CNIOLinux
1717
import NIOCore
1818

19+
public struct MetadataEnvelope {
20+
public var data: ByteBuffer
21+
public var controlData: MessageMetadata? = nil
22+
23+
public init(data: ByteBuffer) {
24+
self.data = data
25+
}
26+
27+
public init(data: ByteBuffer, controlData: MessageMetadata?) {
28+
self.data = data
29+
self.controlData = controlData
30+
}
31+
32+
/// Any metadata associated with an
33+
public struct MessageMetadata: Hashable, Sendable {
34+
init() {
35+
var m: msghdr = .init()
36+
// Create buffer for file descriptor
37+
let fake_fd = 6666
38+
let fd_pointer = UnsafeMutableRawPointer(bitPattern: fake_fd)
39+
m.msg_control = fd_pointer
40+
m.msg_controllen = MemoryLayout.size(ofValue: fake_fd)
41+
// TODO other platoforms
42+
let cm: UnsafeMutablePointer<cmsghdr> = CNIOLinux_CMSG_FIRSTHDR(&m)
43+
cm.pointee.cmsg_level = SOL_SOCKET
44+
cm.pointee.cmsg_type = Int32(SCM_RIGHTS)
45+
cm.pointee.cmsg_len = MemoryLayout.size(ofValue: fake_fd)
46+
47+
// TODO send `m`
48+
}
49+
}
50+
}
51+
1952
private struct PendingStreamWrite {
2053
var data: IOData
2154
var promise: Optional<EventLoopPromise<Void>>
55+
var metadata: MetadataEnvelope?
2256
}
2357

2458
/// Write result is `.couldNotWriteEverything` but we have no more writes to perform.
@@ -322,7 +356,7 @@ private struct PendingStreamWritesState {
322356
}
323357
}
324358

325-
/// This class manages the writing of pending writes to stream sockets. The state is held in a `PendingWritesState`
359+
/// This class manages the writing of pending writes to stream sockets. The state is held in a `PendingStreamWritesState`
326360
/// value. The most important purpose of this object is to call `write`, `writev` or `sendfile` depending on the
327361
/// currently pending writes.
328362
final class PendingStreamWritesManager: PendingWritesManager {
@@ -400,6 +434,7 @@ final class PendingStreamWritesManager: PendingWritesManager {
400434
scalarFileWriteOperation: (CInt, Int, Int) throws -> IOResult<Int>
401435
) throws -> OverallWriteResult {
402436
try self.triggerWriteOperations { writeMechanism in
437+
// TODO: add with metadata calls.
403438
switch writeMechanism {
404439
case .scalarBufferWrite:
405440
return try triggerScalarBufferWrite({ try scalarBufferWriteOperation($0) })

0 commit comments

Comments
 (0)