reconnect method

Future<Connection> reconnect([
  1. bool noreplyWait = true
])

Implementation

Future<Connection> reconnect([bool noreplyWait = true]) {
  close(noreplyWait);

  if (_listeners["connect"] != null) {
    _listeners["connect"]!.forEach((func) => func());
  }
  var _sock = Socket.connect(_host, _port);

  if (_sslOpts != null && _sslOpts!.containsKey('ca')) {
    SecurityContext context = SecurityContext()
      ..setTrustedCertificates(_sslOpts!['ca']);
    _sock = SecureSocket.connect(_host, _port, context: context);
  }

  _sock.then((socket) {
    // ignore: unnecessary_null_comparison
    if (socket != null) {
      _socket = socket;
      _socket!.listen(_handleResponse, onDone: () {
        if (_listeners["close"] != null) {
          _listeners["close"]!.forEach((func) => func());
        }
      });

      _clientFirstMessage = "n=$_user,r=" + _makeSalt();
      String message = json.encode({
        'protocol_version': _protocolVersion,
        'authentication_method': "SCRAM-SHA-256",
        // ignore: unnecessary_brace_in_string_interps
        'authentication': "n,,${_clientFirstMessage}"
      });
      List<int> handshake =
          List.from(_toBytes(p.VersionDummy_Version.V1_0.value))
            ..addAll(message.codeUnits)
            ..add(0);

      _socket!.add(handshake);
    }
  }).catchError((err) {
    _completer.completeError(
      RqlDriverError("Could not connect to $_host:$_port.  Error $err"),
    );
  });

  return _completer.future;
}