connectUri function

Future<SocketInterface> connectUri(
  1. Uri uri,
  2. SocketInterface socket, {
  3. SocketFilter secureUpgrade,
})

Implementation

Future<SocketInterface> connectUri(Uri uri, SocketInterface socket,
    {SocketFilter secureUpgrade}) async {
  /// We might be asking the remote to open an SSH tunnel to [uri].
  Completer<String> connectCompleter = Completer<String>();
  socket.connect(uri, () => connectCompleter.complete(null),
      (error) => connectCompleter.complete('$error'));
  String connectError = await connectCompleter.future;
  if (connectError != null) throw FormatException(connectError);

  if (secureUpgrade != null &&
      uri.hasScheme &&
      (uri.scheme == 'https' || uri.scheme == 'wss')) {
    socket = await secureUpgrade(socket);
  }

  return socket;
}