コード例 #1
0
        /// <summary>
        /// 断线处理 - *****
        /// </summary>
        /// <param name="state"></param>
        private void DisconnectProcessing(object state)
        {
            if (!this.Disposed)
            {
                bool bCallDisconnect = false;

                SocketEventArgs  pSocketEventArgs = null;
                ConnectionManage pConnection      = null;
                IAsyncResult     AsyncResult      = null;

                try
                {
                    if (state is SocketEventArgs)
                    {
                        //----- NT5 / Win2000!
                        pSocketEventArgs = (SocketEventArgs)state;
                        bCallDisconnect  = false;
                    }
                    else
                    {
                        //----- NT5 / WinXP and later!
                        AsyncResult      = (IAsyncResult)state;
                        pSocketEventArgs = (SocketEventArgs)AsyncResult.AsyncState;
                        bCallDisconnect  = true;
                    }

                    pConnection = (ConnectionManage)pSocketEventArgs.Connection;

                    if (pConnection.Active)
                    {
                        if (bCallDisconnect)
                        {
                            pConnection.CurrentSocket.EndDisconnect(AsyncResult);
                        }

                        lock (pConnection.ActiveLock)
                        {
                            pConnection.Active = false;
                            pConnection.CurrentSocket.Close();
                        }

                        this.SocketDisconnectEvent(pSocketEventArgs);
                    }

                    this.RemoveSocketConnection(pConnection);
                    this.StopConnections(ref pConnection);
                }
                catch (Exception ex)
                {
                    this.SocketExceptionEvent(pConnection, ex);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 断线方法 - *****
        /// </summary>
        /// <param name="pConnection"></param>
        /// <param name="DisconnectException"></param>
        internal void SocketDisconnect(ConnectionManage pConnection)
        {
            //判断对象有效
            if (!this.Disposed)
            {
                SocketEventArgs pSocketEventArgs = new SocketEventArgs(pConnection, false);

                if (pConnection.Active)
                {
                    try
                    {
                        //判断操作系统版本号
                        if ((Environment.OSVersion.Version.Major == 5) &&
                            (Environment.OSVersion.Version.Minor >= 1))
                        {
                            //--- NT5 / WinXP and later!
                            pConnection.CurrentSocket.BeginDisconnect(false, new AsyncCallback(DisconnectCallback), pSocketEventArgs);
                        }
                        else
                        {
                            //---- NT5 / Win2000!
                            ThreadPool.QueueUserWorkItem(new WaitCallback(DisconnectProcessing), pSocketEventArgs);
                        }//end Version if...else...
                    }
                    catch (Exception ex)
                    {
                        this.SocketExceptionEvent(pConnection, ex);
                    }
                }
                else
                {
                    this.RemoveSocketConnection(pConnection);
                    this.StopConnections(ref pConnection);
                }
            }//end if
        }
コード例 #3
0
 /// <summary>
 /// 断线事件
 /// </summary>
 /// <param name="DisconnectedEvent"></param>
 internal void SocketDisconnectEvent(SocketEventArgs pDisconnectedEvent)
 {
     this._SocketService.OnDisconnected(pDisconnectedEvent);
 }
コード例 #4
0
 public virtual void OnException(SocketEventArgs pEventArgs)
 {
 }
コード例 #5
0
 public virtual void OnDisconnected(SocketEventArgs pEventArgs)
 {
 }