| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Collections.Concurrent; |
| | 4 | | using System.Net.Security; |
| | 5 | |
|
| | 6 | | namespace IceRpc.Transports.Coloc.Internal; |
| | 7 | |
|
| | 8 | | /// <summary>Implements <see cref="IDuplexServerTransport" /> for the coloc transport.</summary> |
| | 9 | | internal class ColocServerTransport : IDuplexServerTransport |
| | 10 | | { |
| | 11 | | /// <inheritdoc/> |
| 1214 | 12 | | public string Name => ColocTransport.Name; |
| | 13 | |
|
| | 14 | | private readonly ConcurrentDictionary<ServerAddress, ColocListener> _listeners; |
| | 15 | | private readonly ColocTransportOptions _options; |
| | 16 | |
|
| | 17 | | /// <inheritdoc/> |
| | 18 | | public IListener<IDuplexConnection> Listen( |
| | 19 | | ServerAddress serverAddress, |
| | 20 | | DuplexConnectionOptions options, |
| | 21 | | SslServerAuthenticationOptions? serverAuthenticationOptions) |
| 990 | 22 | | { |
| 990 | 23 | | if (serverAuthenticationOptions is not null) |
| 0 | 24 | | { |
| 0 | 25 | | throw new NotSupportedException("The Coloc server transport does not support SSL."); |
| | 26 | | } |
| | 27 | |
|
| 990 | 28 | | if ((serverAddress.Transport is string transport && transport != Name) || |
| 990 | 29 | | !ColocTransport.CheckParams(serverAddress)) |
| 4 | 30 | | { |
| 4 | 31 | | throw new ArgumentException( |
| 4 | 32 | | $"The server address '{serverAddress}' contains parameters that are not valid for the Coloc server trans |
| 4 | 33 | | nameof(serverAddress)); |
| | 34 | | } |
| | 35 | |
|
| 986 | 36 | | var listener = new ColocListener( |
| 986 | 37 | | serverAddress with { Transport = Name }, |
| 986 | 38 | | colocTransportOptions: _options, |
| 986 | 39 | | duplexConnectionOptions: options); |
| | 40 | |
|
| 986 | 41 | | if (!_listeners.TryAdd(listener.ServerAddress, listener)) |
| 4 | 42 | | { |
| 4 | 43 | | throw new IceRpcException(IceRpcError.AddressInUse); |
| | 44 | | } |
| 982 | 45 | | return listener; |
| 982 | 46 | | } |
| | 47 | |
|
| 978 | 48 | | internal ColocServerTransport( |
| 978 | 49 | | ConcurrentDictionary<ServerAddress, ColocListener> listeners, |
| 978 | 50 | | ColocTransportOptions options) |
| 978 | 51 | | { |
| 978 | 52 | | _listeners = listeners; |
| 978 | 53 | | _options = options; |
| 978 | 54 | | } |
| | 55 | | } |