Skip to content

Commit e08c027

Browse files
committed
Fix EndOfLineComment
1 parent 962b76d commit e08c027

18 files changed

+90
-44
lines changed

IntegrationTests/allocation-counter-tests-framework/template/scaffolding.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func waitForThreadsToQuiesce(shouldReachZero: Bool) {
3636
return
3737
}
3838
count += 1
39-
usleep(shouldReachZero ? 50_000 : 200_000) // allocs/frees happen on multiple threads, allow some cool down time
39+
// allocs/frees happen on multiple threads, allow some cool down time
40+
usleep(shouldReachZero ? 50_000 : 200_000)
4041
let newNumberOfUnfreed = getUnfreed()
4142
if oldNumberOfUnfreed == newNumberOfUnfreed && (!shouldReachZero || newNumberOfUnfreed <= 0) {
4243
// nothing happened in the last 100ms, let's assume everything's

Sources/NIOCore/ByteBuffer-aux.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ extension ByteBuffer {
480480
/// - returns: A `ByteBuffer` sharing storage containing the readable bytes only.
481481
@inlinable
482482
public func slice() -> ByteBuffer {
483-
self.getSlice(at: self.readerIndex, length: self.readableBytes)! // must work, bytes definitely in the buffer// must work, bytes definitely in the buffer
483+
// must work, bytes definitely in the buffer// must work, bytes definitely in the buffer
484+
self.getSlice(at: self.readerIndex, length: self.readableBytes)!
484485
}
485486

486487
/// Slice `length` bytes off this `ByteBuffer` and move the reader index forward by `length`.

Sources/NIOCore/Codec.swift

+10-5
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ extension B2MDBuffer {
332332
} else {
333333
buffer.discardReadBytes()
334334
buffer.writeBuffers(self.buffers)
335-
self.buffers.removeAll(keepingCapacity: self.buffers.capacity < 16) // don't grow too much
335+
// don't grow too much
336+
self.buffers.removeAll(keepingCapacity: self.buffers.capacity < 16)
336337
self.buffers.append(buffer)
337338
}
338339
}
@@ -458,12 +459,15 @@ public final class ByteToMessageHandler<Decoder: ByteToMessageDecoder> {
458459
}
459460
}
460461

