Ejemplo n.º 1
0
        /// <summary>
        /// Close socket
        /// </summary>
        public virtual bool Close()
        {
            if (Interlocked.CompareExchange(ref isInClosing, ActiveSentinel, NoneSentinel) == NoneSentinel)
            {
                try
                {
                    WorkSocket.Shutdown(SocketShutdown.Both);
                }
                catch (SocketException)
                { }
                catch (Exception ex)
                {
                    var stackFrameString = StackTrace.GetStackFrameString();
                    logger.Error("ExSocket EndPoint:{0} Close error:{1} stack:{2}", RemoteEndPoint, ex, stackFrameString);
                }
                finally
                {
                    WorkSocket.Close();
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
 public void CloseSocket()
 {
     if (WorkSocket != null)
     {
         WorkSocket.Shutdown(SocketShutdown.Both);
         WorkSocket.Close();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 public void Close()
 {
     try
     {
         WorkSocket.Shutdown(SocketShutdown.Both);
     }
     catch { }
     WorkSocket.Close();
 }
Ejemplo n.º 4
0
        internal void Close()
        {
            if (mIOSendEventArgs == null || mIOSendEventArgs == null)
            {
                return;
            }

            try
            {
                var socket = WorkSocket;
                if (socket != null)
                {
                    WorkSocket.Shutdown(SocketShutdown.Both);
                    WorkSocket.Close();
                }

                var dataToken0 = (AsyncUserToken)mIOSendEventArgs.UserToken;
                if (dataToken0 != null)
                {
                    dataToken0.Reset(true);
                    dataToken0.tcpConn = null;
                }
                var dataToken1 = (AsyncUserToken)mIOReceiveEventArgs.UserToken;
                if (dataToken1 != null)
                {
                    dataToken1.Reset(true);
                    dataToken1.tcpConn = null;
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                mIOSendEventArgs.AcceptSocket = null;
                server.GetIOArgPool().Push(mIOSendEventArgs);
                mIOSendEventArgs = null;

                mIOReceiveEventArgs.AcceptSocket = null;
                server.GetIOArgPool().Push(mIOReceiveEventArgs);
                mIOReceiveEventArgs = null;

                this.server = null;
                mState      = NetState.Disconnect;
            }
        }