Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ae3cf1d

Browse files
committedAug 11, 2023
Fix more warnings
1 parent a1c5228 commit ae3cf1d

23 files changed

+305
-212
lines changed
 

‎Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ let package = Package(
4848
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
4949
.product(name: "Logging", package: "swift-log"),
5050
.product(name: "Atomics", package: "swift-atomics"),
51-
],
52-
swiftSettings: [.unsafeFlags(["-Xfrontend", "-strict-concurrency=complete"])]
51+
]
52+
, swiftSettings: [.unsafeFlags(["-Xfrontend", "-strict-concurrency=complete"])]
5353
),
5454
.testTarget(
5555
name: "AsyncHTTPClientTests",

‎Sources/AsyncHTTPClient/ConnectionPool/ChannelHandler/HTTP1ProxyConnectHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ final class HTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableChannelHand
4040
private let proxyAuthorization: HTTPClient.Authorization?
4141
private let deadline: NIODeadline
4242

43-
private var proxyEstablishedPromise: EventLoopPromise<Void>?
44-
var proxyEstablishedFuture: EventLoopFuture<Void>? {
43+
private var proxyEstablishedPromise: CurrentEventLoopPromise<Void>?
44+
var proxyEstablishedFuture: CurrentEventLoopFuture<Void>? {
4545
return self.proxyEstablishedPromise?.futureResult
4646
}
4747

@@ -81,7 +81,7 @@ final class HTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableChannelHand
8181
}
8282

8383
func handlerAdded(context: ChannelHandlerContext) {
84-
self.proxyEstablishedPromise = context.eventLoop.makePromise(of: Void.self)
84+
self.proxyEstablishedPromise = context.currentEventLoop.makePromise(of: Void.self)
8585

8686
self.sendConnect(context: context)
8787
}

‎Sources/AsyncHTTPClient/ConnectionPool/ChannelHandler/SOCKSEventsHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ final class SOCKSEventsHandler: ChannelInboundHandler, RemovableChannelHandler {
2929
case failed(Error)
3030
}
3131

32-
private var socksEstablishedPromise: EventLoopPromise<Void>?
33-
var socksEstablishedFuture: EventLoopFuture<Void>? {
32+
private var socksEstablishedPromise: CurrentEventLoopPromise<Void>?
33+
var socksEstablishedFuture: CurrentEventLoopFuture<Void>? {
3434
return self.socksEstablishedPromise?.futureResult
3535
}
3636

@@ -42,7 +42,7 @@ final class SOCKSEventsHandler: ChannelInboundHandler, RemovableChannelHandler {
4242
}
4343

4444
func handlerAdded(context: ChannelHandlerContext) {
45-
self.socksEstablishedPromise = context.eventLoop.makePromise(of: Void.self)
45+
self.socksEstablishedPromise = context.currentEventLoop.makePromise(of: Void.self)
4646

4747
if context.channel.isActive {
4848
self.connectionStarted(context: context)

‎Sources/AsyncHTTPClient/ConnectionPool/ChannelHandler/TLSEventsHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ final class TLSEventsHandler: ChannelInboundHandler, RemovableChannelHandler {
2929
case failed(Error)
3030
}
3131

32-
private var tlsEstablishedPromise: EventLoopPromise<String?>?
33-
var tlsEstablishedFuture: EventLoopFuture<String?>? {
32+
private var tlsEstablishedPromise: CurrentEventLoopPromise<String?>?
33+
var tlsEstablishedFuture: CurrentEventLoopFuture<String?>? {
3434
return self.tlsEstablishedPromise?.futureResult
3535
}
3636

@@ -42,7 +42,7 @@ final class TLSEventsHandler: ChannelInboundHandler, RemovableChannelHandler {
4242
}
4343

4444
func handlerAdded(context: ChannelHandlerContext) {
45-
self.tlsEstablishedPromise = context.eventLoop.makePromise(of: String?.self)
45+
self.tlsEstablishedPromise = context.currentEventLoop.makePromise(of: String?.self)
4646

4747
if context.channel.isActive {
4848
self.connectionStarted(context: context)

‎Sources/AsyncHTTPClient/ConnectionPool/HTTP1/HTTP1ClientChannelHandler.swift

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler {
150150
self.request = req
151151

152152
self.logger.debug("Request was scheduled on connection")
153-
req.willExecuteRequest(self)
153+
req.willExecuteRequest(HTTP1ClientChannelHandler.Executor(self))
154154

155155
let action = self.state.runNewRequest(
156156
head: req.requestHead,
@@ -436,43 +436,53 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler {
436436
@available(*, unavailable)
437437
extension HTTP1ClientChannelHandler: Sendable {}
438438

439-
extension HTTP1ClientChannelHandler: HTTPRequestExecutor {
440-
func writeRequestBodyPart(_ data: IOData, request: HTTPExecutableRequest, promise: EventLoopPromise<Void>?) {
441-
if self.eventLoop.wrapped.inEventLoop {
442-
self.writeRequestBodyPart0(data, request: request, promise: promise)
443-
} else {
444-
self.eventLoop.execute {
445-
self.writeRequestBodyPart0(data, request: request, promise: promise)
439+
extension HTTP1ClientChannelHandler {
440+
struct Executor: HTTPRequestExecutor, @unchecked Sendable {
441+
private let handler: HTTP1ClientChannelHandler
442+
private let eventLoop: EventLoop
443+
444+
init(_ handler: HTTP1ClientChannelHandler) {
445+
self.eventLoop = handler.eventLoop.wrapped
446+
self.handler = handler
447+
}
448+
449+
func writeRequestBodyPart(_ data: IOData, request: HTTPExecutableRequest, promise: EventLoopPromise<Void>?) {
450+
if self.eventLoop.inEventLoop {
451+
self.handler.writeRequestBodyPart0(data, request: request, promise: promise)
452+
} else {
453+
self.eventLoop.execute {
454+
self.handler.writeRequestBodyPart0(data, request: request, promise: promise)
455+
}
446456
}
447457
}
448-
}
449-
450-
func finishRequestBodyStream(_ request: HTTPExecutableRequest, promise: EventLoopPromise<Void>?) {
451-
if self.eventLoop.wrapped.inEventLoop {
452-
self.finishRequestBodyStream0(request, promise: promise)
453-
} else {
454-
self.eventLoop.execute {
455-
self.finishRequestBodyStream0(request, promise: promise)
458+
459+
func finishRequestBodyStream(_ request: HTTPExecutableRequest, promise: EventLoopPromise<Void>?) {
460+
if self.eventLoop.inEventLoop {
461+
self.handler.finishRequestBodyStream0(request, promise: promise)
462+
} else {
463+
self.eventLoop.execute {
464+
self.handler.finishRequestBodyStream0(request, promise: promise)
465+
}
456466
}
457467
}
458-
}
459-
460-
func demandResponseBodyStream(_ request: HTTPExecutableRequest) {
461-
if self.eventLoop.wrapped.inEventLoop {
462-
self.demandResponseBodyStream0(request)
463-
} else {
464-
self.eventLoop.execute {
465-
self.demandResponseBodyStream0(request)
468+
469+
func demandResponseBodyStream(_ request: HTTPExecutableRequest) {
470+
if self.eventLoop.inEventLoop {
471+
self.handler.demandResponseBodyStream0(request)
472+
} else {
473+
self.eventLoop.execute {
474+
self.handler.demandResponseBodyStream0(request)
475+
}
466476
}
467477
}
468-
}
469-
470-
func cancelRequest(_ request: HTTPExecutableRequest) {
471-
if self.eventLoop.wrapped.inEventLoop {
472-
self.cancelRequest0(request)
473-
} else {
474-
self.eventLoop.execute {
475-
self.cancelRequest0(request)
478+
479+
func cancelRequest(_ request: HTTPExecutableRequest) {
480+
if self.eventLoop.inEventLoop {
481+
self.handler.cancelRequest0(request)
482+
} else {
483+
self.eventLoop.execute {
484+
self.handler.cancelRequest0(request)
485+
}
476486
}
477487
}
478488
}

‎Sources/AsyncHTTPClient/ConnectionPool/HTTP1/HTTP1Connection.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ final class HTTP1Connection {
6969
if self.channel.eventLoop.inEventLoop {
7070
self.execute0(request: request)
7171
} else {
72+
let sendableSelf = UnsafeTransfer(self)
7273
self.channel.eventLoop.execute {
73-
self.execute0(request: request)
74+
sendableSelf.wrappedValue.execute0(request: request)
7475
}
7576
}
7677
}

‎Sources/AsyncHTTPClient/ConnectionPool/HTTP2/HTTP2ClientRequestHandler.swift

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ final class HTTP2ClientRequestHandler: ChannelDuplexHandler {
110110
// a single request.
111111
self.request = request
112112

113-
request.willExecuteRequest(self)
113+
request.willExecuteRequest(HTTP2ClientRequestHandler.Executor(self))
114114

115115
let action = self.state.startRequest(
116116
head: request.requestHead,
@@ -343,43 +343,53 @@ final class HTTP2ClientRequestHandler: ChannelDuplexHandler {
343343
}
344344
}
345345

346-
extension HTTP2ClientRequestHandler: HTTPRequestExecutor {
347-
func writeRequestBodyPart(_ data: IOData, request: HTTPExecutableRequest, promise: EventLoopPromise<Void>?) {
348-
if self.eventLoop.wrapped.inEventLoop {
349-
self.writeRequestBodyPart0(data, request: request, promise: promise)
350-
} else {
351-
self.eventLoop.execute {
352-
self.writeRequestBodyPart0(data, request: request, promise: promise)
346+
extension HTTP2ClientRequestHandler {
347+
struct Executor: HTTPRequestExecutor, @unchecked Sendable {
348+
private var handler: HTTP2ClientRequestHandler
349+
private var eventLoop: EventLoop
350+
351+
init(_ handler: HTTP2ClientRequestHandler) {
352+
self.handler = handler
353+
self.eventLoop = handler.eventLoop.wrapped
354+
}
355+
356+
func writeRequestBodyPart(_ data: IOData, request: HTTPExecutableRequest, promise: EventLoopPromise<Void>?) {
357+
if self.eventLoop.inEventLoop {
358+
self.handler.writeRequestBodyPart0(data, request: request, promise: promise)
359+
} else {
360+
self.eventLoop.execute {
361+
self.handler.writeRequestBodyPart0(data, request: request, promise: promise)
362+
}
353363
}
354364
}
355-
}
356-
357-
func finishRequestBodyStream(_ request: HTTPExecutableRequest, promise: EventLoopPromise<Void>?) {
358-
if self.eventLoop.wrapped.inEventLoop {
359-
self.finishRequestBodyStream0(request, promise: promise)
360-
} else {
361-
self.eventLoop.execute {
362-
self.finishRequestBodyStream0(request, promise: promise)
365+
366+
func finishRequestBodyStream(_ request: HTTPExecutableRequest, promise: EventLoopPromise<Void>?) {
367+
if self.eventLoop.inEventLoop {
368+
self.handler.finishRequestBodyStream0(request, promise: promise)
369+
} else {
370+
self.eventLoop.execute {
371+
self.handler.finishRequestBodyStream0(request, promise: promise)
372+
}
363373
}
364374
}
365-
}
366-
367-
func demandResponseBodyStream(_ request: HTTPExecutableRequest) {
368-
if self.eventLoop.wrapped.inEventLoop {
369-
self.demandResponseBodyStream0(request)
370-
} else {
371-
self.eventLoop.execute {
372-
self.demandResponseBodyStream0(request)
375+
376+
func demandResponseBodyStream(_ request: HTTPExecutableRequest) {
377+
if self.eventLoop.inEventLoop {
378+
self.handler.demandResponseBodyStream0(request)
379+
} else {
380+
self.eventLoop.execute {
381+
self.handler.demandResponseBodyStream0(request)
382+
}
373383
}
374384
}
375-
}
376-
377-
func cancelRequest(_ request: HTTPExecutableRequest) {
378-
if self.eventLoop.wrapped.inEventLoop {
379-
self.cancelRequest0(request)
380-
} else {
381-
self.eventLoop.execute {
382-
self.cancelRequest0(request)
385+
386+
func cancelRequest(_ request: HTTPExecutableRequest) {
387+
if self.eventLoop.inEventLoop {
388+
self.handler.cancelRequest0(request)
389+
} else {
390+
self.eventLoop.execute {
391+
self.handler.cancelRequest0(request)
392+
}
383393
}
384394
}
385395
}

‎Sources/AsyncHTTPClient/ConnectionPool/HTTP2/HTTP2Connection.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ final class HTTP2Connection {
141141
if self.channel.eventLoop.inEventLoop {
142142
self.executeRequest0(request)
143143
} else {
144+
let sendableSelf = UnsafeTransfer(self)
144145
self.channel.eventLoop.execute {
145-
self.executeRequest0(request)
146+
sendableSelf.wrappedValue.executeRequest0(request)
146147
}
147148
}
148149
}
@@ -153,8 +154,9 @@ final class HTTP2Connection {
153154
if self.channel.eventLoop.inEventLoop {
154155
self.shutdown0()
155156
} else {
157+
let sendableSelf = UnsafeTransfer(self)
156158
self.channel.eventLoop.execute {
157-
self.shutdown0()
159+
sendableSelf.wrappedValue.shutdown0()
158160
}
159161
}
160162
}

0 commit comments

Comments
 (0)
Please sign in to comment.