Skip to content

Commit b351237

Browse files
committed
add strings and comments to kqueue API
1 parent 1ccba65 commit b351237

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Sources/BSD/Core/KQueue/KQueue.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,22 @@ extension BSD {
7171

7272
/// Flags for a kevent.
7373
public struct KEventFlags: OptionSet, KassHelpers.NamedOptionEnum {
74+
/// The name of the flag, if it can be determined.
7475
public var name: String?
76+
77+
/// The raw value of the flag.
7578
public let rawValue: UInt16
7679

80+
/// Initializes a kevent flag with the given name and raw value.
7781
public init(name: String?, rawValue: UInt16) {
7882
self.name = name
7983
self.rawValue = rawValue
8084
}
8185

86+
/// The individual flags in the collection.
87+
public var flags: [Self] { Self.allCases.filter { self.contains($0) } }
88+
89+
/// All known kevent flags.
8290
public static let allCases: [Self] = [
8391
.add,
8492
.delete,
@@ -153,6 +161,21 @@ extension kevent {
153161
}
154162
}
155163

164+
extension kevent: @retroactive CustomStringConvertible {
165+
public var description: String {
166+
"""
167+
kevent(
168+
ident: \(ident),
169+
filter: \(BSD.KEventFilterType(rawValue: filter)),
170+
flags: \(BSD.KEventFlags(rawValue: flags).flags),
171+
fflags: \(fflags),
172+
data: \(data),
173+
udata: \(String(describing: udata))
174+
)
175+
"""
176+
}
177+
}
178+
156179
extension kevent64_s {
157180
/// Initializes a kevent64_s with the given parameters.
158181
public init(
@@ -176,6 +199,21 @@ extension kevent64_s {
176199
}
177200
}
178201

202+
extension kevent64_s: @retroactive CustomStringConvertible {
203+
public var description: String {
204+
"""
205+
kevent64_s(
206+
ident: \(ident),
207+
filter: \(BSD.KEventFilterType(rawValue: filter)),
208+
flags: \(BSD.KEventFlags(rawValue: flags).flags),
209+
fflags: \(fflags),
210+
data: \(data),
211+
udata: \(String(describing: udata))
212+
)
213+
"""
214+
}
215+
}
216+
179217
extension kevent_qos_s {
180218
/// Initializes a kevent_qos_s with the given parameters.
181219
public init(
@@ -203,6 +241,23 @@ extension kevent_qos_s {
203241
}
204242
}
205243

244+
extension kevent_qos_s: @retroactive CustomStringConvertible {
245+
public var description: String {
246+
"""
247+
kevent_qos_s(
248+
ident: \(ident),
249+
filter: \(BSD.KEventFilterType(rawValue: filter)),
250+
flags: \(BSD.KEventFlags(rawValue: flags).flags),
251+
qos: \(qos),
252+
fflags: \(fflags),
253+
xflags: \(xflags),
254+
data: \(data),
255+
udata: \(String(describing: udata))
256+
)
257+
"""
258+
}
259+
}
260+
206261
extension BSD {
207262

208263
/// A class representing a kqueue.

0 commit comments

Comments
 (0)