bind static method

Binds a server using config.

The configuration can be released afterwards; the returned server and its sessions keep working.

Implementation

static Future<WebTransportServer> bind(
  WebTransportServerConfig config,
) async {
  nativeRuntime.start();
  // Applies the identity and the socket settings to the native handle; the
  // certificate digest can only be read afterwards.
  config.materialize();
  final hashes = config.certificateHashes();

  final outStatus = calloc<Int>();
  Pointer<b.wt_server_t> server;
  try {
    server = b.wt_server_new(config.materialize(), outStatus);
    if (server == nullptr) {
      throw WebTransportException(
        outStatus.value,
        'could not create the server endpoint',
        operation: 'wt_server_new',
      );
    }
  } finally {
    calloc.free(outStatus);
  }
  return WebTransportServer._(server, hashes);
}