mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[ijent] IJPL-74864: Allow terminating connection by timeout
GitOrigin-RevId: f528ebe690a8ef43474d19b0605e0fd517373dd2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f353703209
commit
e7a93c5a6a
@@ -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 <T> 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 <T> IjentTunnelsApi.withConnectionToRemotePort(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun <T> 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 <T> IjentTunnelsApi.withConnectionToRemotePort(
|
||||
remotePort: UShort,
|
||||
errorHandler: suspend (IjentConnectionError) -> T,
|
||||
@@ -277,6 +292,10 @@ sealed interface IjentNetworkResult<out T, out E : IjentNetworkError> {
|
||||
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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user