461-
internal private(set) var decoder: Decoder? // only `nil` if we're already decoding (ie. we're re-entered)
462+
// only `nil` if we're already decoding (ie. we're re-entered)
463+
internal private(set) var decoder: Decoder?
462464
private let maximumBufferSize: Int?
463-
private var queuedWrites = CircularBuffer<NIOAny>(initialCapacity: 1) // queues writes received whilst we're already decoding (re-entrant write)
465+
// queues writes received whilst we're already decoding (re-entrant write)
466+
private var queuedWrites = CircularBuffer<NIOAny>(initialCapacity: 1)
464467
private var state: State = .active {
465468
willSet {
466-
assert(!self.state.isFinalState, "illegal state on state set: \(self.state)") // we can never leave final states
469+
// we can never leave final states
470+
assert(!self.state.isFinalState, "illegal state on state set: \(self.state)")
467471
}
468472
}
469473
private var removalState: RemovalState = .notAddedToPipeline
@@ -538,7 +542,8 @@ extension ByteToMessageHandler {
538542
var possiblyReclaimBytes = false
539543
var decoder: Decoder? = nil
540544
swap(&decoder, &self.decoder)
541-
assert(decoder != nil) // self.decoder only `nil` if we're being re-entered, but .available means we're not
545+
// self.decoder only `nil` if we're being re-entered, but .available means we're not
546+
assert(decoder != nil)
542547
defer {
543548
swap(&decoder, &self.decoder)
544549
if buffer.readableBytes > 0 && possiblyReclaimBytes {

Sources/NIOCore/EventLoopFuture.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,8 @@ extension EventLoopFuture {
767767

768768
/// Add a callback. If there's already a value, run as much of the chain as we can.
769769
@inlinable
770-
@preconcurrency // TODO: We want to remove @preconcurrency but it results in more allocations in 1000_udpconnections
770+
// TODO: We want to remove @preconcurrency but it results in more allocations in 1000_udpconnections
771+
@preconcurrency
771772
internal func _whenComplete(_ callback: @escaping @Sendable () -> CallbackList) {
772773
self._internalWhenComplete(callback)
773774
}

Sources/NIOPosix/BaseSocket.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ class BaseSocket: BaseSocketProtocol {
247247
do {
248248
try self.ignoreSIGPIPE()
249249
} catch {
250-
self.descriptor = NIOBSDSocket.invalidHandle // We have to unset the fd here, otherwise we'll crash with "leaking open BaseSocket"
250+
// We have to unset the fd here, otherwise we'll crash with "leaking open BaseSocket"
251+
self.descriptor = NIOBSDSocket.invalidHandle
251252
throw error
252253
}
253254
}

Sources/NIOPosix/BaseSocketChannel.swift

+14-7
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,33 @@ private struct SocketChannelLifecycleManager {
7777
self.currentState == .closed
7878
}
7979

80-
@inline(__always) // we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
80+
// we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
81+
@inline(__always)
8182
internal mutating func beginRegistration() -> ((EventLoopPromise<Void>?, ChannelPipeline) -> Void) {
8283
self.moveState(event: .beginRegistration)
8384
}
8485

85-
@inline(__always) // we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
86+
// we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
87+
@inline(__always)
8688
internal mutating func finishRegistration() -> ((EventLoopPromise<Void>?, ChannelPipeline) -> Void) {
8789
self.moveState(event: .finishRegistration)
8890
}
8991

90-
@inline(__always) // we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
92+
// we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
93+
@inline(__always)
9194
internal mutating func close() -> ((EventLoopPromise<Void>?, ChannelPipeline) -> Void) {
9295
self.moveState(event: .close)
9396
}
9497

95-
@inline(__always) // we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
98+
// we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
99+
@inline(__always)
96100
internal mutating func activate() -> ((EventLoopPromise<Void>?, ChannelPipeline) -> Void) {
97101
self.moveState(event: .activate)
98102
}
99103

100104
// MARK: private API
101-
@inline(__always) // we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
105+
// we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
106+
@inline(__always)
102107
private mutating func moveState(event: Event) -> ((EventLoopPromise<Void>?, ChannelPipeline) -> Void) {
103108
self.eventLoop.assertInEventLoop()
104109

@@ -251,8 +256,10 @@ class BaseSocketChannel<SocketType: BaseSocketProtocol>: SelectableChannel, Chan
251256
private var inFlushNow: Bool = false // Guard against re-entrance of flushNow() method.
252257
private var autoRead: Bool = true
253258

254-
// MARK: Variables that are really constants
255-
private var _pipeline: ChannelPipeline! = nil // this is really a constant (set in .init) but needs `self` to be constructed and therefore a `var`. Do not change as this needs to accessed from arbitrary threads
259+
// MARK: Variables that are really constant
260+
// this is really a constant (set in .init) but needs `self` to be constructed and
261+
// therefore a `var`. Do not change as this needs to accessed from arbitrary threads
262+
private var _pipeline: ChannelPipeline! = nil
256263

257264
// MARK: Special variables, please read comments.
258265
// For reads guarded by _either_ `self._offEventLoopLock` or the EL thread

Sources/NIOPosix/LinuxUring.swift

+10-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ extension TimeAmount {
4444
// for the type of event issued (poll/modify/delete).
4545
@usableFromInline struct URingUserData {
4646
@usableFromInline var fileDescriptor: CInt
47-
@usableFromInline var registrationID: UInt16 // SelectorRegistrationID truncated, only have room for bottom 16 bits (could be expanded to 24 if required)
47+
// SelectorRegistrationID truncated, only have room for bottom 16 bits (could be expanded to 24 if required)
48+
@usableFromInline var registrationID: UInt16
4849
@usableFromInline var eventType: CQEEventType
4950
@usableFromInline var padding: Int8 // reserved for future use
5051

@@ -112,7 +113,8 @@ final internal class URing {
112113
internal static let POLLERR: CUnsignedInt = numericCast(CNIOLinux.POLLERR)
113114
internal static let POLLRDHUP: CUnsignedInt = CNIOLinux_POLLRDHUP() // numericCast(CNIOLinux.POLLRDHUP)
114115
internal static let POLLHUP: CUnsignedInt = numericCast(CNIOLinux.POLLHUP)
115-
internal static let POLLCANCEL: CUnsignedInt = 0xF000_0000 // Poll cancelled, need to reregister for singleshot polls
116+
// Poll cancelled, need to reregister for singleshot polls
117+
internal static let POLLCANCEL: CUnsignedInt = 0xF000_0000
116118

117119
private var ring = io_uring()
118120
private let ringEntries: CUnsignedInt = 8192
@@ -276,10 +278,12 @@ final internal class URing {
276278

277279
self.withSQE { sqe in
278280
CNIOLinux.io_uring_prep_poll_add(sqe, fileDescriptor, pollMask)
279-
CNIOLinux.io_uring_sqe_set_data(sqe, bitpatternAsPointer) // must be done after prep_poll_add, otherwise zeroed out.
281+
// must be done after prep_poll_add, otherwise zeroed out.
282+
CNIOLinux.io_uring_sqe_set_data(sqe, bitpatternAsPointer)
280283

281284
if multishot {
282-
sqe!.pointee.len |= IORING_POLL_ADD_MULTI // turn on multishots, set through environment variable
285+
// turn on multishots, set through environment variable
286+
sqe!.pointee.len |= IORING_POLL_ADD_MULTI
283287
}
284288
}
285289

@@ -316,7 +320,8 @@ final internal class URing {
316320

317321
self.withSQE { sqe in
318322
CNIOLinux.io_uring_prep_poll_remove(sqe, .init(userData: bitPattern))
319-
CNIOLinux.io_uring_sqe_set_data(sqe, .init(userData: userbitPattern)) // must be done after prep_poll_add, otherwise zeroed out.
323+
// must be done after prep_poll_add, otherwise zeroed out.
324+
CNIOLinux.io_uring_sqe_set_data(sqe, .init(userData: userbitPattern))
320325

321326
if link {
322327
CNIOLinux_io_uring_set_link_flag(sqe)

Sources/NIOPosix/SelectableEventLoop.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ internal final class SelectableEventLoop: EventLoop {
133133
)
134134
return self._externalStateLock
135135
}
136-
private var internalState: InternalState = .runningAndAcceptingNewRegistrations // protected by the EventLoop thread
137-
private var externalState: ExternalState = .open // protected by externalStateLock
136+
// protected by the EventLoop thread
137+
private var internalState: InternalState = .runningAndAcceptingNewRegistrations
138+
// protected by externalStateLock
139+
private var externalState: ExternalState = .open
138140

139141
let bufferPool: Pool<PooledBuffer>
140142
let msgBufferPool: Pool<PooledMsgBuffer>

Sources/NIOPosix/SelectorKqueue.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ extension KQueueEventFilterSet {
7171
// we only use three filters (EVFILT_READ, EVFILT_WRITE and EVFILT_EXCEPT) so the number of changes would be 3.
7272
var kevents = KeventTriple()
7373

74-
let differences = previousKQueueFilterSet.symmetricDifference(self) // contains all the events that need a change (either need to be added or removed)
74+
// contains all the events that need a change (either need to be added or removed)
75+
let differences = previousKQueueFilterSet.symmetricDifference(self)
7576

7677
func calculateKQueueChange(event: KQueueEventFilterSet) -> UInt16? {
7778
guard differences.contains(event) else {

Sources/NIOPosix/SelectorUring.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ extension Selector: _SelectorBackendProtocol {
349349
// This is only needed due to the edge triggered nature of liburing, possibly
350350
// we can get away with only updating (force triggering an event if available) for
351351
// partial reads (where we currently give up after N iterations)
352-
if multishot && self.shouldRefreshPollForEvent(selectorEvent: selectorEvent) { // can be after guard as it is multishot
352+
353+
// can be after guard as it is multishot
354+
if multishot && self.shouldRefreshPollForEvent(selectorEvent: selectorEvent) {
353355
ring.io_uring_poll_update(
354356
fileDescriptor: event.fd,
355357
newPollmask: registration.interested.uringEventSet,

Sources/NIOPosix/System.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ func sysRecvFrom_wrapper(
9696
src_addr: UnsafeMutablePointer<sockaddr>,
9797
addrlen: UnsafeMutablePointer<socklen_t>
9898
) -> CLong {
99-
recvfrom(sockfd, buf, len, flags, src_addr, addrlen) // src_addr is 'UnsafeMutablePointer', but it need to be 'UnsafePointer'
99+
// src_addr is 'UnsafeMutablePointer', but it need to be 'UnsafePointer'
100+
recvfrom(sockfd, buf, len, flags, src_addr, addrlen)
100101
// src_addr is 'UnsafeMutablePointer', but it need to be 'UnsafePointer'
101102
}
102103
func sysWritev_wrapper(fd: CInt, iov: UnsafePointer<iovec>?, iovcnt: CInt) -> CLong {

Sources/NIOTLS/SNIHandler.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ public final class SNIHandler: ByteToMessageDecoder {
169169
//
170170
// From this point onwards if we don't have enough data to satisfy a read, this is an error and
171171
// we will fall back to let the upper layers handle it.
172-
tempBuffer = tempBuffer.getSlice(at: tempBuffer.readerIndex, length: Int(contentLength))! // length check above
172+
173+
// length check above
174+
tempBuffer = tempBuffer.getSlice(at: tempBuffer.readerIndex, length: Int(contentLength))!
173175

174176
// Now parse the handshake header. If the length of the handshake message is not exactly the
175177
// length of this record, something has gone wrong and we should give up.

Tests/NIOCoreTests/ByteBufferTest.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,8 @@ class ByteBufferTest: XCTestCase {
23452345
XCTAssertNotEqual(buf.capacity, oldCapacity)
23462346
XCTAssertNotEqual(oldPtrVal, newPtrVal)
23472347
}
2348-
bufCopy.writeString("foo") // stops the optimiser removing `bufCopy` which would make `reserveCapacity` use malloc instead of realloc
2348+
// stops the optimiser removing `bufCopy` which would make `reserveCapacity` use malloc instead of realloc
2349+
bufCopy.writeString("foo")
23492350
}
23502351

23512352
func testReserveCapacityWithMinimumWritableBytesWhenNotEnoughWritableBytes() {

Tests/NIOHTTP1Tests/HTTPDecoderTest.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ class HTTPDecoderTest: XCTestCase {
209209
"OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nConnection: upgrade\r\n\r\nXXXX"
210210
)
211211

212+
// allow the event loop to run (removal is not synchronous here)
212213
XCTAssertNoThrow(try channel.writeInbound(buffer))
213-
(channel.eventLoop as! EmbeddedEventLoop).run() // allow the event loop to run (removal is not synchronous here)
214+
(channel.eventLoop as! EmbeddedEventLoop).run()
214215
XCTAssertNoThrow(
215216
try channel.pipeline.assertDoesNotContain(handlerType: ByteToMessageHandler<HTTPRequestDecoder>.self)
216217
)
@@ -267,7 +268,8 @@ class HTTPDecoderTest: XCTestCase {
267268
)
268269
XCTAssertNoThrow(try channel.pipeline.addHandler(Receiver()).wait())
269270

270-
// This connect call is semantically wrong, but it's how you active embedded channels properly right now.
271+
// This connect call is semantically wrong, but it's how you
272+
// active embedded channels properly right now.
271273
XCTAssertNoThrow(try channel.connect(to: SocketAddress(ipAddress: "127.0.0.1", port: 8888)).wait())
272274

273275
var buffer = channel.allocator.buffer(capacity: 64)
@@ -276,7 +278,8 @@ class HTTPDecoderTest: XCTestCase {
276278
)
277279

278280
XCTAssertNoThrow(try channel.writeInbound(buffer))
279-
(channel.eventLoop as! EmbeddedEventLoop).run() // allow the event loop to run (removal is not synchrnous here)
281+
// allow the event loop to run (removal is not synchrnous here)
282+
(channel.eventLoop as! EmbeddedEventLoop).run()
280283
XCTAssertNoThrow(
281284
try channel.pipeline.assertDoesNotContain(handlerType: ByteToMessageHandler<HTTPRequestDecoder>.self)
282285
)
@@ -348,7 +351,8 @@ class HTTPDecoderTest: XCTestCase {
348351
)
349352

350353
XCTAssertNoThrow(try channel.writeInbound(buffer))
351-
(channel.eventLoop as! EmbeddedEventLoop).run() // allow the event loop to run (removal is not synchrnous here)
354+
// allow the event loop to run (removal is not synchronous here)
355+
(channel.eventLoop as! EmbeddedEventLoop).run()
352356
XCTAssertNoThrow(
353357
try channel.pipeline.assertDoesNotContain(handlerType: ByteToMessageHandler<HTTPRequestDecoder>.self)
354358
)

Tests/NIOPosixTests/ChannelPipelineTest.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -1533,20 +1533,24 @@ class ChannelPipelineTest: XCTestCase {
15331533
// And now close
15341534
operations.close(promise: nil)
15351535

1536+
// EmbeddedChannel itself does one, we did the other.
15361537
XCTAssertEqual(eventCounter.bindCalls, 1)
15371538
XCTAssertEqual(eventCounter.channelActiveCalls, 2)
1538-
XCTAssertEqual(eventCounter.channelInactiveCalls, 2) // EmbeddedChannel itself does one, we did the other.
1539+
XCTAssertEqual(eventCounter.channelInactiveCalls, 2)
15391540
XCTAssertEqual(eventCounter.channelReadCalls, 1)
15401541
XCTAssertEqual(eventCounter.channelReadCompleteCalls, 1)
1541-
XCTAssertEqual(eventCounter.channelRegisteredCalls, 3) // EmbeddedChannel itself does one, we did the other two.
1542-
XCTAssertEqual(eventCounter.channelUnregisteredCalls, 2) // EmbeddedChannel itself does one, we did the other.
1542+
// EmbeddedChannel itself does one, we did the other two.
1543+
XCTAssertEqual(eventCounter.channelRegisteredCalls, 3)
1544+
// EmbeddedChannel itself does one, we did the other.
1545+
XCTAssertEqual(eventCounter.channelUnregisteredCalls, 2)
15431546
XCTAssertEqual(eventCounter.channelWritabilityChangedCalls, 1)
15441547
XCTAssertEqual(eventCounter.closeCalls, 1)
15451548
XCTAssertEqual(eventCounter.connectCalls, 1)
15461549
XCTAssertEqual(eventCounter.errorCaughtCalls, 1)
15471550
XCTAssertEqual(eventCounter.flushCalls, 2) // flush, and writeAndFlush
15481551
XCTAssertEqual(eventCounter.readCalls, 1)
1549-
XCTAssertEqual(eventCounter.registerCalls, 2) // EmbeddedChannel itself does one, we did the other.
1552+
// EmbeddedChannel itself does one, we did the other.
1553+
XCTAssertEqual(eventCounter.registerCalls, 2)
15501554
XCTAssertEqual(eventCounter.triggerUserOutboundEventCalls, 1)
15511555
XCTAssertEqual(eventCounter.userInboundEventTriggeredCalls, 1)
15521556
XCTAssertEqual(eventCounter.writeCalls, 2) // write, and writeAndFlush

Tests/NIOPosixTests/CodecTest.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,8 @@ public final class ByteToMessageDecoderTest: XCTestCase {
14081408
}
14091409
XCTAssertNoThrow(XCTAssertNil(try channel.readInbound()))
14101410

1411-
XCTAssertNoThrow(try channel.writeInbound(buffer)) // this will go through because the decoder is already 'done'
1411+
// this will go through because the decoder is already 'done'
1412+
XCTAssertNoThrow(try channel.writeInbound(buffer))
14121413
}
14131414

14141415
func testBasicLifecycle() {

Tests/NIOPosixTests/EventLoopMetricsDelegateTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ final class EventLoopMetricsDelegateTests: XCTestCase {
6363
}
6464
if let lastTickStartTime = delegate.infos.last?.startTime {
6565
let timeSinceStart = lastTickStartTime - testStartTime
66-
XCTAssertLessThan(timeSinceStart.nanoseconds, 100_000_000) // This should be near instant, limiting to 100ms
66+
// This should be near instant, limiting to 100ms
67+
XCTAssertLessThan(timeSinceStart.nanoseconds, 100_000_000)
6768
XCTAssertGreaterThan(timeSinceStart.nanoseconds, 0)
6869
}
6970
}

0 commit comments

Comments
 (0)