Пример #1
0
        public void IdentifyConnection(INetworkConnection connection)
        {
            TaskCompletionSource <bool> tcs;

            if (_current.TryGetValue(connection, out tcs))
            {
                tcs.Task.Wait();
                return;
            }

            tcs = new TaskCompletionSource <bool>();
            _current.TryAdd(connection, tcs);

            try
            {
                using (var s = connection.NewStream())
                {
                    s.Protocol = Id;
                    //wrap reporter

                    MultistreamMuxer.SelectProtoOrFail(Id, ((IReadWriter)s).AsSystemStream());

                    ResponseHandler(s);

                    _current.TryRemove(connection, out tcs);
                }
            }
            catch (Exception e)
            {
                tcs.TrySetException(e);
            }
            finally
            {
                tcs.TrySetResult(true);
            }
        }