Beispiel #1
0
        /// <summary>
        /// Adds the specified remote end point to the known peers, and returns
        /// the handle associated with it.
        /// </summary>
        public int AddEndPoint(EndPoint endPoint)
        {
            int handle;

            using (new UpgradeableReadLock(rwlock))
            {
                if (!reverseMap.TryGetValue(endPoint, out handle))
                {
                    handle = LinkHandlePool.Acquire();
                    using (new WriteLock(rwlock))
                    {
                        map.Add(handle, endPoint);
                        reverseMap.Add(endPoint, handle);
                    }
                }
            }
            return(handle);
        }
        /// <summary>
        /// Called internally when a new session creation attempt is completed.
        /// </summary>
        internal protected void OnLinkSessionConnectedInternal(bool result, object context)
        {
            Trace.Info("{0} connected {1} {2}", Name, result, context);

            if (result)
            {
                var session = (LinkSession)context;
                lock (session.SyncRoot)
                {
                    // Assign a new link session handle.
                    session.Handle = LinkHandlePool.Acquire();
                }
                session.Connected = true;
            }

            OnSessionConnectedInternal(result, context);

            Hub.Post(new LinkSessionConnected {
                LinkName = Name,
                Result   = result,
                Context  = context
            });
        }