예제 #1
0
 public void Dispose()
 {
     _DisConnect();
     Clear();
     ReceiveEventArgs.Dispose();
     SendEventArgs.Dispose();
 }
예제 #2
0
        /// <summary>
        /// 销毁当前对象并且从服务器列表中删除
        /// </summary>
        public void Destroy()
        {
            // 不存活就不存在销毁
            if (!IsAlive)
            {
                return;
            }
            IsAlive = false;
            // 移除套接字参数
            sendEventArgs.Destroy();
            if (ReceiveEventArgs != null)
            {
                ReceiveEventArgs.Dispose();
            }

            // 移除管理器
            if (SocketSvrMgr != null)
            {
                SocketSvrMgr.RemoveExistClient(this);
            }
            // 重置
            ReceiveEventArgs = null;
            Socket           = null;
            RBuffer          = null;
            Target           = null;
            hySocket         = null;
        }
예제 #3
0
 protected virtual void OnDispose()
 {
     try
     {
         object data = DequeueSendMessage();
         while (data != null)
         {
             if (data is IBuffer buffer)
             {
                 BeetleX.Buffers.Buffer.Free(buffer);
                 //((IBuffer)data).Free();
             }
             data = DequeueSendMessage();
         }
         if (SendEventArgs != null)
         {
             SendEventArgs.Dispose();
         }
         if (ReceiveEventArgs != null)
         {
             ReceiveEventArgs.Dispose();
         }
         mReceiveArgs.Server  = null;
         mReceiveArgs.Session = null;
         mBaseNetStream.Dispose();
         if (mSslStream != null)
         {
             mSslStream.Dispose();
         }
         Server.CloseSession(this);
         Server            = null;
         ReceiveDispatcher = null;
         if (Packet != null)
         {
             Packet.Dispose();
         }
         mProperties.Clear();
         if (SendBufferPool is PrivateBufferPool sendPool)
         {
             sendPool.Dispose();
         }
         if (ReceiveBufferPool is PrivateBufferPool receivePool)
         {
             receivePool.Dispose();
         }
     }
     catch
     {
     }
 }
예제 #4
0
        private void Dispose(bool disposing)
        {
            if (Disposed)
            {
                return;
            }

            if (disposing)
            {
                Socket.Dispose();
                ReceiveEventArgs.Dispose();
            }

            Disposed = true;
        }
 /// <summary>
 /// 释放客户端代理
 /// </summary>
 public void Dispose()
 {
     if (socket.Connected)
     {
         socket.Shutdown(SocketShutdown.Both);
     }
     socket.Close();
     socket.Dispose();
     ReceiveEventArgs.Dispose();
     try
     {
         SendEventArgs.Dispose();
     }
     catch { }
     GC.SuppressFinalize(this);
 }
예제 #6
0
 protected virtual void OnDispose()
 {
     try
     {
         object data = DequeueSendMessage();
         while (data != null)
         {
             if (data is IBuffer buffer)
             {
                 BeetleX.Buffers.Buffer.Free(buffer);
             }
             data = DequeueSendMessage();
         }
         SendEventArgs?.Dispose();
         SendEventArgs?.Clear();
         ReceiveEventArgs?.Dispose();
         ReceiveEventArgs?.Clear();
         mReceiveArgs.Server  = null;
         mReceiveArgs.Session = null;
         mBaseNetStream.Dispose();
         if (mSslStream != null)
         {
             mSslStream.Dispose();
         }
         Server.CloseSession(this);
         ListenHandler     = null;
         ReceiveDispatcher = null;
         if (Packet != null)
         {
             Packet.Dispose();
         }
         ((IDisposable)Tag)?.Dispose();
         OnDisposeProperties();
         ((IDisposable)mToken)?.Dispose();
     }
     catch
     {
     }
     finally
     {
         Tag    = null;
         mToken = null;
     }
 }
예제 #7
0
 protected virtual void Dispose(bool disposing)
 {
     if (m_disposed)
     {
         return;
     }
     if (disposing)
     {
         //释放托管资源
         m_connectSocket            = null;
         m_asyncReceiveBuffer       = null;
         ReceiveEventArgs.UserToken = null;
         SendEventArgs.UserToken    = null;
     }
     //释放非托管资源
     ReceiveEventArgs.Dispose();
     SendEventArgs.Dispose();
     SendEvent.Dispose();
     m_disposed = true;
 }
