Ejemplo n.º 1
0
        /// <summary>
        /// Called internally when an existing link session is closed.
        /// </summary>
        internal protected void OnLinkSessionDisconnectedInternal(int handle, object context)
        {
            Trace.Info("{0} disconnected {1} {2}", Name, handle, context);

            if (handle == 0)
            {
                return;
            }

            // Release the link session handle.
            LinkHandlePool.Release(handle);

            var session = (LinkSession)context;

            session.Connected = false;

            try
            {
                OnSessionDisconnectedInternal(handle, context);
            }
            catch (ObjectDisposedException)
            {
                // already disposed
                // TODO need to be improved
            }

            Hub.Post(new LinkSessionDisconnected {
                LinkName = Name,
                Handle   = handle,
                Context  = context
            });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Removes the specified handle from the known peers.
 /// </summary>
 public void RemoveHandle(int handle)
 {
     using (new UpgradeableReadLock(rwlock))
     {
         EndPoint endPoint;
         if (!map.TryGetValue(handle, out endPoint))
         {
             return;
         }
         using (new WriteLock(rwlock))
         {
             map.Remove(handle);
             reverseMap.Remove(endPoint);
         }
     }
     LinkHandlePool.Release(handle);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Removes the specified remote end point from the known peers.
        /// </summary>
        public void RemoveEndPoint(EndPoint endPoint)
        {
            int handle;

            using (new UpgradeableReadLock(rwlock))
            {
                if (!reverseMap.TryGetValue(endPoint, out handle))
                {
                    return;
                }
                using (new WriteLock(rwlock))
                {
                    map.Remove(handle);
                    reverseMap.Remove(endPoint);
                }
            }
            LinkHandlePool.Release(handle);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <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
            });
        }