diff --git a/platform/ijent/src/com/intellij/platform/ijent/IjentTunnelsApi.kt b/platform/ijent/src/com/intellij/platform/ijent/IjentTunnelsApi.kt index 0f299fa9e432..d37e41d868c3 100644 --- a/platform/ijent/src/com/intellij/platform/ijent/IjentTunnelsApi.kt +++ b/platform/ijent/src/com/intellij/platform/ijent/IjentTunnelsApi.kt @@ -81,6 +81,16 @@ sealed interface IjentTunnelsApi { */ fun preferOSDefault(): Builder + /** + * Sets timeout for connecting to remote host. + * If the connection could not be established before [timeout], then [IjentConnectionError.ConnectionTimeout] would be returned + * in [IjentTunnelsApi.getConnectionToRemotePort]. + * + * Default value: 10 seconds. + * The recognizable granularity is milliseconds. + */ + fun connectionTimeout(timeout: Duration): Builder + /** * Builds a remote host address object. */ @@ -229,10 +239,10 @@ interface IjentTunnelsWindowsApi : IjentTunnelsApi * @see com.intellij.platform.ijent.IjentTunnelsApi.getConnectionToRemotePort for more details on the behavior of [Connection] */ suspend fun IjentTunnelsApi.withConnectionToRemotePort( - host: String, port: UShort, + hostAddress: IjentTunnelsApi.HostAddress, errorHandler: suspend (IjentConnectionError) -> T, action: suspend CoroutineScope.(Connection) -> T): T = - when (val connectionResult = getConnectionToRemotePort(hostAddressBuilder(port).hostname(host).build())) { + when (val connectionResult = getConnectionToRemotePort(hostAddress)) { is IjentNetworkResult.Error -> errorHandler(connectionResult.error) is Ok -> try { coroutineScope { action(connectionResult.value) } @@ -242,6 +252,11 @@ suspend fun IjentTunnelsApi.withConnectionToRemotePort( } } +suspend fun IjentTunnelsApi.withConnectionToRemotePort( + host: String, port: UShort, + errorHandler: suspend (IjentConnectionError) -> T, + action: suspend CoroutineScope.(Connection) -> T): T = withConnectionToRemotePort(hostAddressBuilder(port).hostname(host).build(), errorHandler, action) + suspend fun IjentTunnelsApi.withConnectionToRemotePort( remotePort: UShort, errorHandler: suspend (IjentConnectionError) -> T, @@ -277,6 +292,10 @@ sealed interface IjentNetworkResult { interface IjentConnectionError : IjentNetworkError { val message: @NlsSafe String + data object ConnectionTimeout : IjentConnectionError { + override val message: @NlsSafe String = "Connection could not be established because of timeout" + } + /** * Returned when a hostname on the remote server was resolved to multiple different addresses. */