Skip to content

Commit 74e83fb

Browse files
committed
Move Connections down in the file
1 parent 7808ca1 commit 74e83fb

File tree

1 file changed

+109
-106
lines changed

1 file changed

+109
-106
lines changed

Diff for: Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift

+109-106
Original file line numberDiff line numberDiff line change
@@ -22,112 +22,6 @@ protocol HTTPConnectionPoolDelegate {
2222
}
2323

2424
final class HTTPConnectionPool {
25-
struct Connection: Hashable {
26-
typealias ID = Int
27-
28-
private enum Reference {
29-
case http1_1(HTTP1Connection)
30-
case http2(HTTP2Connection)
31-
case __testOnly_connection(ID, EventLoop)
32-
}
33-
34-
private let _ref: Reference
35-
36-
fileprivate static func http1_1(_ conn: HTTP1Connection) -> Self {
37-
Connection(_ref: .http1_1(conn))
38-
}
39-
40-
fileprivate static func http2(_ conn: HTTP2Connection) -> Self {
41-
Connection(_ref: .http2(conn))
42-
}
43-
44-
static func __testOnly_connection(id: ID, eventLoop: EventLoop) -> Self {
45-
Connection(_ref: .__testOnly_connection(id, eventLoop))
46-
}
47-
48-
var id: ID {
49-
switch self._ref {
50-
case .http1_1(let connection):
51-
return connection.id
52-
case .http2(let connection):
53-
return connection.id
54-
case .__testOnly_connection(let id, _):
55-
return id
56-
}
57-
}
58-
59-
var eventLoop: EventLoop {
60-
switch self._ref {
61-
case .http1_1(let connection):
62-
return connection.channel.eventLoop
63-
case .http2(let connection):
64-
return connection.channel.eventLoop
65-
case .__testOnly_connection(_, let eventLoop):
66-
return eventLoop
67-
}
68-
}
69-
70-
fileprivate func executeRequest(_ request: HTTPExecutableRequest) {
71-
switch self._ref {
72-
case .http1_1(let connection):
73-
return connection.executeRequest(request)
74-
case .http2(let connection):
75-
return connection.executeRequest(request)
76-
case .__testOnly_connection:
77-
break
78-
}
79-
}
80-
81-
/// Shutdown cancels any running requests on the connection and then closes the connection
82-
fileprivate func shutdown() {
83-
switch self._ref {
84-
case .http1_1(let connection):
85-
return connection.shutdown()
86-
case .http2(let connection):
87-
return connection.shutdown()
88-
case .__testOnly_connection:
89-
break
90-
}
91-
}
92-
93-
/// Closes the connection without cancelling running requests. Use this when you are sure, that the
94-
/// connection is currently idle.
95-
fileprivate func close(promise: EventLoopPromise<Void>?) {
96-
switch self._ref {
97-
case .http1_1(let connection):
98-
return connection.close(promise: promise)
99-
case .http2(let connection):
100-
return connection.close(promise: promise)
101-
case .__testOnly_connection:
102-
promise?.succeed(())
103-
}
104-
}
105-
106-
static func == (lhs: HTTPConnectionPool.Connection, rhs: HTTPConnectionPool.Connection) -> Bool {
107-
switch (lhs._ref, rhs._ref) {
108-
case (.http1_1(let lhsConn), .http1_1(let rhsConn)):
109-
return lhsConn.id == rhsConn.id
110-
case (.http2(let lhsConn), .http2(let rhsConn)):
111-
return lhsConn.id == rhsConn.id
112-
case (.__testOnly_connection(let lhsID, let lhsEventLoop), .__testOnly_connection(let rhsID, let rhsEventLoop)):
113-
return lhsID == rhsID && lhsEventLoop === rhsEventLoop
114-
default:
115-
return false
116-
}
117-
}
118-
119-
func hash(into hasher: inout Hasher) {
120-
switch self._ref {
121-
case .http1_1(let conn):
122-
hasher.combine(conn.id)
123-
case .http2(let conn):
124-
hasher.combine(conn.id)
125-
case .__testOnly_connection(let id, let eventLoop):
126-
hasher.combine(id)
127-
hasher.combine(eventLoop.id)
128-
}
129-
}
130-
}
13125

13226
private let stateLock = Lock()
13327
private var _state: StateMachine
@@ -531,6 +425,115 @@ extension HTTPConnectionPool: HTTPRequestScheduler {
531425
}
532426
}
533427

