コード例 #1
0
ファイル: TcpSocketSaeaServer.cs プロジェクト: thinhils/Teach
        public TcpSocketSaeaSession GetSession(string sessionKey)
        {
            TcpSocketSaeaSession session = null;

            _sessions.TryGetValue(sessionKey, out session);
            return(session);
        }
 public async Task OnSessionClosed(TcpSocketSaeaSession session)
 {
     if (_onSessionClosed != null)
     {
         await _onSessionClosed(session);
     }
 }
コード例 #3
0
ファイル: TcpSocketSaeaServer.cs プロジェクト: thinhils/Teach
 private void Initialize()
 {
     _acceptSaeaPool = new SaeaPool(16, 32,
                                    () =>
     {
         var saea = new SaeaAwaitable();
         return(saea);
     },
                                    (saea) =>
     {
         try
         {
             saea.Saea.AcceptSocket = null;
             saea.Saea.SetBuffer(0, 0);
             saea.Saea.RemoteEndPoint = null;
             saea.Saea.SocketFlags    = SocketFlags.None;
         }
         catch (Exception ex)
         {
             Loger.Error(ex.Message, ex);
         }
     });
     _handleSaeaPool = new SaeaPool(1024, int.MaxValue,
                                    () =>
     {
         var saea = new SaeaAwaitable();
         return(saea);
     },
                                    (saea) =>
     {
         try
         {
             saea.Saea.AcceptSocket = null;
             saea.Saea.SetBuffer(EmptyArray, 0, 0);
             saea.Saea.RemoteEndPoint = null;
             saea.Saea.SocketFlags    = SocketFlags.None;
         }
         catch (Exception ex)
         {
             Loger.Error(ex.Message, ex);
         }
     });
     _sessionPool = new SessionPool(1024, int.MaxValue,
                                    () =>
     {
         var session = new TcpSocketSaeaSession(_configuration, _configuration.BufferManager, _handleSaeaPool, _dispatcher, this);
         return(session);
     },
                                    (session) =>
     {
         try
         {
             session.Clear();
         }
         catch (Exception ex)
         {
             Loger.Error(ex.Message, ex);
         }
     });
 }
 public async Task OnSessionDataReceived(TcpSocketSaeaSession session, byte[] data, int offset, int count)
 {
     if (_onSessionDataReceived != null)
     {
         await _onSessionDataReceived(session, data, offset, count);
     }
 }
コード例 #5
0
ファイル: TcpSocketSaeaServer.cs プロジェクト: thinhils/Teach
        public async Task CloseSession(string sessionKey)
        {
            TcpSocketSaeaSession session = null;

            if (_sessions.TryGetValue(sessionKey, out session))
            {
                await session.Close();
            }
        }
コード例 #6
0
        public async Task CloseSession(string sessionKey)
        {
            TcpSocketSaeaSession session = null;

            if (_sessions.TryGetValue(sessionKey, out session))
            {
                await session.Close(); // parent server close session by session-key
            }
        }
コード例 #7
0
ファイル: TcpSocketSaeaServer.cs プロジェクト: thinhils/Teach
        public async Task SendToAsync(TcpSocketSaeaSession session, byte[] data, int offset, int count)
        {
            TcpSocketSaeaSession sessionFound;

            if (_sessions.TryGetValue(session.SessionKey, out sessionFound))
            {
                await sessionFound.SendAsync(data, offset, count);
            }
            else
            {
                Loger.WarnFormat("Cannot find session [{0}].", session);
            }
        }
コード例 #8
0
ファイル: TcpSocketSaeaServer.cs プロジェクト: thinhils/Teach
 public async Task SendToAsync(TcpSocketSaeaSession session, byte[] data)
 {
     await SendToAsync(session, data, 0, data.Length);
 }
 public async Task OnSessionClosed(TcpSocketSaeaSession session)
 {
     if (_onSessionClosed != null)
         await _onSessionClosed(session);
 }
 public async Task OnSessionDataReceived(TcpSocketSaeaSession session, byte[] data, int offset, int count)
 {
     if (_onSessionDataReceived != null)
         await _onSessionDataReceived(session, data, offset, count);
 }
コード例 #11
0
        private void Initialize()
        {
            _bufferManager = new GrowingByteBufferManager(_configuration.InitialBufferAllocationCount, _configuration.ReceiveBufferSize);

            _acceptSaeaPool = new SaeaPool(16, 32,
                () =>
                {
                    var saea = new SaeaAwaitable();
                    return saea;
                },
                (saea) =>
                {
                    try
                    {
                        saea.Saea.AcceptSocket = null;
                        saea.Saea.SetBuffer(0, 0);
                        saea.Saea.RemoteEndPoint = null;
                        saea.Saea.SocketFlags = SocketFlags.None;
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex.Message, ex);
                    }
                });
            _handleSaeaPool = new SaeaPool(1024, int.MaxValue,
                () =>
                {
                    var saea = new SaeaAwaitable();
                    return saea;
                },
                (saea) =>
                {
                    try
                    {
                        saea.Saea.AcceptSocket = null;
                        saea.Saea.SetBuffer(EmptyArray, 0, 0);
                        saea.Saea.RemoteEndPoint = null;
                        saea.Saea.SocketFlags = SocketFlags.None;
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex.Message, ex);
                    }
                });
            _sessionPool = new SessionPool(1024, int.MaxValue,
                () =>
                {
                    var session = new TcpSocketSaeaSession(_configuration, _bufferManager, _handleSaeaPool, _dispatcher, this);
                    return session;
                },
                (session) =>
                {
                    try
                    {
                        session.Clear();
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex.Message, ex);
                    }
                });
        }
コード例 #12
0
 public async Task SendToAsync(TcpSocketSaeaSession session, byte[] data, int offset, int count)
 {
     TcpSocketSaeaSession sessionFound;
     if (_sessions.TryGetValue(session.SessionKey, out sessionFound))
     {
         await sessionFound.SendAsync(data, offset, count);
     }
     else
     {
         _log.WarnFormat("Cannot find session [{0}].", session);
     }
 }
コード例 #13
0
 public async Task SendToAsync(TcpSocketSaeaSession session, byte[] data)
 {
     await SendToAsync(session, data, 0, data.Length);
 }