Scoop API

scoop:scoop.asyncio:0.1.0

src/tcp_connect_options.scoop

Selected production source · src/tcp_connect_options.scoop

1package scoop.asyncio
3import scoop.platform.net.*
4import scoop.platform.system.OsString
5import scoop.time.Duration
7/**
8 * Controls staggered address resolution and connection racing, concurrency, optional phase/overall
9 * deadlines, and trace delivery.
10 */
11public class TcpConnectOptions internal constructor(
12 /**
13 * The delay used to stagger address-family resolution.
14 */
15 public val resolutionDelay: Duration = Duration.milliseconds(50L),
16 /**
17 * The delay between starting eligible connection candidates.
18 */
19 public val attemptDelay: Duration = Duration.milliseconds(250L),
20 /**
21 * The positive maximum number of simultaneously active TCP connection attempts.
22 */
23 public val maxConcurrentAttempts: Long = 2L,
24 /**
25 * An optional deadline for address-family resolution.
26 */
27 public val resolveTimeout: Duration? = None,
28 /**
29 * An optional overall deadline for the connection procedure.
30 */
31 public val connectTimeout: Duration? = None,
32 /**
33 * An optional non-suspending observer of resolution and connect phase transitions.
34 */
35 public val onEvent: ((TcpConnectEvent) -> Unit)? = None
36) {
37 init {
38 if (resolutionDelay < Duration.ZERO || attemptDelay < Duration.ZERO) {
39 throw IllegalArgumentException(Some("TCP connection delays must be nonnegative"))
40 }
41 if (maxConcurrentAttempts <= 0L) {
42 throw IllegalArgumentException(Some("TCP connection concurrency must be positive"))
43 }
44 for (timeout in [resolveTimeout, connectTimeout]) {
45 if (timeout != None && timeout!! < Duration.ZERO)
46 throw IllegalArgumentException(Some("TCP connection timeouts must be nonnegative"))
47 }
48 }
51/**
52 * A failed concrete address attempt and its original exception.
53 */
54public struct TcpConnectionFailure(val address: SocketAddress, val cause: Throwable)
56/**
57 * A failed address-family resolution and its original exception.
58 */
59public struct TcpResolutionFailure(val family: AddressFamily, val cause: Throwable)
61/**
62 * All usable TCP candidates failed; retains individual connection and resolution failures.
63 */
64public class TcpConnectException internal constructor(
65 /**
66 * The originally requested host name.
67 */
68 public val host: OsString,
69 /**
70 * The requested destination port.
71 */
72 public val port: Int,
73 /**
74 * The concrete candidate failures collected before termination.
75 */
76 public val attempts: Array<TcpConnectionFailure>,
77 /**
78 * Address-family lookup failures collected before termination.
79 */
80 public val resolutionFailures: Array<TcpResolutionFailure>
81): Exception(Some("all TCP connection candidates failed"))
83/**
84 * Address resolution exceeded its configured time limit for the specified family.
85 */
86public class TcpResolutionTimeoutException internal constructor(
87 /**
88 * The originally requested host name.
89 */
90 public val host: OsString,
91 /**
92 * The requested destination port.
93 */
94 public val port: Int,
95 /**
96 * The address family whose lookup timed out.
97 */
98 public val family: AddressFamily,
99 /**
100 * The configured timeout duration.
101 */
102 public val limit: Duration,
103 /**
104 * The measured elapsed time when the timeout was reported.
105 */
106 public val elapsed: Duration
107): Exception(Some("TCP address resolution timeout"))
109/**
110 * The connection procedure exceeded its configured limit; retains completed attempt and resolution
111 * failures.
112 */
113public class TcpConnectTimeoutException internal constructor(
114 /**
115 * The originally requested host name.
116 */
117 public val host: OsString,
118 /**
119 * The requested destination port.
120 */
121 public val port: Int,
122 /**
123 * The configured timeout duration.
124 */
125 public val limit: Duration,
126 /**
127 * The measured elapsed time when the timeout was reported.
128 */
129 public val elapsed: Duration,
130 /**
131 * The concrete candidate failures collected before termination.
132 */
133 public val attempts: Array<TcpConnectionFailure>,
134 /**
135 * Address-family lookup failures collected before termination.
136 */
137 public val resolutionFailures: Array<TcpResolutionFailure>
138): Exception(Some("TCP connection timeout"))