mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
new: custom timeout
This commit is contained in:
@@ -46,14 +46,16 @@ Future<SSHClient> genClient(
|
|||||||
ServerPrivateInfo spi, {
|
ServerPrivateInfo spi, {
|
||||||
void Function(GenSSHClientStatus)? onStatus,
|
void Function(GenSSHClientStatus)? onStatus,
|
||||||
String? privateKey,
|
String? privateKey,
|
||||||
|
Duration? timeout,
|
||||||
}) async {
|
}) async {
|
||||||
onStatus?.call(GenSSHClientStatus.socket);
|
onStatus?.call(GenSSHClientStatus.socket);
|
||||||
late SSHSocket socket;
|
late SSHSocket socket;
|
||||||
|
final duration = timeout ?? const Duration(seconds: 5);
|
||||||
try {
|
try {
|
||||||
socket = await SSHSocket.connect(
|
socket = await SSHSocket.connect(
|
||||||
spi.ip,
|
spi.ip,
|
||||||
spi.port,
|
spi.port,
|
||||||
timeout: const Duration(seconds: 5),
|
timeout: duration,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (spi.alterUrl == null) rethrow;
|
if (spi.alterUrl == null) rethrow;
|
||||||
@@ -62,7 +64,7 @@ Future<SSHClient> genClient(
|
|||||||
socket = await SSHSocket.connect(
|
socket = await SSHSocket.connect(
|
||||||
ipPort.ip,
|
ipPort.ip,
|
||||||
ipPort.port,
|
ipPort.port,
|
||||||
timeout: const Duration(seconds: 5),
|
timeout: duration,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rethrow;
|
rethrow;
|
||||||
|
|||||||
@@ -198,7 +198,10 @@ class ServerProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
// Only reconnect if neccessary
|
// Only reconnect if neccessary
|
||||||
if (newSpi.shouldReconnect(old)) {
|
if (newSpi.shouldReconnect(old)) {
|
||||||
_servers[newSpi.id]?.client = await genClient(newSpi);
|
_servers[newSpi.id]?.client = await genClient(
|
||||||
|
newSpi,
|
||||||
|
timeout: _settingStore.timeoutD,
|
||||||
|
);
|
||||||
refreshData(spi: newSpi);
|
refreshData(spi: newSpi);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +234,10 @@ class ServerProvider extends ChangeNotifier {
|
|||||||
final time1 = DateTime.now();
|
final time1 = DateTime.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
s.client = await genClient(spi);
|
s.client = await genClient(
|
||||||
|
spi,
|
||||||
|
timeout: _settingStore.timeoutD,
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_limiter.inc(sid);
|
_limiter.inc(sid);
|
||||||
s.status.failedInfo = e.toString();
|
s.status.failedInfo = e.toString();
|
||||||
|
|||||||
@@ -153,4 +153,14 @@ class SettingStore extends PersistentStore {
|
|||||||
'serverTabUseOldUI',
|
'serverTabUseOldUI',
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// Time out for server connect and more...
|
||||||
|
late final timeout = StoreProperty(
|
||||||
|
box,
|
||||||
|
'timeOut',
|
||||||
|
5,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Duration of [timeout]
|
||||||
|
Duration get timeoutD => Duration(seconds: timeout.fetch());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -326,6 +326,7 @@ class _SSHPageState extends State<SSHPage> {
|
|||||||
return _write('Sending password to auth...');
|
return _write('Sending password to auth...');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
timeout: _setting.timeoutD,
|
||||||
);
|
);
|
||||||
_write('Connected\r\n');
|
_write('Connected\r\n');
|
||||||
_write('Terminal size: ${_terminal.viewWidth}x${_terminal.viewHeight}\r\n');
|
_write('Terminal size: ${_terminal.viewWidth}x${_terminal.viewHeight}\r\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user