예제 #8
0
        /// <summary>
        /// 关闭连接
        /// </summary>
        public void Close()
        {
            if (Socket != null)
            {
                if (Socket.Connected)
                {
                    Socket.Close();
                }

                Socket.Dispose();
                Socket = null;
            }

            if (SendEventArgs != null)
            {
                SendEventArgs.Completed -= OnSendCompleted;
                SendEventArgs.UserToken  = null;
                SendEventArgs.Dispose();
            }

            SendEventArgs = null;

            if (ReceiveEventArgs != null)
            {
                ReceiveEventArgs.UserToken = null;
                ReceiveEventArgs.Dispose();
            }

            ReceiveEventArgs = null;

            //  清理发送缓冲区
            if (m_PendingBuffer.Count > 0)
            {
                foreach (var buff in m_PendingBuffer)
                {
                    buff.Release();
                }

                m_PendingBuffer.Clear();
            }
        }
예제 #9
0
 protected virtual void OnDispose()
 {
     try
     {
         object data = DequeueSendMessage();
         while (data != null)
         {
             if (data is IBuffer)
             {
                 ((IBuffer)data).Free();
             }
             data = DequeueSendMessage();
         }
         if (SendEventArgs != null)
         {
             SendEventArgs.Dispose();
         }
         if (ReceiveEventArgs != null)
         {
             ReceiveEventArgs.Dispose();
         }
         mReceiveArgs.Server  = null;
         mReceiveArgs.Session = null;
         mBaseNetStream.Dispose();
         if (mSslStream != null)
         {
             mSslStream.Dispose();
         }
         Server.CloseSession(this);
         Server            = null;
         ReceiveDispatcher = null;
         if (Packet != null)
         {
             Packet.Dispose();
         }
         mProperties.Clear();
     }
     catch
     {
     }
 }
예제 #10
0
 public void DisConnect()
 {
     OnDisConnect(this);
     if (ConnectSocket != null)
     {
         try
         {
             ConnectSocket.Shutdown(SocketShutdown.Both);
         }
         catch (Exception e)
         {
             //日志记录
             loger.Fatal(string.Format("CloseClientSocket Disconnect client {0} error, message: {1}", ConnectSocket, e.Message));
         }
         ConnectSocket.Dispose();
         ConnectSocket = null;
     }
     Clear();
     ReceiveEventArgs.Dispose();
     SendEventArgs.Dispose();
 }
예제 #11
0
 protected virtual void OnDispose()
 {
     try
     {
         object data = DequeueSendMessage();
         while (data != null)
         {
             if (data is IBuffer buffer)
             {
                 BeetleX.Buffers.Buffer.Free(buffer);
                 //((IBuffer)data).Free();
             }
             data = DequeueSendMessage();
         }
         SendEventArgs?.Dispose();
         SendEventArgs?.Clear();
         ReceiveEventArgs?.Dispose();
         ReceiveEventArgs?.Clear();
         mReceiveArgs.Server  = null;
         mReceiveArgs.Session = null;
         mBaseNetStream.Dispose();
         if (mSslStream != null)
         {
             mSslStream.Dispose();
         }
         Server.CloseSession(this);
         //Server = null;
         ListenHandler     = null;
         ReceiveDispatcher = null;
         if (Packet != null)
         {
             Packet.Dispose();
         }
         mProperties.Clear();
     }
     catch
     {
     }
 }
예제 #12
0
 public void Dispose()
 {
     if (ConnectDateTime != null)
     {
         lock (closeLock)
         {
             if (ConnectDateTime != null)
             {
                 Clear();
                 ConnectDateTime = null;
                 ActiveDateTime  = null;
                 if (Pool != null)
                 {
                     Pool.Push(this);
                 }
                 else
                 {
                     ReceiveEventArgs.Dispose();
                     SendEventArgs.Dispose();
                 }
             }
         }
     }
 }
예제 #13
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            try
            {
                Connected = false;
                UserContext.OnDisconnect();

                // close client connection
                if (Connection != null)
                {
                    try
                    {
                        Connection.Close();
                    }
                    catch (Exception)
                    {
                        // skip
                    }
                }
            }
            catch
            {}

            try
            {
                SendReady.Release();
                ReceiveReady.Release();
            }
            catch
            {}

            try
            {
                if (SendReady != null)
                {
                    SendReady.Dispose();
                }

                if (ReceiveReady != null)
                {
                    ReceiveReady.Dispose();
                }
            }
            catch
            {}

            try
            {
                if (ReceiveEventArgs != null)
                {
                    ReceiveEventArgs.Dispose();
                }
            }
            catch
            {}

            try
            {
                if (SendEventArgs != null)
                {
                    SendEventArgs.Dispose();
                }
            }
            catch
            {}
        }