428+
extension HTTPConnectionPool {
429+
struct Connection: Hashable {
430+
typealias ID = Int
431+
432+
private enum Reference {
433+
case http1_1(HTTP1Connection)
434+
case http2(HTTP2Connection)
435+
case __testOnly_connection(ID, EventLoop)
436+
}
437+
438+
private let _ref: Reference
439+
440+
fileprivate static func http1_1(_ conn: HTTP1Connection) -> Self {
441+
Connection(_ref: .http1_1(conn))
442+
}
443+
444+
fileprivate static func http2(_ conn: HTTP2Connection) -> Self {
445+
Connection(_ref: .http2(conn))
446+
}
447+
448+
static func __testOnly_connection(id: ID, eventLoop: EventLoop) -> Self {
449+
Connection(_ref: .__testOnly_connection(id, eventLoop))
450+
}
451+
452+
var id: ID {
453+
switch self._ref {
454+
case .http1_1(let connection):
455+
return connection.id
456+
case .http2(let connection):
457+
return connection.id
458+
case .__testOnly_connection(let id, _):
459+
return id
460+
}
461+
}
462+
463+
var eventLoop: EventLoop {
464+
switch self._ref {
465+
case .http1_1(let connection):
466+
return connection.channel.eventLoop
467+
case .http2(let connection):
468+
return connection.channel.eventLoop
469+
case .__testOnly_connection(_, let eventLoop):
470+
return eventLoop
471+
}
472+
}
473+
474+
fileprivate func executeRequest(_ request: HTTPExecutableRequest) {
475+
switch self._ref {
476+
case .http1_1(let connection):
477+
return connection.executeRequest(request)
478+
case .http2(let connection):
479+
return connection.executeRequest(request)
480+
case .__testOnly_connection:
481+
break
482+
}
483+
}
484+
485+
/// Shutdown cancels any running requests on the connection and then closes the connection
486+
fileprivate func shutdown() {
487+
switch self._ref {
488+
case .http1_1(let connection):
489+
return connection.shutdown()
490+
case .http2(let connection):
491+
return connection.shutdown()
492+
case .__testOnly_connection:
493+
break
494+
}
495+
}
496+
497+
/// Closes the connection without cancelling running requests. Use this when you are sure, that the
498+
/// connection is currently idle.
499+
fileprivate func close(promise: EventLoopPromise<Void>?) {
500+
switch self._ref {
501+
case .http1_1(let connection):
502+
return connection.close(promise: promise)
503+
case .http2(let connection):
504+
return connection.close(promise: promise)
505+
case .__testOnly_connection:
506+
promise?.succeed(())
507+
}
508+
}
509+
510+
static func == (lhs: HTTPConnectionPool.Connection, rhs: HTTPConnectionPool.Connection) -> Bool {
511+
switch (lhs._ref, rhs._ref) {
512+
case (.http1_1(let lhsConn), .http1_1(let rhsConn)):
513+
return lhsConn.id == rhsConn.id
514+
case (.http2(let lhsConn), .http2(let rhsConn)):
515+
return lhsConn.id == rhsConn.id
516+
case (.__testOnly_connection(let lhsID, let lhsEventLoop), .__testOnly_connection(let rhsID, let rhsEventLoop)):
517+
return lhsID == rhsID && lhsEventLoop === rhsEventLoop
518+
default:
519+
return false
520+
}
521+
}
522+
523+
func hash(into hasher: inout Hasher) {
524+
switch self._ref {
525+
case .http1_1(let conn):
526+
hasher.combine(conn.id)
527+
case .http2(let conn):
528+
hasher.combine(conn.id)
529+
case .__testOnly_connection(let id, let eventLoop):
530+
hasher.combine(id)
531+
hasher.combine(eventLoop.id)
532+
}
533+
}
534+
}
535+
}
536+
534537
extension HTTPConnectionPool {
535538
/// This is a wrapper that we use inside the connection pool state machine to ensure that
536539
/// the actual request can not be accessed at any time. Further it exposes all that is needed within

0 commit comments

Comments
 (0)