serveConnection method

Future<void> serveConnection({
  1. required ServerTransportConnection connection,
  2. X509Certificate? clientCertificate,
  3. InternetAddress? remoteAddress,
})

Implementation

Future<void> serveConnection({
  required ServerTransportConnection connection,
  X509Certificate? clientCertificate,
  InternetAddress? remoteAddress,
}) async {
  _connections.add(connection);
  ServerHandler? handler;
  // TODO(jakobr): Set active state handlers, close connection after idle
  // timeout.
  connection.incomingStreams.listen((stream) {
    handler = serveStream_(
      stream: stream,
      clientCertificate: clientCertificate,
      remoteAddress: remoteAddress,
    );
  }, onError: (error, stackTrace) {
    if (error is Error) {
      Zone.current.handleUncaughtError(error, stackTrace);
    }
  }, onDone: () {
    // TODO(sigurdm): This is not correct behavior in the presence of
    // half-closed tcp streams.
    // Half-closed  streams seems to not be fully supported by package:http2.
    // https://github.com/dart-lang/http2/issues/42
    handler?.cancel();
    _connections.remove(connection);
  });
}