Esempio n. 1
0
 public void Disconnect(object socket, int timeout)
 {
     if (socket != null)
     {
         if (ToPeer.ContainsKey((EndPoint)socket))
         {
             if (SocketList.Contains(ToPeer[(EndPoint)socket]))
             {
                 SocketList.Remove(ToPeer[(EndPoint)socket]);
             }
         }
         if (SocketToKey.ContainsKey((EndPoint)socket))
         {
             SocketToKey.Remove((EndPoint)socket);
         }
         if (ToPeer.ContainsKey((EndPoint)socket))
         {
             ToPeer.Remove((EndPoint)socket);
         }
         lock (checklock)
         {
             if (clientcheck.ContainsKey((EndPoint)socket))
             {
                 clientcheck.Remove((EndPoint)socket);
             }
         }
     }
 }
Esempio n. 2
0
        public void Disconnect(object socket, int timeout)
        {
            if (socket != null)
            {
                if (SocketToEndPoint.ContainsKey((Socket)socket))
                {
                    if (ToPeer.ContainsKey(SocketToEndPoint[(Socket)socket]))
                    {
                        if (SocketList.Contains(ToPeer[SocketToEndPoint[(Socket)socket]]))
                        {
                            SocketList.Remove(ToPeer[SocketToEndPoint[(Socket)socket]]);
                        }
                    }
                    if (SocketToKey.ContainsKey(socket))
                    {
                        SocketToKey.Remove(socket);
                    }
                    if (ToPeer.ContainsKey(SocketToEndPoint[(Socket)socket]))
                    {
                        ToPeer.Remove(SocketToEndPoint[(Socket)socket]);
                    }
                }

                try
                {
                    ((Socket)socket).Shutdown(SocketShutdown.Both);
                }
                catch (Exception e)
                {
                    GetMessage(e.Message);
                }
                finally
                {
                    if (timeout == -1)
                    {
                        ((Socket)socket).Close();
                    }
                    else
                    {
                        ((Socket)socket).Close(timeout);
                    }
                    socket = null;
                }
            }
        }