Skip to content

Commit 77a3d7e

Browse files
committed
[HTTPConnectionPool] Move Connections down in the file
1 parent 64fbfda commit 77a3d7e

File tree

1 file changed

+109
-107
lines changed

1 file changed

+109
-107
lines changed

‎Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift‎

Lines changed: 109 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -22,113 +22,6 @@ protocol HTTPConnectionPoolDelegate{
2222
}
2323

2424
finalclassHTTPConnectionPool{
25-
structConnection:Hashable{
26-
typealiasID=Int
27-
28-
privateenumReference{
29-
case http1_1(HTTP1Connection)
30-
case http2(HTTP2Connection)
31-
case __testOnly_connection(ID,EventLoop)
32-
}
33-
34-
privatelet_ref:Reference
35-
36-
fileprivatestaticfunc http1_1(_ conn:HTTP1Connection)->Self{
37-
Connection(_ref:.http1_1(conn))
38-
}
39-
40-
fileprivatestaticfunc http2(_ conn:HTTP2Connection)->Self{
41-
Connection(_ref:.http2(conn))
42-
}
43-
44-
staticfunc __testOnly_connection(id:ID, eventLoop:EventLoop)->Self{
45-
Connection(_ref:.__testOnly_connection(id, eventLoop))
46-
}
47-
48-
varid:ID{
49-
switchself._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-
vareventLoop:EventLoop{
60-
switchself._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-
fileprivatefunc executeRequest(_ request:HTTPExecutableRequest){
71-
switchself._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-
fileprivatefunc shutdown(){
83-
switchself._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-
fileprivatefunc close(promise:EventLoopPromise<Void>?){
96-
switchself._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-
staticfunc==(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-
returnfalse
116-
}
117-
}
118-
119-
func hash(into hasher:inoutHasher){
120-
switchself._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-
}
131-
13225
privateletstateLock=Lock()
13326
privatevar_state:StateMachine
13427

@@ -530,6 +423,115 @@ extension HTTPConnectionPool: HTTPRequestScheduler{
530423
}
531424
}
532425

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

0 commit comments

Comments
(0)