@@ -43,7 +43,7 @@ private struct SocketChannelLifecycleManager {
43
43
44
44
private var currentState : State = . fresh {
45
45
didSet {
46
- assert ( self . eventLoop. inEventLoop )
46
+ self . eventLoop. assertInEventLoop ( )
47
47
switch ( oldValue, self . currentState) {
48
48
case ( _, . activated) :
49
49
self . isActiveAtomic. store ( true )
@@ -90,7 +90,7 @@ private struct SocketChannelLifecycleManager {
90
90
// MARK: private API
91
91
@inline ( __always) // we need to return a closure here and to not suffer from a potential allocation for that this must be inlined
92
92
private mutating func moveState( event: Event , promise: EventLoopPromise < Void > ? ) -> ( ( ChannelPipeline ) -> Void ) {
93
- assert ( self . eventLoop. inEventLoop )
93
+ self . eventLoop. assertInEventLoop ( )
94
94
95
95
switch ( self . currentState, event) {
96
96
// origin: .fresh
@@ -158,12 +158,12 @@ private struct SocketChannelLifecycleManager {
158
158
159
159
// MARK: convenience properties
160
160
internal var isActive : Bool {
161
- assert ( self . eventLoop. inEventLoop )
161
+ self . eventLoop. assertInEventLoop ( )
162
162
return self . currentState == . activated
163
163
}
164
164
165
165
internal var isPreRegistered : Bool {
166
- assert ( self . eventLoop. inEventLoop )
166
+ self . eventLoop. assertInEventLoop ( )
167
167
switch self . currentState {
168
168
case . fresh, . closed:
169
169
return false
@@ -173,7 +173,7 @@ private struct SocketChannelLifecycleManager {
173
173
}
174
174
175
175
internal var isRegisteredFully : Bool {
176
- assert ( self . eventLoop. inEventLoop )
176
+ self . eventLoop. assertInEventLoop ( )
177
177
switch self . currentState {
178
178
case . fresh, . closed, . preRegistered:
179
179
return false
@@ -185,7 +185,7 @@ private struct SocketChannelLifecycleManager {
185
185
/// Returns whether the underlying file descriptor is open. This property will always be true (even before registration)
186
186
/// until the Channel is closed.
187
187
internal var isOpen : Bool {
188
- assert ( self . eventLoop. inEventLoop )
188
+ self . eventLoop. assertInEventLoop ( )
189
189
return self . currentState != . closed
190
190
}
191
191
}
@@ -229,13 +229,13 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
229
229
private var autoRead : Bool = true
230
230
private var lifecycleManager : SocketChannelLifecycleManager {
231
231
didSet {
232
- assert ( self . eventLoop. inEventLoop )
232
+ self . eventLoop. assertInEventLoop ( )
233
233
}
234
234
}
235
235
236
236
private var bufferAllocator : ByteBufferAllocator = ByteBufferAllocator ( ) {
237
237
didSet {
238
- assert ( self . eventLoop. inEventLoop )
238
+ self . eventLoop. assertInEventLoop ( )
239
239
self . bufferAllocatorCached. store ( Box ( self . bufferAllocator) )
240
240
}
241
241
}
@@ -287,12 +287,12 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
287
287
288
288
/// `false` if the whole `Channel` is closed and so no more IO operation can be done.
289
289
var isOpen : Bool {
290
- assert ( eventLoop. inEventLoop )
290
+ self . eventLoop. assertInEventLoop ( )
291
291
return self . lifecycleManager. isOpen
292
292
}
293
293
294
294
var isRegistered : Bool {
295
- assert ( self . eventLoop. inEventLoop )
295
+ self . eventLoop. assertInEventLoop ( )
296
296
return self . lifecycleManager. isPreRegistered
297
297
}
298
298
@@ -401,15 +401,15 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
401
401
}
402
402
403
403
public final func localAddress0( ) throws -> SocketAddress {
404
- assert ( self . eventLoop. inEventLoop )
404
+ self . eventLoop. assertInEventLoop ( )
405
405
guard self . isOpen else {
406
406
throw ChannelError . ioOnClosedChannel
407
407
}
408
408
return try self . socket. localAddress ( )
409
409
}
410
410
411
411
public final func remoteAddress0( ) throws -> SocketAddress {
412
- assert ( self . eventLoop. inEventLoop )
412
+ self . eventLoop. assertInEventLoop ( )
413
413
guard self . isOpen else {
414
414
throw ChannelError . ioOnClosedChannel
415
415
}
@@ -420,7 +420,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
420
420
///
421
421
/// - returns: If this socket should be registered for write notifications. Ie. `IONotificationState.register` if _not_ all data could be written, so notifications are necessary; and `IONotificationState.unregister` if everything was written and we don't need to be notified about writability at the moment.
422
422
func flushNow( ) -> IONotificationState {
423
- assert ( self . eventLoop. inEventLoop )
423
+ self . eventLoop. assertInEventLoop ( )
424
424
// Guard against re-entry as data that will be put into `pendingWrites` will just be picked up by
425
425
// `writeToSocket`.
426
426
guard !self . inFlushNow && self . isOpen else {
@@ -475,7 +475,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
475
475
}
476
476
477
477
func setOption0< T: ChannelOption > ( option: T , value: T . OptionType ) throws {
478
- assert ( eventLoop. inEventLoop )
478
+ self . eventLoop. assertInEventLoop ( )
479
479
480
480
guard isOpen else {
481
481
throw ChannelError . ioOnClosedChannel
@@ -523,7 +523,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
523
523
}
524
524
525
525
func getOption0< T: ChannelOption > ( option: T ) throws -> T . OptionType {
526
- assert ( eventLoop. inEventLoop )
526
+ self . eventLoop. assertInEventLoop ( )
527
527
528
528
guard isOpen else {
529
529
throw ChannelError . ioOnClosedChannel
@@ -550,7 +550,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
550
550
///
551
551
/// - returns: `true` if `readPending` is `true`, `false` otherwise.
552
552
@discardableResult func readIfNeeded0( ) -> Bool {
553
- assert ( eventLoop. inEventLoop )
553
+ self . eventLoop. assertInEventLoop ( )
554
554
if !self . lifecycleManager. isActive {
555
555
return false
556
556
}
@@ -563,7 +563,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
563
563
564
564
// Methods invoked from the HeadHandler of the ChannelPipeline
565
565
public func bind0( to address: SocketAddress , promise: EventLoopPromise < Void > ? ) {
566
- assert ( eventLoop. inEventLoop )
566
+ self . eventLoop. assertInEventLoop ( )
567
567
568
568
guard self . isOpen else {
569
569
promise? . fail ( error: ChannelError . ioOnClosedChannel)
@@ -581,7 +581,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
581
581
}
582
582
583
583
public final func write0( _ data: NIOAny , promise: EventLoopPromise < Void > ? ) {
584
- assert ( eventLoop. inEventLoop )
584
+ self . eventLoop. assertInEventLoop ( )
585
585
586
586
guard self . isOpen else {
587
587
// Channel was already closed, fail the promise and not even queue it.
@@ -598,7 +598,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
598
598
}
599
599
600
600
private func registerForWritable( ) {
601
- assert ( eventLoop. inEventLoop )
601
+ self . eventLoop. assertInEventLoop ( )
602
602
603
603
guard !self . interestedEvent. contains ( . write) else {
604
604
// nothing to do if we were previously interested in write
@@ -608,7 +608,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
608
608
}
609
609
610
610
func unregisterForWritable( ) {
611
- assert ( eventLoop. inEventLoop )
611
+ self . eventLoop. assertInEventLoop ( )
612
612
613
613
guard self . interestedEvent. contains ( . write) else {
614
614
// nothing to do if we were not previously interested in write
@@ -618,7 +618,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
618
618
}
619
619
620
620
public final func flush0( ) {
621
- assert ( eventLoop. inEventLoop )
621
+ self . eventLoop. assertInEventLoop ( )
622
622
623
623
guard self . isOpen else {
624
624
return
@@ -637,7 +637,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
637
637
}
638
638
639
639
public func read0( ) {
640
- assert ( eventLoop. inEventLoop )
640
+ self . eventLoop. assertInEventLoop ( )
641
641
642
642
guard self . isOpen else {
643
643
return
@@ -650,15 +650,15 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
650
650
}
651
651
652
652
private final func pauseRead0( ) {
653
- assert ( eventLoop. inEventLoop )
653
+ self . eventLoop. assertInEventLoop ( )
654
654
655
655
if self . lifecycleManager. isPreRegistered {
656
656
unregisterForReadable ( )
657
657
}
658
658
}
659
659
660
660
private final func registerForReadable( ) {
661
- assert ( eventLoop. inEventLoop )
661
+ self . eventLoop. assertInEventLoop ( )
662
662
assert ( self . lifecycleManager. isRegisteredFully)
663
663
664
664
guard !self . lifecycleManager. hasSeenEOFNotification else {
@@ -674,7 +674,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
674
674
}
675
675
676
676
internal final func unregisterForReadable( ) {
677
- assert ( eventLoop. inEventLoop )
677
+ self . eventLoop. assertInEventLoop ( )
678
678
assert ( self . lifecycleManager. isRegisteredFully)
679
679
680
680
guard self . interestedEvent. contains ( . read) else {
@@ -693,7 +693,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
693
693
/// - mode: The close mode, must be `.all` for `BaseSocketChannel`
694
694
/// - promise: The promise that gets notified about the result of the deregistration/close operations.
695
695
public func close0( error: Error , mode: CloseMode , promise: EventLoopPromise < Void > ? ) {
696
- assert ( eventLoop. inEventLoop )
696
+ self . eventLoop. assertInEventLoop ( )
697
697
698
698
guard self . isOpen else {
699
699
promise? . fail ( error: ChannelError . alreadyClosed)
@@ -765,7 +765,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
765
765
766
766
767
767
public final func register0( promise: EventLoopPromise < Void > ? ) {
768
- assert ( eventLoop. inEventLoop )
768
+ self . eventLoop. assertInEventLoop ( )
769
769
770
770
guard self . isOpen else {
771
771
promise? . fail ( error: ChannelError . ioOnClosedChannel)
@@ -792,7 +792,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
792
792
}
793
793
794
794
public final func registerAlreadyConfigured0( promise: EventLoopPromise < Void > ? ) {
795
- assert ( self . eventLoop. inEventLoop )
795
+ self . eventLoop. assertInEventLoop ( )
796
796
assert ( self . isOpen)
797
797
assert ( !self . lifecycleManager. isActive)
798
798
let registerPromise : EventLoopPromise < Void > = self . eventLoop. newPromise ( )
@@ -821,7 +821,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
821
821
822
822
// Methods invoked from the EventLoop itself
823
823
public final func writable( ) {
824
- assert ( self . eventLoop. inEventLoop )
824
+ self . eventLoop. assertInEventLoop ( )
825
825
assert ( self . isOpen)
826
826
827
827
self . finishConnect ( ) // If we were connecting, that has finished.
@@ -832,7 +832,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
832
832
}
833
833
834
834
private func finishConnect( ) {
835
- assert ( eventLoop. inEventLoop )
835
+ self . eventLoop. assertInEventLoop ( )
836
836
assert ( self . lifecycleManager. isPreRegistered)
837
837
838
838
if let connectPromise = self . pendingConnect {
@@ -857,7 +857,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
857
857
}
858
858
859
859
private func finishWritable( ) {
860
- assert ( eventLoop. inEventLoop )
860
+ self . eventLoop. assertInEventLoop ( )
861
861
862
862
if self . isOpen {
863
863
assert ( self . lifecycleManager. isPreRegistered)
@@ -950,7 +950,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
950
950
951
951
@discardableResult
952
952
private final func readable0( ) -> ReadStreamState {
953
- assert ( eventLoop. inEventLoop )
953
+ self . eventLoop. assertInEventLoop ( )
954
954
assert ( self . lifecycleManager. isActive)
955
955
956
956
defer {
@@ -1016,7 +1016,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
1016
1016
}
1017
1017
1018
1018
internal final func updateCachedAddressesFromSocket( updateLocal: Bool = true , updateRemote: Bool = true ) {
1019
- assert ( self . eventLoop. inEventLoop )
1019
+ self . eventLoop. assertInEventLoop ( )
1020
1020
assert ( updateLocal || updateRemote)
1021
1021
let cached = addressesCached. load ( ) . value
1022
1022
let local = updateLocal ? try ? self . localAddress0 ( ) : cached. local
@@ -1025,12 +1025,12 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
1025
1025
}
1026
1026
1027
1027
internal final func unsetCachedAddressesFromSocket( ) {
1028
- assert ( self . eventLoop. inEventLoop )
1028
+ self . eventLoop. assertInEventLoop ( )
1029
1029
self . addressesCached. store ( Box ( ( local: nil , remote: nil ) ) )
1030
1030
}
1031
1031
1032
1032
public final func connect0( to address: SocketAddress , promise: EventLoopPromise < Void > ? ) {
1033
- assert ( eventLoop. inEventLoop )
1033
+ self . eventLoop. assertInEventLoop ( )
1034
1034
1035
1035
guard self . isOpen else {
1036
1036
promise? . fail ( error: ChannelError . ioOnClosedChannel)
@@ -1087,7 +1087,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
1087
1087
}
1088
1088
1089
1089
private final func safeReregister( interested: SelectorEventSet ) {
1090
- assert ( eventLoop. inEventLoop )
1090
+ self . eventLoop. assertInEventLoop ( )
1091
1091
assert ( self . lifecycleManager. isRegisteredFully)
1092
1092
1093
1093
guard self . isOpen else {
@@ -1108,7 +1108,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
1108
1108
}
1109
1109
1110
1110
private func safeRegister( interested: SelectorEventSet ) throws {
1111
- assert ( eventLoop. inEventLoop )
1111
+ self . eventLoop. assertInEventLoop ( )
1112
1112
assert ( !self . lifecycleManager. isRegisteredFully)
1113
1113
1114
1114
guard self . isOpen else {
@@ -1126,7 +1126,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
1126
1126
}
1127
1127
1128
1128
final func becomeFullyRegistered0( ) throws {
1129
- assert ( self . eventLoop. inEventLoop )
1129
+ self . eventLoop. assertInEventLoop ( )
1130
1130
assert ( self . lifecycleManager. isPreRegistered)
1131
1131
assert ( !self . lifecycleManager. isRegisteredFully)
1132
1132
@@ -1136,7 +1136,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
1136
1136
}
1137
1137
1138
1138
final func becomeActive0( promise: EventLoopPromise < Void > ? ) {
1139
- assert ( self . eventLoop. inEventLoop )
1139
+ self . eventLoop. assertInEventLoop ( )
1140
1140
assert ( self . lifecycleManager. isPreRegistered)
1141
1141
if !self . lifecycleManager. isRegisteredFully {
1142
1142
do {
0 commit comments