mirror of https://github.com/grpc/grpc-dart.git
Added ability to set connectTimeout of socket (#575)
This commit is contained in:
parent
6c0829ed8b
commit
60311a7492
|
|
@ -1,5 +1,10 @@
|
|||
## 3.1.1-dev
|
||||
|
||||
* `ChannelOptions` now exposes `connectTimeout`, which is used on the
|
||||
socket connect. This is used to specify the maximum allowed time to wait
|
||||
for a connection to be established. If `connectTime` is longer than the system
|
||||
level timeout duration, a timeout may occur sooner than specified in
|
||||
`connectTimeout`. On timeout, a `SocketException` is thrown.
|
||||
* Require Dart 2.17 or greater.
|
||||
* Fix issue [#51](https://github.com/grpc/grpc-dart/issues/51), add support for custom error handling.
|
||||
|
||||
|
|
|
|||
|
|
@ -334,7 +334,8 @@ class _SocketTransportConnector implements ClientTransportConnector {
|
|||
@override
|
||||
Future<ClientTransportConnection> connect() async {
|
||||
final securityContext = _options.credentials.securityContext;
|
||||
_socket = await Socket.connect(_host, _port);
|
||||
_socket =
|
||||
await Socket.connect(_host, _port, timeout: _options.connectTimeout);
|
||||
// Don't wait for io buffers to fill up before sending requests.
|
||||
if (_socket.address.type != InternetAddressType.unix) {
|
||||
_socket.setOption(SocketOption.tcpNoDelay, true);
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@ class ChannelOptions {
|
|||
|
||||
/// The maximum time a single connection will be used for new requests.
|
||||
final Duration connectionTimeout;
|
||||
|
||||
/// The maximum allowed time to wait for a connection to be established.
|
||||
/// If [connectTimeout] is longer than the system level timeout duration,
|
||||
/// a timeout may occur sooner than specified in [connectTimeout].
|
||||
final Duration? connectTimeout;
|
||||
final BackoffStrategy backoffStrategy;
|
||||
final String userAgent;
|
||||
|
||||
|
|
@ -58,6 +63,7 @@ class ChannelOptions {
|
|||
this.idleTimeout = defaultIdleTimeout,
|
||||
this.userAgent = defaultUserAgent,
|
||||
this.backoffStrategy = defaultBackoffStrategy,
|
||||
this.connectTimeout,
|
||||
this.connectionTimeout = defaultConnectionTimeOut,
|
||||
this.codecRegistry,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -69,6 +69,8 @@ class FakeChannelOptions implements ChannelOptions {
|
|||
@override
|
||||
Duration connectionTimeout = const Duration(seconds: 10);
|
||||
@override
|
||||
Duration? connectTimeout;
|
||||
@override
|
||||
String userAgent = 'dart-grpc/1.0.0 test';
|
||||
@override
|
||||
BackoffStrategy backoffStrategy = testBackoff;
|
||||
|
|
|
|||
Loading…
Reference in New Issue