Пример #1
0
    //-------------------------------------------------------------------------
    async void _onSuperSocketSessionDestroy(IRpcSession s, SessionCloseReason reason)
    {
        ClientInfo client_info = getClientInfoThenRemove(s);

        if (client_info == null)
        {
            return;
        }

        EbLog.Note("玩家连接断开,EtPlayerGuid=" + client_info.et_player_guid);

        try
        {
            if (client_info.player_watcher_weak != null && !string.IsNullOrEmpty(client_info.et_player_guid))
            {
                var grain_player = GrainClient.GrainFactory.GetGrain <ICellPlayer>(new Guid(client_info.et_player_guid));
                await grain_player.unsubPlayer(client_info.player_watcher_weak);

                client_info.remote_endpoint     = null;
                client_info.player_watcher      = null;
                client_info.player_watcher_weak = null;
            }
        }
        catch (Exception ex)
        {
            EbLog.Error(ex.ToString());
        }
    }
Пример #2
0
        //---------------------------------------------------------------------
        void _onSocketClose(SessionCloseReason reason)
        {
            mSocket = null;

            if (OnSocketClosed != null)
            {
                OnSocketClosed(reason);
            }
        }
Пример #3
0
 //-------------------------------------------------------------------------
 public void sessionClosed(SuperSocketSession s, CloseReason reason)
 {
     if (OnSessionDestroy != null && s.UserData != null)
     {
         SessionCloseReason           r  = (SessionCloseReason)reason;
         EntityRpcSessionSuperSocketS rs = (EntityRpcSessionSuperSocketS)s.UserData;
         OnSessionDestroy((IRpcSession)rs, r);
     }
 }
        //---------------------------------------------------------------------
        void _onSocketClose(SessionCloseReason reason)
        {
            mSocket = null;

            if (OnSocketClosed != null)
            {
                OnSocketClosed(reason);
            }
        }
Пример #5
0
 private void TerminateSession(SessionCloseReason reason, Exception exception)
 {
     //shutdown socket
     vSocket.Shutdown(SocketShutdown.Both);
     //disconnect socket
     vSocket.Disconnect(false);
     //Close to release any resources claimed by the socket instance
     vSocket.Close();
     RaiseSessionClosedEvent(reason, exception);
 }
Пример #6
0
 //---------------------------------------------------------------------
 protected override void OnSessionClosed(CloseReason reason)
 {
     lock (mLockWorker)
     {
         SessionCloseReason r = (SessionCloseReason)reason;
         SocketEvent        socket_event;
         socket_event.type = eSocketEventType.Closed;
         socket_event.args = r;
         mSocketEvent.Enqueue(socket_event);
     }
 }
Пример #7
0
 private void RaiseSessionClosedEvent(SessionCloseReason reason, Exception ex)
 {
     if (SessionClosed == null)
     {
         return;
     }
     foreach (EventHandler <TcpIpSessionClosedEventArgs> del in SessionClosed.GetInvocationList())
     {
         SessionClosed.BeginInvoke(this, new TcpIpSessionClosedEventArgs(reason, ex),
                                   AsyncCallBackRaiseSessionClosedEvent, del);
     }
 }
Пример #8
0
        private void RaiseSessionClosedEvent(SessionCloseReason reason, Exception ex)
        {
            if (SessionClosed == null)
            {
                return;
            }
            foreach (EventHandler <TcpIpSessionClosedEventArgs> del in SessionClosed.GetInvocationList())
            {
#if NET40
                SessionClosed.BeginInvoke(this, new TcpIpSessionClosedEventArgs(reason, ex),
                                          AsyncCallBackRaiseSessionClosedEvent, del);
#else
                System.Threading.Tasks.Task.Run(() => SessionClosed.Invoke(this, new TcpIpSessionClosedEventArgs(reason, ex)));
#endif
            }
        }
Пример #9
0
        //---------------------------------------------------------------------
        void _processSocketEvent(eSocketEventType type, object args)
        {
            switch (type)
            {
            case eSocketEventType.Connected:
            {
                if (OnSocketConnected != null)
                {
                    OnSocketConnected();
                }
            }
            break;

            case eSocketEventType.Closed:
            {
                SessionCloseReason reason = (SessionCloseReason)args;
                if (OnSocketClosed != null)
                {
                    SessionCloseReason r = (SessionCloseReason)reason;
                    OnSocketClosed(r);
                }
            }
            break;

            case eSocketEventType.Error:
            {
                if (OnSocketError != null)
                {
                    OnSocketError(args.ToString());
                }
            }
            break;

            case eSocketEventType.UnknownRequest:
            {
                if (OnSocketError != null)
                {
                    OnSocketError("HandleUnknownRequest");
                }
            }
            break;
            }
        }
Пример #10
0
        /// <summary>
        ///     关闭会话
        /// </summary>
        /// <param name="reason"></param>
        public void Close(SessionCloseReason reason)
        {
            if (Interlocked.CompareExchange(ref _closeFlag, 1, 0) == 1)
            {
                return;
            }

            if (UnderlineSocket.Connected)
            {
                UnderlineSocket.Shutdown(SocketShutdown.Both);
            }

            UnderlineSocket.Close();
            UnderlineSocket = null;

            //_receiveAsyncEventArgs.Dispose();
            //_receiveAsyncEventArgs = null;

            _receiveBuffer = null;
            _extractor     = null;

            Loop.Ins.Perform(() => { _dispatcher.OnClose(this, reason); });
        }
Пример #11
0
 private void TerminateSession(SessionCloseReason reason, Exception exception)
 {
     //shutdown socket
     vSocket.Shutdown(SocketShutdown.Both);
     //disconnect socket
     vSocket.Disconnect(false);
     //Close to release any resources claimed by the socket instance
     vSocket.Close();
     RaiseSessionClosedEvent(reason, exception);
 }
Пример #12
0
 private void RaiseSessionClosedEvent(SessionCloseReason reason, Exception ex)
 {
     if (SessionClosed == null) { return; }
     foreach (EventHandler<TcpIpSessionClosedEventArgs> del in SessionClosed.GetInvocationList())
     {
         SessionClosed.BeginInvoke(this, new TcpIpSessionClosedEventArgs(reason, ex),
             AsyncCallBackRaiseSessionClosedEvent, del);
     }
 }
Пример #13
0
 public TcpIpSessionClosedEventArgs(SessionCloseReason reason, Exception exception)
 {
     vReason = reason;
     vException = exception;
 }
Пример #14
0
 public void OnClose(Session session, SessionCloseReason reason)
 {
     Logger.Ins.Debug($"{session.Name} closed by {reason}!");
     _dispatcher?.OnClose(session, reason);
     _closeHandler?.Invoke(reason);
 }
Пример #15
0
 public virtual void OnClose(Session session, SessionCloseReason reason)
 {
     Logger.Ins.Warn("You should override OnClose.");
 }
 public TcpIpSessionClosedEventArgs(SessionCloseReason reason, Exception exception)
 {
     _vReason    = reason;
     _vException = exception;
 }
Пример #17
0
        public bool RemoveSession(ushort id, SessionCloseReason reason)
        {
            Session session;

            return(_items.TryRemove(id, out session));
        }