Skip to content

Commit d2a4dcc

Browse files
committed
Formatter
1 parent fd4571d commit d2a4dcc

File tree

5 files changed

+137
-38
lines changed

5 files changed

+137
-38
lines changed

Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ final class HTTPConnectionPool:
105105
enum Unlocked {
106106
case createConnection(Connection.ID, on: EventLoop)
107107
case closeConnection(Connection, isShutdown: StateMachine.ConnectionAction.IsShutdown)
108-
case closeConnectionAndCreateConnection(close: Connection, newConnectionID: Connection.ID, on: EventLoop, isShutdown: StateMachine.ConnectionAction.IsShutdown)
108+
case closeConnectionAndCreateConnection(
109+
close: Connection,
110+
newConnectionID: Connection.ID,
111+
on: EventLoop,
112+
isShutdown: StateMachine.ConnectionAction.IsShutdown
113+
)
109114
case cleanupConnections(CleanupContext, isShutdown: StateMachine.ConnectionAction.IsShutdown)
110115
case migration(
111116
createConnections: [(Connection.ID, EventLoop)],
@@ -192,13 +197,23 @@ final class HTTPConnectionPool:
192197
self.unlocked.connection = .createConnection(newConnectionID, on: eventLoop)
193198
case .cancelTimeoutTimer(let connectionID):
194199
self.locked.connection = .cancelTimeoutTimer(connectionID)
195-
case .createConnectionAndCancelTimeoutTimer(createdID: let createdID, on: let eventLoop, cancelTimerID: let cancelID):
200+
case .createConnectionAndCancelTimeoutTimer(let createdID, on: let eventLoop, cancelTimerID: let cancelID):
196201
self.unlocked.connection = .createConnection(createdID, on: eventLoop)
197202
self.locked.connection = .cancelTimeoutTimer(cancelID)
198203
case .closeConnection(let connection, let isShutdown):
199204
self.unlocked.connection = .closeConnection(connection, isShutdown: isShutdown)
200-
case .closeConnectionAndCreateConnection(let closeConnection, let isShutdown, let newConnectionID, let eventLoop):
201-
self.unlocked.connection = .closeConnectionAndCreateConnection(close: closeConnection, newConnectionID: newConnectionID, on: eventLoop, isShutdown: isShutdown)
205+
case .closeConnectionAndCreateConnection(
206+
let closeConnection,
207+
let isShutdown,
208+
let newConnectionID,
209+
let eventLoop
210+
):
211+
self.unlocked.connection = .closeConnectionAndCreateConnection(
212+
close: closeConnection,
213+
newConnectionID: newConnectionID,
214+
on: eventLoop,
215+
isShutdown: isShutdown
216+
)
202217
case .cleanupConnections(var cleanupContext, let isShutdown):
203218
self.locked.connection = .cancelBackoffTimers(cleanupContext.connectBackoff)
204219
cleanupContext.connectBackoff = []
@@ -296,7 +311,12 @@ final class HTTPConnectionPool:
296311
self.delegate.connectionPoolDidShutdown(self, unclean: unclean)
297312
}
298313

299-
case .closeConnectionAndCreateConnection(let connectionToClose, let newConnectionID, let eventLoop, let isShutdown):
314+
case .closeConnectionAndCreateConnection(
315+
let connectionToClose,
316+
let newConnectionID,
317+
let eventLoop,
318+
let isShutdown
319+
):
300320
self.logger.trace(
301321
"closing and creating connection",
302322
metadata: [

Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP1StateMachine.swift

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ extension HTTPConnectionPool {
149149

150150
private mutating func executeRequestOnPreferredEventLoop(_ request: Request, eventLoop: EventLoop) -> Action {
151151
if let connection = self.connections.leaseConnection(onPreferred: eventLoop) {
152-
// Cool, a connection is available. If using this would put us below our needed extra set, we
152+
// Cool, a connection is available. If using this would put us below our needed extra set, we
153153
// should create another.
154154
let stats = self.connections.generalPurposeStats
155-
let needExtraConnection = stats.nonLeased < (self.requests.count + self.preWarmedConnectionCount) && self.connections.canGrow
155+
let needExtraConnection =
156+
stats.nonLeased < (self.requests.count + self.preWarmedConnectionCount) && self.connections.canGrow
156157
let action: StateMachine.ConnectionAction
157158

158159
if needExtraConnection {
@@ -475,17 +476,25 @@ extension HTTPConnectionPool {
475476
at index: Int,
476477
context: HTTP1Connections.IdleConnectionContext
477478
) -> EstablishedAction {
478-
var requestAction = HTTPConnectionPool.StateMachine.RequestAction.none
479+
var requestAction = HTTPConnectionPool.StateMachine.RequestAction.none
479480
var parkedConnectionDetails: (HTTPConnectionPool.Connection.ID, any EventLoop)? = nil
480481

481482
// 1. Check if there are waiting requests in the general purpose queue
482483
if let request = self.requests.popFirst(for: nil) {
483-
requestAction = .executeRequest(request, self.connections.leaseConnection(at: index), cancelTimeout: true)
484+
requestAction = .executeRequest(
485+
request,
486+
self.connections.leaseConnection(at: index),
487+
cancelTimeout: true
488+
)
484489
}
485490

486491
// 2. Check if there are waiting requests in the matching eventLoop queue
487492
if case .none = requestAction, let request = self.requests.popFirst(for: context.eventLoop) {
488-
requestAction = .executeRequest(request, self.connections.leaseConnection(at: index), cancelTimeout: true)
493+
requestAction = .executeRequest(
494+
request,
495+
self.connections.leaseConnection(at: index),
496+
cancelTimeout: true
497+
)
489498
}
490499

491500
// 3. Create a timeout timer to ensure the connection is closed if it is idle for too
@@ -500,7 +509,9 @@ extension HTTPConnectionPool {
500509
// confirmed that.
501510
let connectionAction: EstablishedConnectionAction
502511

503-
if self.connections.generalPurposeStats.nonLeased < self.preWarmedConnectionCount && self.connections.canGrow {
512+
if self.connections.generalPurposeStats.nonLeased < self.preWarmedConnectionCount
513+
&& self.connections.canGrow
514+
{
504515
// Re-use the event loop of the connection that just got created.
505516
if let parkedConnectionDetails {
506517
let newConnectionID = self.connections.createNewConnection(on: parkedConnectionDetails.1)
@@ -521,7 +532,7 @@ extension HTTPConnectionPool {
521532

522533
return .init(
523534
request: requestAction,
524-
connection: connectionAction
535+
connection: connectionAction
525536
)
526537
}
527538

@@ -616,7 +627,9 @@ extension HTTPConnectionPool {
616627
at index: Int,
617628
context: HTTP1Connections.FailedConnectionContext
618629
) -> Action {
619-
let needConnectionForRequest = context.connectionsStartingForUseCase < (self.requests.generalPurposeCount + self.preWarmedConnectionCount)
630+
let needConnectionForRequest =
631+
context.connectionsStartingForUseCase
632+
< (self.requests.generalPurposeCount + self.preWarmedConnectionCount)
620633
if needConnectionForRequest {
621634
// if we have more requests queued up, than we have starting connections, we should
622635
// create a new connection

Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+StateMachine.swift

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ extension HTTPConnectionPool {
4242

4343
case scheduleTimeoutTimer(Connection.ID, on: EventLoop)
4444
case cancelTimeoutTimer(Connection.ID)
45-
case createConnectionAndCancelTimeoutTimer(createdID: Connection.ID, on: EventLoop, cancelTimerID: Connection.ID)
45+
case createConnectionAndCancelTimeoutTimer(
46+
createdID: Connection.ID,
47+
on: EventLoop,
48+
cancelTimerID: Connection.ID
49+
)
4650
case scheduleTimeoutTimerAndCreateConnection(
4751
timeoutID: Connection.ID,
4852
newConnectionID: Connection.ID,
@@ -466,11 +470,25 @@ extension HTTPConnectionPool.StateMachine.ConnectionAction {
466470
self = .scheduleTimeoutTimer(connectionID, on: eventLoop)
467471
case .closeConnection(let connection, let isShutdown):
468472
self = .closeConnection(connection, isShutdown: isShutdown)
469-
case .closeConnectionAndCreateConnection(let closeConnection, let isShutdown, let newConnectionID, let eventLoop):
470-
self = .closeConnectionAndCreateConnection(closeConnection: closeConnection, isShutdown: isShutdown, newConnectionID: newConnectionID, on: eventLoop)
471-
case .scheduleTimeoutTimerAndCreateConnection(let timeoutID, let newConnectionID, let eventLoop):
472-
self = .scheduleTimeoutTimerAndCreateConnection(timeoutID: timeoutID, newConnectionID: newConnectionID, on: eventLoop)
473-
case .createConnection(connectionID: let connectionID, on: let eventLoop):
473+
case .closeConnectionAndCreateConnection(
474+
let closeConnection,
475+
let isShutdown,
476+
let newConnectionID,
477+
let eventLoop
478+
):
479+
self = .closeConnectionAndCreateConnection(
480+
closeConnection: closeConnection,
481+
isShutdown: isShutdown,
482+
newConnectionID: newConnectionID,
483+
on: eventLoop
484+
)
485+
case .scheduleTimeoutTimerAndCreateConnection(let timeoutID, let newConnectionID, let eventLoop):
486+
self = .scheduleTimeoutTimerAndCreateConnection(
487+
timeoutID: timeoutID,
488+
newConnectionID: newConnectionID,
489+
on: eventLoop
490+
)
491+
case .createConnection(let connectionID, on: let eventLoop):
474492
self = .createConnection(connectionID, on: eventLoop)
475493
}
476494
}
@@ -490,7 +508,12 @@ extension HTTPConnectionPool.StateMachine.ConnectionAction {
490508
closeConnections: migrationAction.closeConnections,
491509
scheduleTimeout: nil
492510
)
493-
case .closeConnectionAndCreateConnection(closeConnection: let connection, isShutdown: let isShutdown, newConnectionID: _, on: _):
511+
case .closeConnectionAndCreateConnection(
512+
closeConnection: let connection,
513+
let isShutdown,
514+
newConnectionID: _,
515+
on: _
516+
):
494517
// This event can only come _from_ the HTTP/1 pool, migrating to HTTP/2. We do not do prewarmed HTTP/2 connections,
495518
// so we can ignore the request for a new connection. This is thus the same as the case below.
496519
fallthrough
@@ -509,7 +532,11 @@ extension HTTPConnectionPool.StateMachine.ConnectionAction {
509532
closeConnections: closeConnections,
510533
scheduleTimeout: nil
511534
)
512-
case .scheduleTimeoutTimerAndCreateConnection(timeoutID: let connectionID, newConnectionID: _, on: let eventLoop):
535+
case .scheduleTimeoutTimerAndCreateConnection(
536+
timeoutID: let connectionID,
537+
newConnectionID: _,
538+
on: let eventLoop
539+
):
513540
// This event can only come _from_ the HTTP/1 pool, migrating to HTTP/2. We do not do prewarmed HTTP/2 connections,
514541
// so we can ignore the request for a new connection. This is thus the same as the case below.
515542
fallthrough

Sources/AsyncHTTPClient/HTTPClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,11 +1212,11 @@ extension HTTPClient.Configuration {
12121212
public var retryConnectionEstablishment: Bool = true
12131213

12141214
/// The number of pre-warmed HTTP/1 connections to maintain.
1215-
///
1215+
///
12161216
/// When set to a number greater than zero, any HTTP/1 connection pool created will attempt to maintain
12171217
/// at least this number of "extra" idle connections, above the connections currently in use, up to the
12181218
/// limit of ``concurrentHTTP1ConnectionsPerHostSoftLimit``.
1219-
///
1219+
///
12201220
/// These connections will not be made while the pool is idle: only once the first connection is made
12211221
/// to a host will the others be opened. In addition, to manage the connection creation rate and
12221222
/// avoid flooding servers, prewarmed connection creation will be done one-at-a-time.

0 commit comments

Comments
 (0)