public async Task Run(string listenAddress, string listenToken) { Console.WriteLine("Starting listener on {0}", listenAddress); using (var relayListener = new RelayListener(listenAddress, TokenProvider.CreateSharedAccessSignatureTokenProvider(listenToken), RelayAddressType.Configured)) { await relayListener.StartAsync(); RelayConnection connection; do { await maxConcurrentConnections.WaitAsync(); try { connection = await relayListener.AcceptConnectionAsync(TimeSpan.MaxValue); } catch { maxConcurrentConnections.Release(); throw; } if (connection != null) { // not awaiting, we're handling these in parallel on the I/O thread pool // and simply running into the first await inside ProcessConnection // is sufficient to get the handling off this thread #pragma warning disable 4014 ProcessConnection(connection).ContinueWith( t => maxConcurrentConnections.Release()); #pragma warning restore 4014 } else { maxConcurrentConnections.Release(); } } while (connection != null); } }
public RelayListenerServerTransport(RelayListener listener) { this.listener = listener; }