|
| 1 | +#if canImport(Darwin) |
| 2 | +import Darwin |
| 3 | +#else |
| 4 | +import Glibc |
| 5 | +#endif |
| 6 | + |
| 7 | +@usableFromInline |
| 8 | +@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) |
| 9 | +struct PoolConfiguration { |
| 10 | + /// The minimum number of connections to preserve in the pool. |
| 11 | + /// |
| 12 | + /// If the pool is mostly idle and the remote servers closes idle connections, |
| 13 | + /// the `ConnectionPool` will initiate new outbound connections proactively |
| 14 | + /// to avoid the number of available connections dropping below this number. |
| 15 | + @usableFromInline |
| 16 | + var minimumConnectionCount: Int = 0 |
| 17 | + |
| 18 | + /// The maximum number of connections to for this pool, to be preserved. |
| 19 | + @usableFromInline |
| 20 | + var maximumConnectionSoftLimit: Int = 10 |
| 21 | + |
| 22 | + @usableFromInline |
| 23 | + var maximumConnectionHardLimit: Int = 10 |
| 24 | + |
| 25 | + @usableFromInline |
| 26 | + var keepAliveDuration: Duration? |
| 27 | + |
| 28 | + @usableFromInline |
| 29 | + var idleTimeoutDuration: Duration = .seconds(30) |
| 30 | +} |
| 31 | + |
| 32 | +@usableFromInline |
| 33 | +@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) |
| 34 | +struct PoolStateMachine< |
| 35 | + Connection: PooledConnection, |
| 36 | + ConnectionIDGenerator: ConnectionIDGeneratorProtocol, |
| 37 | + ConnectionID: Hashable & Sendable, |
| 38 | + Request: ConnectionRequestProtocol, |
| 39 | + RequestID, |
| 40 | + TimerCancellationToken |
| 41 | +> where Connection.ID == ConnectionID, ConnectionIDGenerator.ID == ConnectionID, RequestID == Request.ID { |
| 42 | + |
| 43 | + @usableFromInline |
| 44 | + struct Timer: Hashable, Sendable { |
| 45 | + @usableFromInline |
| 46 | + enum Usecase: Sendable { |
| 47 | + case backoff |
| 48 | + case idleTimeout |
| 49 | + case keepAlive |
| 50 | + } |
| 51 | + |
| 52 | + @usableFromInline |
| 53 | + var connectionID: ConnectionID |
| 54 | + |
| 55 | + @usableFromInline |
| 56 | + var timerID: Int |
| 57 | + |
| 58 | + @usableFromInline |
| 59 | + var duration: Duration |
| 60 | + |
| 61 | + @usableFromInline |
| 62 | + var usecase: Usecase |
| 63 | + |
| 64 | + @inlinable |
| 65 | + init(connectionID: ConnectionID, timerID: Int, duration: Duration, usecase: Usecase) { |
| 66 | + self.connectionID = connectionID |
| 67 | + self.timerID = timerID |
| 68 | + self.duration = duration |
| 69 | + self.usecase = usecase |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + |
| 74 | +} |
0 commit comments