| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using IceRpc.Transports.Quic; |
| | | 4 | | using IceRpc.Transports.Slic; |
| | | 5 | | using IceRpc.Transports.Tcp; |
| | | 6 | | using System.Net.Security; |
| | | 7 | | using System.Runtime.Versioning; |
| | | 8 | | |
| | | 9 | | namespace IceRpc.Transports.Internal; |
| | | 10 | | |
| | | 11 | | /// <summary>Implements <see cref="IMultiplexedServerTransport" /> using two multiplexed transports: QUIC and |
| | | 12 | | /// Slic over TCP.</summary> |
| | | 13 | | internal class DefaultMultiplexedServerTransport : IMultiplexedServerTransport |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc/> |
| | 3 | 16 | | public string DefaultName => _quicTransport.DefaultName; |
| | | 17 | | |
| | | 18 | | internal static DefaultMultiplexedServerTransport Instance |
| | | 19 | | { |
| | | 20 | | get |
| | 10 | 21 | | { |
| | 10 | 22 | | if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsWindows()) |
| | 10 | 23 | | { |
| | 10 | 24 | | return _instance; |
| | | 25 | | } |
| | 0 | 26 | | throw new PlatformNotSupportedException( |
| | 0 | 27 | | "The default multiplexed server transport, QUIC, is only available on Linux, macOS, and Windows."); |
| | 10 | 28 | | } |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | [SupportedOSPlatform("linux")] |
| | | 32 | | [SupportedOSPlatform("macos")] |
| | | 33 | | [SupportedOSPlatform("windows")] |
| | 1 | 34 | | private static readonly DefaultMultiplexedServerTransport _instance = new(); |
| | | 35 | | |
| | | 36 | | private readonly IMultiplexedServerTransport _quicTransport; |
| | 1 | 37 | | private readonly IMultiplexedServerTransport _tcpTransport = new SlicServerTransport(new TcpServerTransport()); |
| | | 38 | | |
| | | 39 | | /// <inheritdoc/> |
| | | 40 | | public IListener<IMultiplexedConnection> Listen( |
| | | 41 | | TransportAddress transportAddress, |
| | | 42 | | MultiplexedConnectionOptions options, |
| | | 43 | | SslServerAuthenticationOptions? serverAuthenticationOptions) |
| | 5 | 44 | | { |
| | 5 | 45 | | return Resolve(transportAddress.TransportName).Listen(transportAddress, options, serverAuthenticationOptions); |
| | | 46 | | |
| | | 47 | | IMultiplexedServerTransport Resolve(string? transportName) => |
| | 5 | 48 | | transportName switch |
| | 5 | 49 | | { |
| | 0 | 50 | | null => _quicTransport, |
| | 4 | 51 | | "quic" => _quicTransport, |
| | 1 | 52 | | "tcp" => _tcpTransport, |
| | 0 | 53 | | _ => throw new NotSupportedException( |
| | 0 | 54 | | $"The default multiplexed server transport does not support transport '{transportName}'.") |
| | 5 | 55 | | }; |
| | 5 | 56 | | } |
| | | 57 | | |
| | | 58 | | [SupportedOSPlatform("linux")] |
| | | 59 | | [SupportedOSPlatform("macos")] |
| | | 60 | | [SupportedOSPlatform("windows")] |
| | 2 | 61 | | private DefaultMultiplexedServerTransport() => _quicTransport = new QuicServerTransport(); |
| | | 62 | | } |